[R] Homework help: Is this how CIs of normal distributions arecomputed?

Greg Snow Greg.Snow at intermountainmail.org
Wed Oct 31 22:05:24 CET 2007


There is a z.test function in the TeachingDemos package, but it is
mainly for learning purposes to ease students into using t.test.

The rule of "use the normal for n>30" comes from the days when
computations were done by hand using tables and people did not want to
carry around t-tables with 100's of rows, so they noticed that the row
for 29 df on the t-table is "close" to the normal values for the common
confidence intervals.  If you are using the computer then that does not
apply and you should use the t test and t intervals for any situation
that the computer can compute the t-values for you.  The normal based
confidence intervals should only be used for the paradoxical case where
you know for certain the population standard deviation, but don't know
the mean.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Zembower, Kevin
> Sent: Wednesday, October 31, 2007 1:57 PM
> To: r-help at r-project.org
> Subject: [R] Homework help: Is this how CIs of normal 
> distributions arecomputed?
> 
> 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 
> 
> ______________________________________________
> 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.
> 



More information about the R-help mailing list