[R] Calculate confidence interval of the mean based on ANOVA

Joshua Wiley jwiley.psych at gmail.com
Tue Jul 13 19:45:55 CEST 2010


N_runs -1 seems a bit of an odd df to choose to calculate the CI for a
mean.  To answer your question, I think that t.test() is the easiest
way to get a CI in R.  That said, you can use the MS_residuals from
ANOVA to take advantage of variance calculated on groups and pooled.
Something like:

foo <- structure(list(OBS = structure(1:18, .Label = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
"49", "50", "51", "52", "53", "54"), class = "factor"), NOM =
structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = c("0.05", "0.1", "1"), class = "factor"),
RUN = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L,
5L, 5L, 6L, 6L, 6L), .Label = c("1", "2", "3", "4", "5", "6"), class =
"factor"), CALC = c(0.04989, 0.04872, 0.04544, 0.05645, 0.06516,
0.0622, 0.04868, 0.05006, 0.04746, 0.05574, 0.04442, 0.04742, 0.05508,
0.0593, 0.04898, 0.06373, 0.05537, 0.04674)), .Names = c("OBS", "NOM",
"RUN", "CALC"), row.names = c(NA, 18L), class = "data.frame")

foo.aov <- aov(CALC ~ RUN, data = foo)

sdpooled.calc <- sqrt(anova(foo.aov)["Residuals", "Mean Sq"])
mcalc <- mean(foo$CALC)
ncalc <- length(foo$CALC)
t.crit <- qt(p = .05/2, df = 12, lower.tail=FALSE)

#then if memory serves the CI for means formula is

mcalc - ((t.crit * sdpooled.calc)/sqrt(ncalc))
mcalc + ((t.crit * sdpooled.calc)/sqrt(ncalc))

#rm(foo, foo.aov, sdpooled.calc, mcalc, ncalc, t.crit)

Btw, it helps if you send plaintext emails rather than html.

Best regards,

Josh


On Tue, Jul 13, 2010 at 10:14 AM, Paul <paul at paulhurley.co.uk> wrote:
> Paul wrote:
>>
>> I am trying to recreate an analysis that has been done by another group
>> (in SAS I believe).  I'm stuck on one part, I think because my stats
>> knowledge is lacking, and while it's OT, I'm hoping someone here can help.
>>
>> Given this dataframe;
>>
>> <snip>
>
> Well, that will teach me to read the question ! The previous analysis stated
> (quite clearly) that they calculated confidence intervals using number of
> runs - 1 degrees of freedom, so doing my t quantile over 5 df instead of 17
> produced the right answer.
>
> Paul.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list