Solved – How to compute confidence interval in ANOVA with repeated measures

anovaconfidence intervalrrepeated measures

I made a model using repeated measures univariate ANOVA in R.

> g <- aov(bis ~ x1 + x2 + bg.sol + x1:x2:I(bg.sol * k1) + Error(subject), coded)
> summary.lm(g$Within)
Call:
NULL

Residuals:
     Min       1Q   Median       3Q      Max 
-24.7459  -4.8055  -0.1518   5.1696  17.6015 

Coefficients:
                     Estimate Std. Error t value Pr(>|t|)    
x1                     3.1170     0.8444   3.691 0.000275 ***
x2                    -1.0906     0.1230  -8.864  < 2e-16 ***
I(bg.sol * k1)         2.0522     1.0216   2.009 0.045645 *  
x1:x2:I(bg.sol * k1)  -0.3191     0.1254  -2.545 0.011543 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 7.256 on 246 degrees of freedom
Multiple R-squared: 0.2743, Adjusted R-squared: 0.2654 
F-statistic: 30.99 on 3 and 246 DF,  p-value: < 2.2e-16 

I calculated confidence limit for each estimates. I thought SE * critical value would work. In case of x1 (continuous variable) 95% confidence limit was,

> 0.8444 * qt(0.975, df = 1)
[1] 10.72912

I'm wondering whether the calculated value is real confidence limit for x1. The estimates for x1 is 3.1170, and the limit is 10.72912. Plus-minus it includes zero value. But P-value showed value less than 0.05!

I want to know where I made an error!

Best Answer

As noted in the comments, the issue here was with the degrees of freedom in the calculation of the critical value.

If you had run the anova(·) with the lm() or aov() output, you do indeed have one degree of freedom listed in that row. But that degree of freedom is for the estimate of the variance. The appropriate degrees of freedom for the confidence interval for the effect (i.e., the partial slope of the MR version of the ANOVA) would be the overall model d.f. (which is indeed 246 for this output).