Zembower, Kevin
2007-Oct-30 20:24 UTC
[R] Homework help: Is this how CI using t dist are constructed?
I'm trying to replicate some of the examples from my textbook in R (my text uses Minitab). In this problem, I'm trying to construct a 95% confidence interval for these distance measurements [1]:> # Case Study 7.4.1, p. 483 > x <- scan()1: 62 52 68 23 34 45 27 42 83 56 40 12: Read 11 items> alpha<-.95 > mean(x) + qt(c((1-alpha)/2, 1-((1-alpha)/2)), df=length(x)-1) * sd(x)/ sqrt(length(x)) [1] 36.21420 60.51307>Are confidence intervals with the t distribution constructed using this type of equation, or am I overlooking a more concise, 'canned' approach that's already been programmed? Any suggestions on simplifying this? Thanks for all your advice and help. -Kevin [1] An Introduction to Mathematical Statistics and its Applications, fourth ed., Larsen and Marx. 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
Achim Zeileis
2007-Oct-30 20:52 UTC
[R] Homework help: Is this how CI using t dist are constructed?
On Tue, 30 Oct 2007, Zembower, Kevin wrote:> I'm trying to replicate some of the examples from my textbook in R (my > text uses Minitab). In this problem, I'm trying to construct a 95% > confidence interval for these distance measurements [1]: > > > # Case Study 7.4.1, p. 483 > > x <- scan() > 1: 62 52 68 23 34 45 27 42 83 56 40 > 12: > Read 11 items > > alpha<-.95 > > mean(x) + qt(c((1-alpha)/2, 1-((1-alpha)/2)), df=length(x)-1) * sd(x) > / sqrt(length(x)) > [1] 36.21420 60.51307 > > > > Are confidence intervals with the t distribution constructed using this > type of equation, or am I overlooking a more concise, 'canned' approach > that's already been programmed? Any suggestions on simplifying this?R offers a confint() generic with methods for various types of models. If you consider estimation of the mean as a simple linear model (with only an intercept) you can do fm <- lm(x ~ 1) fm to estimate the mean and then confint(fm) to get the confidence interval (by default at 0.95 level). hth, Z> Thanks for all your advice and help. > > -Kevin > > [1] An Introduction to Mathematical Statistics and its Applications, > fourth ed., Larsen and Marx. > > 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. > >
Peter Dalgaard
2007-Oct-30 20:54 UTC
[R] Homework help: Is this how CI using t dist are constructed?
Zembower, Kevin wrote:> I'm trying to replicate some of the examples from my textbook in R (my > text uses Minitab). In this problem, I'm trying to construct a 95% > confidence interval for these distance measurements [1]: > > >> # Case Study 7.4.1, p. 483 >> x <- scan() >> > 1: 62 52 68 23 34 45 27 42 83 56 40 > 12: > Read 11 items > >> alpha<-.95 >> mean(x) + qt(c((1-alpha)/2, 1-((1-alpha)/2)), df=length(x)-1) * sd(x) >> > / sqrt(length(x)) > [1] 36.21420 60.51307 > > > Are confidence intervals with the t distribution constructed using this > type of equation, or am I overlooking a more concise, 'canned' approach > that's already been programmed? Any suggestions on simplifying this? > > Thanks for all your advice and help. >You mean like t.test(x)? -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Greg Snow
2007-Oct-31 15:06 UTC
[R] Homework help: Is this how CI using t dist are constructed?
Doing:> t.test(x)Will give the same CI (among other things), but it is good to do it the long way a couple of times to make sure that you understand what the canned approach is doing (but from now on you can use the t.test function). Also just as a minor terminology correction, usually alpha would be 0.05 from your example, what you have as 0.95 is the confidence level (1-alpha). 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: Tuesday, October 30, 2007 2:25 PM > To: r-help at r-project.org > Subject: [R] Homework help: Is this how CI using t dist are > constructed? > > I'm trying to replicate some of the examples from my textbook > in R (my text uses Minitab). In this problem, I'm trying to > construct a 95% confidence interval for these distance > measurements [1]: > > > # Case Study 7.4.1, p. 483 > > x <- scan() > 1: 62 52 68 23 34 45 27 42 83 56 40 > 12: > Read 11 items > > alpha<-.95 > > mean(x) + qt(c((1-alpha)/2, 1-((1-alpha)/2)), > df=length(x)-1) * sd(x) > / sqrt(length(x)) > [1] 36.21420 60.51307 > > > > Are confidence intervals with the t distribution constructed > using this type of equation, or am I overlooking a more > concise, 'canned' approach that's already been programmed? > Any suggestions on simplifying this? > > Thanks for all your advice and help. > > -Kevin > > [1] An Introduction to Mathematical Statistics and its > Applications, fourth ed., Larsen and Marx. > > 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. >