One way to perform an ANOVA for repeated measures in R is to use a mixed effects model. Specifically, the lmer()
function from the lme4
package can be used to fit a linear mixed effects model.
Here is an example code with explanations:
main.r296 chars12 lines
In this example, dependent_variable
is the response variable, fixed_effect_1
and fixed_effect_2
are the independent variables, and subject_ID
is the ID variable for the repeated measure. The (1|subject_ID)
notation specifies that the intercept varies randomly across subjects, while the fixed effects (i.e., the coefficients for fixed_effect_1
and fixed_effect_2
) are assumed to be constant across subjects.
The resulting anova_table
provides information on the fixed effects and the random intercept.
gistlibby LogSnag