library(lme4) library(mgcv) library(lattice) d <- read.table("tutorial.txt", head=TRUE) #### #### #### #### m1 <- lmer(duration~mary_context +(1|speakerid), data=d) m2 <- lmer(duration~mary_context+amiFreq +(1|speakerid), data=d) summary(m1) summary(m2) anova(m1,m2) m1b <- lmer(duration~mary_context + (1+mary_context | speakerid), data=d) summary(m1b) anova(m1, m1b) # show the effect of individuals print(dotplot(ranef(m1b,cond=TRUE), scales = list(x = list(relation = 'free')))[["speakerid"]]) # consider only subset of french native speakers: m1bfrench <- lmer(duration~mary_context + (1+mary_context | speakerid), data=subset(d, native_language=="french")) print(dotplot(ranef(m1bfrench,cond=TRUE), scales = list(x = list(relation ='free')))[["speakerid"]]) # add out of domain trigram as a predictor m3<-lmer(duration~mary_context+amiFreq+srpTrigram.OODomain+(1|speakerid),data=d) summary(m3) anova(m3,m2) # look at in domain trigram model m3in<-lmer(duration~mary_context+amiFreq+srpTrigram.inDomain +( 1|speakerid), data=d) summary(m3in) summary(m3) par(mfcol=c(2,1)) plot(gam(duration~mary_context + amiFreq + s(srpTrigram.inDomain), data=d)) plot(gam(duration~mary_context + amiFreq + s(srpTrigram.OODomain), data=d)) m3full<-lmer(duration~mary_context+amiFreq+srpTrigram.OODomain+(mary_context+amiFreq+srpTrigram.OODomain+1|speakerid),data=d) summary(m3full) m3infull<-lmer(duration~mary_context+amiFreq+srpTrigram.inDomain +(mary_context+amiFreq+srpTrigram.inDomain +1|speakerid), data=d) summary(m3infull)