nested_lmer <- function(x) { # Assigning single-ms trials to first and last according to median sacOnset mso <- median(x$sacOnset) x$typ2 <- x$typ x$typ2[x$typ==0 & x$sacOnset < mso] <- 1 x$typ2[x$typ==0 & x$sacOnset >= mso] <- 2 # Design specification: mtc nested within levels of cv x$design <- factor(paste(x$cv, x$mtc, sep="")) x$design <- C(x$design, matrix(c(-.5, +.5, 0, 0, # (1) mtc | cv=1 - invalid 0, 0, -.5, +.5, # (2) mtc | cv=2 - valid -.5, -.5, +.5, +.5 # (3) cv ), 4, 3), 3) # Remove subjects with incomplete cells in typ>0 x.n <- table(x$ID[x$typ>=1], x$design[x$typ>=1]) temp <- vector() for (i in 1:dim(x.n)[1]) { temp[i] <- any(x.n[i,]==0) } vid <- attr(x.n, "dimnames")[[1]][temp] # vid contains ids with 0 v <- vector() for (i in length(vid) ) { temp <- which(x$ID == vid[i]) v <- c(v, temp) # v contains records of ids } if(length(v) > 0) {x <- x[-v, ]} print(table(x$ID[x$typ>=1], x$design[x$typ>=1])) print(lmer(rt ~ design + (1|ID), x, subset=x$typ==1 )) #print(lmer(lrt ~ design + (1|ID), x, subset=x$typ==1 )) print(lmer(rt ~ design + (1|ID), x, subset=x$typ==2 )) #print(lmer(lrt ~ design + (1|ID), x, subset=x$typ==2 )) #print(lmer(rt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ==1)) #print(lmer(lrt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ==1)) #print(lmer(rt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ==2)) #print(lmer(lrt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ==2)) print(table(x$ID[x$typ2>=1], x$design[x$typ2>=1])) print(lmer(rt ~ design + (1|ID), x, subset=x$typ2==1 )) #print(lmer(lrt ~ design + (1|ID), x, subset=x$typ2==1 )) print(lmer(rt ~ design + (1|ID), x, subset=x$typ2==2 )) #print(lmer(lrt ~ design + (1|ID), x, subset=x$typ2==2 )) #print(lmer(rt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ2==1)) #print(lmer(lrt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ==1)) #print(lmer(rt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ2==2)) #print(lmer(lrt ~ cv.e*mtc.e + (1|ID), x, subset=x$typ2==2)) #return the new data frame x }