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

2010-07-13 Thread Joshua Wiley
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  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;
>>
>> 
>
> 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@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/

__
R-help@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.


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

2010-07-13 Thread Paul

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;


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@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.


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

2010-07-12 Thread Paul
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;

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")

I want to perform an anova on CALC~RUN, and based on that calculate the 
95% confidence interval.  However the interval produced by the earlier 
analysis is  [0.04741, 0.05824].  Is there some way to calculate a 
confidence interval based on an ANOVa that I'm completely missing ?

 > nrow(foo)

[1] 18

 > mean(foo$CALC)

[1] 0.05282444

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

 > print(fooaov)

Call:

aov(formula = CALC ~ RUN, data = foo)

Terms:

RUN Residuals

Sum of Squares 0.0003991420 0.0003202277

Deg. of Freedom 5 12

Residual standard error: 0.005165814

Estimated effects may be unbalanced

 > print(summary(fooaov))

Df Sum Sq Mean Sq F value Pr(>F)

RUN 5 0.00039914 7.9828e-05 2.9914 0.05565 .

Residuals 12 0.00032023 2.6686e-05

---

Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

 > model.tables(fooaov,type="means",se=TRUE)

Tables of means

Grand mean

0.05282444

RUN

RUN

1 2 3 4 5 6

0.04802 0.06127 0.04873 0.04919 0.05445 0.05528

Standard errors for differences of means

RUN

0.004218

replic. 3

 > t.test(foo$CALC,conf.level=0.95)

One Sample t-test

data: foo$CALC

t = 34.4524, df = 17, p-value < 2.2e-16

alternative hypothesis: true mean is not equal to 0

95 percent confidence interval:

0.04958955 0.05605934

sample estimates:

mean of x

0.05282444

Thanks

Paul.



[[alternative HTML version deleted]]

__
R-help@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.