Guest User

Untitled

a guest
Jul 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. library(lme4)
  2. library(lmerTest)
  3. library(MASS)
  4.  
  5. # Generate data
  6. 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))
  7.  
  8. # Convert to factors
  9. X$cond <- factor(X$cond)
  10. X$time <- factor(X$time)
  11.  
  12. # Contrast coding
  13. contrastCond <- rbind(c(1, -0.5, -0.5), # A vs. (B + C)/2
  14. c(0, 1, -1)) # B vs. C
  15. contrastTime <- c(+1, -1) # today vs. tomorrow
  16.  
  17. # Generalized inverse matrix
  18. MatCond <- ginv(contrastCond)
  19.  
  20. # Mixed model analyses
  21. mdl <- lmer(rating ~ cond * time + (1|id) + (1|target),
  22. contrasts = list(cond = MatCond, time = contrastTime),
  23. data = X)
  24.  
  25. summary(mdl)
Add Comment
Please, Sign In to add comment