This preview shows pages 1–2. Sign up to view the full content.
# This lab looks long, but it's not!
# Most of the material is on the web, where you can cut/paste from.
# The majority of this document is explanations  lots of it. So,
# read carefuly.
# 1) Last time, we computed CIs in three ways: a) Using the formula for CI,
# b) Using the function t.test(), and c) using bootstrap, i.e., literally
# doing the resampling and building the empirical sampling distribution
# for the parameter of interest. The 1st method is based on the normal
# distribution. Now, we will do the same thing, but with the tdistribution.
# Three different ways of computing CIs based on tdistribution.
# Copy/paste the next block from the web:
# http://www.stat.washington.edu/marzban/390/lab_CI_supp.txt .
rm(list=ls(all=TRUE))
set.seed(123)
samp.size = 30
# Take a SMALL sample of size 30,
x = rnorm(samp.size,0,1)
# from a normal population with mean=0, sd=1.
# Note: last time, we made a nonnormal population and then took samples
# from it. This time, though, we are taking a sample from a Normal
# population, because that's the only population for which the t.test()
# applies.
###################################################################
## First way: using the formulas that apply to a single sample mean only.
## Note: last week, we computed the zinterval, and so we needed quantiles
## of the normal distribution, i.e. qnorm(). This time, we are building
## tintervals, and so we use qt(), which gives quantiles of the tdistribution.
lower = mean(x) + qt(0.05/2,samp.size1)*sd(x)/sqrt(samp.size)
upper = mean(x)  qt(0.05/2,samp.size1)*sd(x)/sqrt(samp.size)
c(lower,upper)
###################################################################
## Second way: t.test itself, which does exactly what the first way does.
## Obviously, this is the easiest way, but make sure you know what
## assumptions underlie it.
t.test(x)
#
Here is the portion of the output which we need for todays lab:
#
TAs explain these quantities.
#
t = 0.263, df = 29,
# The observed tvalue, and the df.
#
95 percent confidence interval:
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08

Click to edit the document details