10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Using</strong> R <strong>for</strong> introductory statistics 198This distribution is the t-distribution. The standard error and degrees of freedom differdepending on whether or not the variances are equal. The standard error is given byEquation 7.4 and the degrees of freedom by Equation 7.5.If the unsummarized data is available, the t.test() function can be used to compute theconfidence interval <strong>for</strong> the difference of means. It is used ast.test (x, y, var.equal=FALSE, conf.level=0.95)The data is contained in two data vectors, x and y. The assumption on the equality ofvariances is specified by the argument var. equal= with default of FALSE.■ Example 7.9: Comparing independent samples In a clinical trial, a weightloss drugis tested against a placebo to see whether the drug is effective. The amount of weight lost<strong>for</strong> each group is given by the stem-and-leaf plot in Table 3.6. Find a 90% confidenceinterval <strong>for</strong> the difference in mean weight loss.From inspection of the boxplots of the data in Figure 7.6, the assumption of equalvariances is reasonable, prompting the use of t.test() with the argument var.equal=TRUE.Figure 7.6 Boxplots used toinvestigate assumption of equalvariances> x = c(0,0,0,2,4,5,13,14,14,14,15,17,17)> y = c(0,6,7,8,11,13,16,16,16,17,18)> boxplot(list(drug=x,placebo=y), col="gray") # comparespreads> t.test(x,y, var.equal=TRUE)Two Sample t-testdata: x and yt = −1.054, df = 22, p-value = 0.3032alternative hypothesis: true difference in means is notequal to a95 percent confidence interval:−8.279 2.699sample estimates:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!