Advertisement
singmann

all 2-way interactions for 3-way interaction

Sep 29th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.64 KB | None | 0 0
  1. require(lsmeans)
  2. require(afex)
  3. data(obk.long, package = "afex")
  4. #lsm.options(disable.pbkrtest = TRUE)  pbkrtest needed for F-test
  5.  
  6. # let's fit this example data with 2 between. and two within-subjects factors via the ANOVA equivalent using lme4:
  7. m1 <- mixed(value ~ treatment*gender*phase*hour + (1|id) + (1|id:phase) + (1|id:hour), obk.long)
  8. ##                         Effect     F ndf   ddf F.scaling p.value
  9. ## 1                    treatment  3.94   2 10.00      1.00     .05
  10. ## 2                       gender  3.66   1 10.00      1.00     .08
  11. ## 3                        phase 16.13   2 20.00      1.00 <.0001
  12. ## 4                         hour 16.69   4 40.00      1.00 <.0001
  13. ## 5             treatment:gender  2.86   2 10.00      1.00     .10
  14. ## 6              treatment:phase  4.85   4 20.00      1.00    .007
  15. ## 7                 gender:phase  0.28   2 20.00      1.00     .76
  16. ## 8               treatment:hour  0.09   8 40.00      1.00 >.99
  17. ## 9                  gender:hour  0.45   4 40.00      1.00     .77
  18. ## 10                  phase:hour  1.18   8 80.00      1.00     .32
  19. ## 11      treatment:gender:phase  0.64   4 20.00      1.00     .64
  20. ## 12       treatment:gender:hour  0.62   8 40.00      1.00     .76
  21. ## 13        treatment:phase:hour  0.35  16 80.00      1.00     .99
  22. ## 14           gender:phase:hour  0.93   8 80.00      1.00     .50
  23. ## 15 treatment:gender:phase:hour  0.74  16 80.00      1.00     .75
  24.  
  25. # I am interested in the phase:hour interaction per levels of treatment. It has 8 numerator df.
  26.  
  27. # set up the interaction per treatment:
  28. (ls1 <- lsmeans(m1$full.model, ~phase:hour |treatment))
  29. # alternatively:
  30. # ls1 <- lsmeans(m1, ~phase:hour|treatment, data = obk.long)
  31.  
  32. # (following code by Russel Lenth)
  33.  
  34. #  create the contrasts for phase – 2 d.f. for each combination of the other factors:
  35. (con1 <- contrast(ls1, "trt.vs.ctrl1", by = c("hour","treatment")))
  36.  
  37. # Now contrast these contrasts for each contrast (label in above results) and treatment combination, and summarize them by treatment
  38. con2 <- contrast(con1, "trt.vs.ctrl1", by = c("contrast","treatment"))
  39. summary(con2, by = "treatment")
  40.  
  41. # Finally, use the new capability of test to obtain the joint tests
  42. test(con2, joint = TRUE, by = "treatment")
  43. ##              F df1 df2 p.value
  44. ## control 0.4090   8  80  0.9123
  45. ## A       0.9879   8  80  0.4518
  46. ## B       0.3838   8  80  0.9263
  47.  
  48. # Finally, use the new capability of test to obtain the joint tests
  49. test(con2, joint = TRUE, rows = 1:8)
  50.  
  51. test(con2, joint = TRUE, rows = 9:16)
  52.  
  53. test(con2, joint = TRUE, rows = 17:24)
  54.  
  55.  
  56. ## Alternatively in next versions of lsmeans:
  57. # test(con2, joint = TRUE, by = "treat")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement