Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(lme4)
- library(lmerTest)
- library(MASS)
- # Generate data
- X <- structure(list(time = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("today", "tomorrow"), class = "factor"), cond = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("A", "B", "C"), class = "factor"), target = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L), .Label = c("target1", "target2", "target3", "target4", "target5", "target6", "target7", "target8", "target9"), class = "factor"), id = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("s1", "s2"), class = "factor"), rating = c(4L, 1L, 3L, 6L, 6L, 5L, 2L, 4L, 0L, 4L, 0L, 5L, 4L, 4L, 2L, 3L, 6L, 0L)), class = "data.frame", row.names = c(NA, -18L))
- # Convert to factors
- X$cond <- factor(X$cond)
- X$time <- factor(X$time)
- # Contrast coding
- contrastCond <- rbind(c(1, -0.5, -0.5), # A vs. (B + C)/2
- c(0, 1, -1)) # B vs. C
- contrastTime <- c(+1, -1) # today vs. tomorrow
- # Generalized inverse matrix
- MatCond <- ginv(contrastCond)
- # Mixed model analyses
- mdl <- lmer(rating ~ cond * time + (1|id) + (1|target),
- contrasts = list(cond = MatCond, time = contrastTime),
- data = X)
- summary(mdl)
Add Comment
Please, Sign In to add comment