Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docssource/mixed_example2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In this example we work out the analysis of a simple repeated measures design wi

We use the GAMLj module in Jamovi. One can follow the example by downloading the file `r datafile("wicksell.csv","wicksell.csv")`. Be sure to install GAMLj module from within jamovi library.

The data are from a [David C. Howell](https://www.uvm.edu/~dhowell/StatPages/More_Stuff/Mixed-Models-Repeated/Mixed-Models-for-Repeated-Measures1.html) website. You can find there a lot of very clear information and discussion of repeated measures mixed model analysis, in SPSS, SAS, and R. As you would expect from David C. Howell, the material is simply great.
The data are from a [David C. Howell](https://www.uvm.edu/~statdhtx/StatPages/Mixed-Models-Repeated/Mixed-Models-for-Repeated-Measures1.html) website. You can find there a lot of very clear information and discussion of repeated measures mixed model analysis, in SPSS, SAS, and R. As you would expect from David C. Howell, the material is simply great.

Data can also be opened within jamovi in the jamovi data library, with the name `wicksell`.

Expand All @@ -35,14 +35,14 @@ Data can also be opened within jamovi in the jamovi data library, with the name
# The research design


"[Howell] has created data to have a number of characteristics. There are two groups - a Control group and a Treatment group, measured at 4 times. These times are labeled as 1 (pretest), 2 (one month posttest), 3 (3 months follow-up), and 4 (6 months follow-up). I created the treatment group to show a sharp drop at post-test and then sustain that drop (with slight regression) at 3 and 6 months. The Control group declines slowly over the 4 intervals but does not reach the low level of the Treatment group. There are noticeable individual differences in the Control group, and some subjects show a steeper slope than others. In the Treatment group there are individual differences in level but the slopes are not all that much different from one another. You might think of this as a study of depression, where the dependent variable is a depression score (e.g. Beck Depression Inventory) and the treatment is drug versus no drug. If the drug worked about as well for all subjects the slopes would be comparable and negative across time. For the control group we would expect some subjects to get better on their own and some to stay depressed, which would lead to differences in slope for that group." ( [Howell](https://www.uvm.edu/~dhowell/StatPages/More_Stuff/Mixed-Models-Repeated/Mixed-Models-for-Repeated-Measures1.html) )
"[Howell] has created data to have a number of characteristics. There are two groups - a Control group and a Treatment group, measured at 4 times. These times are labeled as 1 (pretest), 2 (one month posttest), 3 (3 months follow-up), and 4 (6 months follow-up). I created the treatment group to show a sharp drop at post-test and then sustain that drop (with slight regression) at 3 and 6 months. The Control group declines slowly over the 4 intervals but does not reach the low level of the Treatment group. There are noticeable individual differences in the Control group, and some subjects show a steeper slope than others. In the Treatment group there are individual differences in level but the slopes are not all that much different from one another. You might think of this as a study of depression, where the dependent variable is a depression score (e.g., Beck Depression Inventory) and the treatment is drug versus no drug. If the drug worked about as well for all subjects the slopes would be comparable and negative across time. For the control group we would expect some subjects to get better on their own and some to stay depressed, which would lead to differences in slope for that group." ( [Howell](https://www.uvm.edu/~statdhtx/StatPages/Mixed-Models-Repeated/Mixed-Models-for-Repeated-Measures1.html) )

The design is thus a 2 (group) X 4 (time) design with the latter factor repeated within participants.

<img src="examples/mixed2/freq.png" class="img-responsive" alt="">


The depenent variable is a continuous variable.
The dependent variable is a continuous variable.

<img src="examples/mixed2/desc.png" class="img-responsive" alt="">

Expand All @@ -53,7 +53,7 @@ Data are in the long format: Each observation is a row, and the variable `subj`

# Understanding the problem

Here we simple need to estimate the main effects of `time`, of `group` and their interaction, as one would do in a standard ANOVA. Because we have a repeated measures factor (`time`), we should take dependency in the data into the account. We do that by allowing the intercepts to vary from subject to subject. In this way, each participant is "allowed" to have a higher or lower overall response (average response over time), and thus the error term (the residuals) are computed as deviation from the participant's mean (and the fixed effects). This captures (for a good share) the dependency among data.
Here we simply need to estimate the main effects of `time`, of `group` and their interaction, as one would do in a standard ANOVA. Because we have a repeated measures factor (`time`), we should take dependency in the data into the account. We do that by allowing the intercepts to vary from subject to subject. In this way, each participant is "allowed" to have a higher or lower overall response (average response over time), and thus the error term (the residuals) are computed as deviation from the participant's mean (and the fixed effects). This captures (for a good share) the dependency among data.

We can talk about "average response" because we are going to use `deviations` coding for the categorical variables (GAMLj does that by default), so the fixed intercept is the expected value of the dependent variable on average, and the random intercepts are individual deviations from it.

Expand All @@ -65,12 +65,12 @@ To run a mixed model, we should answer three questions:

* Which is the cluster variable: in our case it is clearly the `subj` variable.
* What are the fixed effects: here they are the effect of `time`, of `group` and their interaction. Please notice that GAMLj automatically push the categorical variables and their interaction in the fixed effects definition (cf. panel `Fixed Effects`). If one needs a different set of fixed effects, that is the place to work.
* What are the random effects: for the first run on the estimation, we go for a random intercepts model, thus the random coefficients are the interectps.
* What are the random effects: for the first run on the estimation, we go for a random intercepts model, thus the random coefficients are the intercepts.


## Set up

In order to estimate the model with jamovi, we first need to set each variable in the rigth field.
In order to estimate the model with jamovi, we first need to set each variable in the right field.

<img src="examples/mixed2/variables1.png" class="img-responsive" alt="">

Expand Down Expand Up @@ -133,12 +133,12 @@ In the output there's also a `Fixed effects Parameters Estimates` table that giv
<img src="examples/mixed2/r.random.png" class="img-responsive" alt="">


The **Random Component** display the variances and SD of the random coefficients, in this case of the random intercepts. From the table we can see that there is variance in the intercepts (${\sigma_a}^2$=2539), thus we did well in letting the intercepts vary from cluster to cluster. ${\sigma_a}^2$ can be reported as an intra-class correlation by dividing it by the sum of itself and the residual variace ($\sigma^2$), that is $v_{ic}={{\sigma_a}^2 \over {{\sigma_a}^2+{\sigma}^2}}$
The **Random Component** display the variances and SD of the random coefficients, in this case of the random intercepts. From the table we can see that there is variance in the intercepts (${\sigma_a}^2$=2539), thus we did well in letting the intercepts vary from cluster to cluster. ${\sigma_a}^2$ can be reported as an intra-class correlation by dividing it by the sum of itself and the residual variance ($\sigma^2$), that is $v_{ic}={{\sigma_a}^2 \over {{\sigma_a}^2+{\sigma}^2}}$
(future releases will compute that for you).

## Mixed vs RM Anova

If one looks at the results discussed in [David C. Howell](https://www.uvm.edu/~dhowell/StatPages/More_Stuff/Mixed-Models-Repeated/Mixed-Models-for-Repeated-Measures1.html) website, one can appreciate that our results are almost perfectly in line with the ones obtained with SPSS, SAS, and with a repeated measures ANOVA. The latter it is not always true, meaning that depending on the data and model charateristics, RM ANOVA and the Mixed model results may differ. RM ANOVA and the Mixed model are different strategies to estimates effects in RM designs, thus they are not always overlapping.
If one looks at the results discussed in [David C. Howell](https://www.uvm.edu/~statdhtx/StatPages/Mixed-Models-Repeated/Mixed-Models-for-Repeated-Measures1.html) website, one can appreciate that our results are almost perfectly in line with the ones obtained with SPSS, SAS, and with a repeated measures ANOVA. The latter it is not always true, meaning that depending on the data and model characteristics, RM ANOVA and the Mixed model results may differ. RM ANOVA and the Mixed model are different strategies to estimates effects in RM designs, thus they are not always overlapping.

## Estimated Means Plots

Expand Down Expand Up @@ -190,7 +190,7 @@ Here are the B coefficients of the effects. Because `group` is centered, it is c

<img src="examples/mixed2/r.plots2.png" class="img-responsive" alt="">

Now we can interpret the interaction terms involving the contrasts. `Time1 * groups` corresponds to `linear * group` contrasts, and it is clearly small (compare the B=-.894 with the other B's) and not statistically significant (p=.934). This means that the linear trend is basically the same for the two groups defined by `group`. Indeed, the two groups starts more or less at the same hight and end up at the same level: same linear trend. Very different is the quadratic term, because the interaction `quadratic * group` is strong and significant (p<.001). Indeed, for group 1 there is no "bending" of the trend, whereas for group 1 the rate of change over time is much faster at the begining and very small at the end. The fluctuation captured by the cubic trend does not really differ in the two groups (p=.103)
Now we can interpret the interaction terms involving the contrasts. `Time1 * groups` corresponds to `linear * group` contrasts, and it is clearly small (compare the B=-.894 with the other B's) and not statistically significant (p=.934). This means that the linear trend is basically the same for the two groups defined by `group`. Indeed, the two groups starts more or less at the same hight and end up at the same level: same linear trend. Very different is the quadratic term, because the interaction `quadratic * group` is strong and significant (p<.001). Indeed, for group 1 there is no "bending" of the trend, whereas for group 1 the rate of change over time is much faster at the beginning and very small at the end. The fluctuation captured by the cubic trend does not really differ in the two groups (p=.103)


<img src="examples/mixed2/r.plots1.png" class="img-responsive" alt="">
Expand Down Expand Up @@ -226,7 +226,7 @@ Results are almost self-explanatory:

<img src="examples/mixed2/r.posthoc1.png" class="img-responsive" alt="">

Time 0 mean (on average across groups) differs from the mean of all the other three times, time 1 mean differs (based on NHST) only from time 6, and time 3 and 6 are not differnt. That concludes the probing of the main effect of time. The same can be done for the interaction, which would produce ${(8 \cdot 7) \over 2}=28$ comparisons. We stop here because post-hoc tests are very boring.
Time 0 mean (on average across groups) differs from the mean of all the other three times, time 1 mean differs (based on NHST) only from time 6, and time 3 and 6 are not different. That concludes the probing of the main effect of time. The same can be done for the interaction, which would produce ${(8 \cdot 7) \over 2}=28$ comparisons. We stop here because post-hoc tests are very boring.

# Estimated Marginal Means

Expand Down