KNOWLEDGEBASE - ARTICLE #2104

R and SAS code to fit a mixed-effects model instead of two-way ANOVA with repeated measures in both factors

Prism 8 introduces fitting a mixed-effects model to allow, essentially, repeated measures ANOVA with missing values. We provide R and SAS code to show your statistical consultants, so they can understand what Prism is doing. This example is for two-way ANOVA with repeated measures in both factors. Another FAQs covers one-way repeated measures ANOVA

Download the Prism 8 file. 

Download the data file used by R and SAS. anova2.rm.maxwell_12.1.csv

SAS Code

FILENAME REFFILE 'anova2.rm.maxwell_12.1.csv';
PROC IMPORT DATAFILE=REFFILE
DBMS=CSV
OUT=gsData;
GETNAMES=YES;
RUN;
PROC MIXED data=gsData METHOD=REML;
CLASS A B S;
MODEL Y = A B A*B;
RANDOM Int A B / SUBJECT=S;
RUN;

R code

library(lme4)
options(contrasts = c("contr.sum","contr.poly"))
noiseData<-read.csv("anova2.rm.maxwell_12.1.csv")
model<-lmer(Y ~ T*G + (1|Subject) + (1|T:Subject) + (1|G:Subject), 
data = noiseData, REML = TRUE)
summary(model)
anova(model)

Source

Designing Experiments and Analyzing Data: A Model Comparison Perspective (3rd edition; Maxwell, Delaney, & Kelley, 2018), Table 12.5

Explore the Knowledgebase

Analyze, graph and present your scientific work easily with GraphPad Prism. No coding required.