<p>R LAB THREE: Inferences for One Population Mean </p><p>Topics: confidence intervals; one sample z intervals/tests; one sample t intervals/tests</p><p>R textbook: Sections 5.1, 5.2 </p><p>Data: Daily energy expenditure for lean and obese women data (energy.txt) posted on the class webpage.</p><p>1) Read the data from the webpage into RStudio</p><p>As shown in the picture, click “From Web URL…” and type/paste the link of the data file, which is http://www.sci.csueastbay.edu/~sfan/SubPages/CSUteach/st3502/labs/energy.txt</p><p>2) Inference for the mean expenditure (ignoring stature group for now)</p><p>> summary(energy$expend) Min. 1st Qu. Median Mean 3rd Qu. Max. 6.130 7.660 8.595 8.979 9.900 12.790</p><p> One sample t method</p><p>R code: </p><p>#normaility checking qqnorm(energy$expend) qqline(energy$expend,col=2) shapiro.test(energy$expend) t.test(energy$expend,mu=8.5,alternative="two.sided",conf.level = .90)</p><p>R output: Shapiro-Wilk normality test data: energy$expend W = 0.95418, p-value = 0.3812</p><p>1 One Sample t-test data: energy$expend t = 1.3238, df = 21, p-value = 0.1998 alternative hypothesis: true mean is not equal to 8.5</p><p>90 percent confidence interval: 8.356339 9.601843 sample estimates: mean of x 8.979091 </p><p>Note: The four R functions for t distribution with degree of freedom of df dt(x, df) returns the t probability density at x pt(q, df) returns the t cumulative probability at q, P[t < q] qt(p, df) returns the (p*100)th percentile of t rt(n, df) returns n random numbers generated from t distribution</p><p>Power and sample size calculation: see R document (help(power.t.test))</p><p># Ott, 6th ed., eg. 5.11 power.t.test(delta=.1,sd=.225,sig.level=.05,power=.99,type="one.sample",alternative="one.sided") # Ott, 6th ed., eg. 5.8 power.t.test(n=50,delta=15,sd=35.2,sig.level=.01,type="one.sample",alternative="one.sided")</p><p> One sample z method</p><p>R does not have a function for z method and thus we need to calculate the confidence interval and z test statistic ourselves. Yet, we can use R to find statistics, such as sample mean and sample S.D., critical value and p value.</p><p>Note that if n is greater than 200, z method is almost the same as t method.</p><p> Wilcoxon signed rank test</p><p>R code: wilcox.test(energy$expend,mu=8.5) R output: </p><p>Wilcoxon signed rank test with continuity correction data: energy$expend V = 159, p-value = 0.2988 alternative hypothesis: true location is not equal to 8.5</p><p>2</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages2 Page
-
File Size-