## Hugo Quené, R course at UiL OTS, June 2012 ## h.quene@uu.nl sophia <- read.csv( file=url("http://www.hugoquene.nl/R/SophiaManika2.csv"), header=T) # data are in WIDE layout and have many empty rows sophia <- sophia[1:2160,] # remove empty rows install.packages("reshape") require(reshape) # convert or "melt" from wide to long layout sophia2 <- melt(sophia, id.vars=1:4, variable.name="rt") sophia2$variable = factor(gsub('rt(.+)', '\\1', sophia2$variable)) dimnames(sophia2)[[2]][5:6] <- c("region","rt") sophia2$entropy <- as.factor(sophia2$entropy) sophia2$sentype <- as.factor(sophia2$sentype) sophia2$region <- as.integer(sophia2$region) # empty model sophia0.lmer <- lmer(rt~1+(1|subject)+(1|item), data=sophia2, REML=F ) sophia0.lmer # center to region 2.5 cval <- 2.5 sophia1.lmer <- lmer(rt~1+I(region-cval)+(1|subject)+(1|item), data=sophia2, REML=F ) sophia1.lmer # add quadratic component sophia2.lmer <- lmer(rt~1+I(region-cval)+I((region-cval)^2)+(1|subject)+(1|item), data=sophia2, REML=F ) sophia2.lmer #Fixed effects: # Estimate Std. Error t value #(Intercept) 379.5567 13.3490 28.433 #I(region - 2.5) -9.1128 0.9440 -9.654 #I((region - 2.5)^2) 0.7649 0.1102 6.939 # plot estimated rt by region curve( 380-9.1*(x-cval)+0.76*((x-cval)^2), from=1-cval, to=12-cval, xlab="region", ylab="estimated RT (ms)", main="model sophia2.lmer", type="b", n=12, pch=16, cex=2, xaxt="n" ) # no x axis marks axis(side=1, at=(1:12)-cval, labels=as.character(1:12) ) # my own x axis marks abline(v=cval-cval,col="red", lty=2) # add main effects and interactions of key experimental factors sophia3.lmer <- lmer( rt~ entropy*sentype+ I(region-cval)*entropy*sentype+I((region-cval)^2)*entropy*sentype +(1|subject)+(1|item), data=sophia2, REML=F ) sophia3.lmer #Fixed effects: # Estimate Std. Error t value #(Intercept) 384.1921 13.8880 27.664 #entropy2 -7.0910 6.2234 -1.139 #sentype1 -6.2793 5.3254 -1.179 #I(region - 2.5) -10.0907 1.9716 -5.118 #I((region - 2.5)^2) 0.8541 0.2302 3.710 #entropy2:sentype1 8.7899 7.3963 1.188 #entropy2:I(region - 2.5) -0.3885 2.6789 -0.145 #sentype1:I(region - 2.5) 3.7582 2.7296 1.377 #entropy2:I((region - 2.5)^2) 0.1487 0.3128 0.475 #sentype1:I((region - 2.5)^2) -0.4699 0.3188 -1.474 #entropy2:sentype1:I(region - 2.5) -2.7953 3.7820 -0.739 #entropy2:sentype1:I((region - 2.5)^2) 0.2733 0.4416 0.619 # There are significant linear and quadratic terms for region. # But entropy and sentype are not significant, # and neither entropy nor sentype affects slope or curvature of rt over regions. anova(sophia3.lmer,sophia2.lmer) # Df AIC BIC logLik Chisq Chi Df Pr(>Chisq) #sophia2.lmer 6 345043 345092 -172516 #sophia3.lmer 15 345054 345176 -172512 7.3047 9 0.6054 # More complex model is not better than simpler model without experimental factors...