ANOVA – How to Implement a Two-Way ANOVA with Nesting in R or SPSS

anovarspssstatistical significancet-test

I currently am conducting a study where I have three variables: one that is binary, and two numerical ratio variables. Each of the subjects in my study has values for each of the three variables.

Variables:

  • Condition (binary): Values 0 and 1
  • Pre (ratio)
  • Post (ratio)

I want to test if there is a significant difference between the the pre and post variables of the 0 control group and the 1 experimental group. Both groups have 103 subjects. The data meet all typical ANOVA assumptions such as normality and the like. I was thinking of nesting the variables as follows and then running a two-way ANOVA.

Variable 1 is exposed / not and variable 2 is pre / post. People are nested in Variable 1 (meaning that each person gives both pre and post information for either exposed or not exposed conditions)

Would this be the correct way to approach this problem? Also how would I implement this statistical analysis, preferably in R or SPSS?

Best Answer

Pre-post designs are quite common and the standard method is to use the pre-measure as a control variable and the post-measure as the response with the binary variable as the covariate.

This is quite simple:

m0 <- lm(Post ~ Pre, data=dat)
m1 <- lm(Post ~ Pre+Condition, data=dat)
anova(m1,m0) # test for difference in mean(Post) after control for Pre
m2 <- lm(Post ~ Pre*Condition, data=dat) 
anova(m2, m1) # test for interaction: different slopes in the two Conditions

If this had been with repeated measures within subject (i.e, pre-post measures in each Condition, you would need to specify the error structure in the aov function: You could compare this model in R where the errors for each Condition are nested in subject-ID:

 m1 <- aov(post ~ pre + Condition+Error(subjID/Condition), data=dat)

Ratio variables are notorious for being poorly behaved statistically (i.e., often having significant skew and blowing up as the denominator goes near zero.) However, if the denominator is far from zero, you should not make the mistake of looking at the raw distributions and deciding that the data fail the assumptions needed for validity of linear methods. You need to look at the residuals before conducting any test. (And even then, there is some doubt whether minor departures from normality invalidate inferences.) The help page for aov warns you to use orthogonal contrasts. There was an article in R-News several years ago on multi-variate (as opposed to multi-variable) methods and this would provide further options for model comparisons and measures of sphericity.

Another option is offered by the Anova function in John Fox's car package.

A useful link: http://blog.gribblelab.org/2009/03/09/repeated-measures-anova-using-r/

Another approach is to analyze the pairwise differences, but that approach has flaws.

Related Question