-
Notifications
You must be signed in to change notification settings - Fork 4
/
homework07.Rmd
79 lines (57 loc) · 4.36 KB
/
homework07.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: "Homework 07"
---
## Homework 07 - due 12/10/2018
### ANSWER KEY FILES
* [SPSS Code](https://github.com/melindahiggins2000/N736Fall2017_Homework7Key/raw/master/SPSS_Syntax_Homework7Key_2018.sps)
* [SPSS Output](https://melindahiggins2000.github.io/N736Fall2017_Homework7Key/SPSS_Output_Homework7Key_2018.htm)
* [SAS Code](https://github.com/melindahiggins2000/N736Fall2017_Homework7Key/raw/master/Homework7Key_SAS_2018.sas)
* [SAS Output](https://melindahiggins2000.github.io/N736Fall2017_Homework7Key/SAS_output_homework7Key_2018.htm)
* [R Code](https://github.com/melindahiggins2000/N736Fall2017_Homework7Key/raw/master/Homework7Key_Rcode_2018.R)
* [R Output (with detailed explanation)](https://melindahiggins2000.github.io/N736Fall2017_Homework7Key/Homework7Key_Rmarkdown_2018.html)
### Repeated Measures ANOVA and Multilevel (MIXED) Linear Models
For Homework 07, you will be using the HELP dataset, learn more at:
* [https://melindahiggins2000.github.io/N736Fall2017_HELPdataset/](https://melindahiggins2000.github.io/N736Fall2017_HELPdataset/) &
* [https://github.com/melindahiggins2000/N736Fall2017_HELPdataset](https://github.com/melindahiggins2000/N736Fall2017_HELPdataset)
Refer to the repeated measures ANOVA and MLM (2017) lessons 21, 22 and 23. See
* Lesson 21 [https://github.com/melindahiggins2000/N736Fall2017_lesson21](https://github.com/melindahiggins2000/N736Fall2017_lesson21)
* Lesson 22 [https://github.com/melindahiggins2000/N736Fall2017_lesson22](https://github.com/melindahiggins2000/N736Fall2017_lesson22)
* Lesson 23 [https://github.com/melindahiggins2000/N736Fall2017_lesson23](https://github.com/melindahiggins2000/N736Fall2017_lesson23)
For the HELP dataset:
* OUTCOME VARIABLE: consider the 5 measurements of mental health (`mcs`) at baseline, 6m, 12m, 18m and 24m. Use variables `mcs`, `mcs1`, `mcs2`, `mcs3`, `mcs4`
* BETWEEN GROUP VARIABLE: Also consider the treatment group variable `treat`
* FYI: You will also need the `id` to
a. properly restructure the data from WIDE to LONG format; and
b. treat subjects as a random effect for the random intercepts approach to MLM
### For Homework 7, complete the following:
1. Perform a repeated measures analysis of variance (RM-ANOVA) for the 5 MCS measurements across time by treatment group.
a. treat time as a continuous variable (not as a factor) - this is your WITHIN group effect
b. treat the treatment group `treat` as a factor - this is your BETWEEN group effect
c. TABLE: present the table of the intercept, time, treat and time*treat interaction effects including the tests of significance. _[Remember this significance might change depending on the treatment group coding - try flipping the 0 and 1 and run the model again to see if the significance changes]_
d. FIGURE: make a plot of the MCS means across time by group - if you can make it an error bar plot which has the means and CI's (confidence intervals) or SE's (standard errors)
2. Repeate the "repeated measures/longitudinal" analysis using a random intercepts MLM model
a. REMEMBER to restructure the data from WIDE to LONG format
b. TABLE: present the table of the intercept, time, treat and time*treat interaction effects including the tests of significance. _[Remember this significance might change depending on the treatment group coding - try flipping the 0 and 1 and run the model again to see if the significance changes]_
3. Compare the results between the 2 approaches
a. compare the sample size differences (i.e. RM-ANOVA listwise deletion versus MLM approach which keeps all non-missing cases)
b. why do you think the results are different or are similar?
## Variables in HELP dataset to be used for Homework 07:
```{r, echo=FALSE, message=FALSE, warning=FALSE}
helpdata <- readRDS("helpmkh.rds")
library(tidyverse)
sub1 <- helpdata %>%
select(id, treat, mcs, mcs1, mcs2, mcs3, mcs4)
# create a function to get the label
# label output from the attributes() function
getlabel <- function(x) attributes(x)$label
# getlabel(sub1$age)
library(purrr)
ldf <- purrr::map_df(sub1, getlabel) # this is a 1x15 tibble data.frame
# t(ldf) # transpose for easier reading to a 15x1 single column list
# using knitr to get a table of these
# variable names for Rmarkdown
library(knitr)
knitr::kable(t(ldf),
col.names = c("Variable Label"),
caption="Use these variables from HELP dataset for Homework 07")
```