[R] Homework help: Is this how CIs of normal distributions are computed?
Zembower, Kevin
kzembowe at jhuccp.org
Wed Oct 31 20:56:37 CET 2007
I'm looking for a function in R similar to t.test() which was generously
pointed out to me yesterday, but which can be used for normally
distributed data.
To recap yesterday:
> x <- scan()
1: 62 52 68 23 34 45 27 42 83 56 40
12:
Read 11 items
> alpha<- .05
> t.test(x)
One Sample t-test
data: x
t = 8.8696, df = 10, p-value = 4.717e-06
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
36.21420 60.51307
sample estimates:
mean of x
48.36364
What if I now mock-up my data for 100 trials:
> x100<-sample(x, 100, replace=TRUE)
I think that I should be able to use a normal distribution, because of
the n>30 rule-of-thumb.
I can compute the 95% CI using:
> mean(x100) - qnorm(alpha/2)*sd(x100)/sqrt(length(x100))
[1] 51.91222
> mean(x100) + qnorm(alpha/2)*sd(x100)/sqrt(length(x100))
[1] 44.80778
> t.test(x100)
One Sample t-test
data: x100
t = 26.683, df = 99, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
44.76383 51.95617
sample estimates:
mean of x
48.36
>
The critical values I compute manually are close to the t.test values,
which is what I expect. As the number of samples increases, the t value
approaches the normal distribution value.
I thought I looked at all the other .test functions in the stats
package, and didn't find one that computed results like the t.test for
normal distributions. Is something similar to my 'manual' computations
the way it's done in R, or have I overlooked something again?
Thanks.
-Kevin
Kevin Zembower
Internet Services Group manager
Center for Communication Programs
Bloomberg School of Public Health
Johns Hopkins University
111 Market Place, Suite 310
Baltimore, Maryland 21202
410-659-6139
More information about the R-help
mailing list