In: Statistics and Probability
Go into R and view all of the data sets preloaded in R by using the data() command. As you see there are quite a few data sets loaded into R. Now retrieve the dataset women using data(women). This data is from a random sample of 15 women, recording the height and weight of each woman in the sample. I want you to create a 95% confidence interval for the population mean using this data and R.
First find the sample mean using the mean() command and sample standard deviation using the sd() command. Now find t* using the qt() function. Look up help for this function to learn how to use it. Remember that for a 95% CI value, t* you want to find the value t for which P(T14 < t∗) = .975. Construct the margin of error using the R math functions. Now find the upper and lower ends of the confidence interval.
Now go to R help and look up the t.test function. Use the t.test to conduct the hypothesis testH0 : μ = 62.5 with Ha : μ ̸= 62.5. For this application, use women$height in place of x, mu=62.5 for the second argument, and alternative=“two.sided” for the third. Interpret the p-value in terms of your typical test sizes.
Does the null hypothesis value H0 : μ = 62.5 fall in the condfidence interval you constructed earlier? Now pick any value that falls inside the confidence interval you constructed. Conduct the t-test on that as the null value and report the p-value. Try other null values that fall inside your CI and conduct the t-test on these. What is the relationship between a 95% CI and a two-sided hypothesis test withα = .05?
R codes and output:
> data(women)
> women
height weight
1 58 115
2 59 117
3 60 120
4 61 123
5 62 126
6 63 129
7 64 132
8 65 135
9 66 139
10 67 142
11 68 146
12 69 150
13 70 154
14 71 159
15 72 164
> attach(women)
The following objects are masked from women (pos = 3):
height, weight
> m=mean(height);m
[1] 65
> s=sd(height);s
[1] 4.472136
> t=qt(0.975,14);
> me=t*s/sqrt(15);me
[1] 2.476586
> LL = m -me; LL
[1] 62.52341
> UL = m +me;UL
[1] 67.47659
Confidence interval:
Lower Limit = 62.52341
Upper limit = 67.47659
> t.test(height,mu=62.5,alternative='two.sided')
One Sample t-test
data: height
t = 2.1651, df = 14, p-value = 0.04815
alternative hypothesis: true mean is not equal to 62.5
95 percent confidence interval:
62.52341 67.47659
sample estimates:
mean of x
65
P-value is 0.04815 which is less than 0.05, hene we reject null hypothesis and conclude that mean height not equal to 62.5
μ = 62.5 does not fall in the confidence interval ccomputed above.
Let μ = 63
> t.test(height,mu=63,alternative='two.sided')
One Sample t-test
data: height
t = 1.7321, df = 14, p-value = 0.1052
alternative hypothesis: true mean is not equal to 63
95 percent confidence interval:
62.52341 67.47659
sample estimates:
mean of x
65
Let μ = 62.7
> t.test(height,mu=62.7,alternative='two.sided')
One Sample t-test
data: height
t = 1.9919, df = 14, p-value = 0.06626
alternative hypothesis: true mean is not equal to 62.7
95 percent confidence interval:
62.52341 67.47659
sample estimates:
mean of x
65
From above two test we see that if mu fall in the confidence interval then p-value is greater than alpha(0.05).
Hence we accept null hypothesis in both the cases.