Inference for numerical data
Data 606 Chapter 5 Homework
Heather Geiger; March 25, 2018
Question 5.6
qt(.95,24)
## [1] 1.710882
- Sample mean = mean(c(65,77)) = 71.
- For a confidence interval of 90%, we calculate the t-statistic below which 95% of values fall. This is t=1.71 for df=24. We then solve for the equations 71 - (1.71 x se_mean) = 65 or 71 + (1.71 x se_mean) = 77. This gives standard error of the mean equal to (6/1.71) ~ 3.508772 (~3.51) or “margin of error” equal to 6.
- We solve the equation sd/sqrt(n) = standard error of the mean here. So we solve for sd/sqrt(25) = 3.508772, so sd = 5*3.508772 = 17.54. The sample has a standard deviation of 17.54.
Question 5.14
qnorm(0.95)
## [1] 1.644854
qnorm(0.995)
## [1] 2.575829
- Let’s use a t-statistic for n=infinity, which is the same as getting value in a normal distribution. For a 90% confidence interval, we find that 95% of values will fall below t=1.645. So, we solve for the equation t x standard error of the mean = 25. 1.645 x standard error of the mean = 25, so standard error of the mean = 15.199. Next, sd/sqrt(n) = standard error of the mean. So 250/sqrt(n) = 15.199, sqrt(n) = 16.44854. n equals to 270.5543, round up to 271. We need to sample at least 271 people to have margin of error (which we define as t x standard error of the mean) less than 25.
- A larger percent confidence interval means we need to make the interval wider, which means we need a larger sample size so we can have a smaller denominator for the standard error of the mean equation.
- The t-statistic for n=infinity and 99% confidence interval is t=2.5758. t x standard error of the mean = 25, standard error of the mean = 9.7056. Next, sd/sqrt(n) = standard error of the mean. So 250/sqrt(n) = 9.7056, sqrt(n) = 25.75829. n equals to 663.4897, round up to 664. We need to sample at least 664 people to have margin of error less than 25.
Question 5.20
pt(-0.545/0.6284,199)
## [1] 0.1934161
- There is not a clear difference in the average reading and writing scores based on these plots. Sometimes the reading score is higher, sometimes the writing score is higher, sometimes they are both very similar.
- No, the reading and writing scores of each student are not independent of each other, as they come from the same student and thus are paired.
- Null hypothesis - reading and writing scores for the same student are equal. Alternative hypothesis - reading and writing scores for the same student are different (either reading or writing is systematically higher).
- To complete a test based on differences, each student’s scores reading and writing scores need to be independent from other students’ reading and writing scores. Assuming a lot of students take this test, the sample size is less than 10% of the population and seems to be met. The assumption that the differences in scores are normally distributed also seems to fit based on the histogram. And even if it didn’t, sample size is large enough to withstand even pretty severe skew here.
- Standard error of the mean here = 8.887/sqrt(200) = 0.6284. So t = -0.545/0.6284 = -0.867. P-value of this t-statistic given df=199 = 0.19. There is not convincing evidence of a difference between the average scores on the two exams.
- We may have made a type 2 error, where we incorrectly retained the null hypothesis. This is also known as a false negative, where there actually was a difference, but we failed to detect it.
- Yes, based on the results of this hypothesis test we would expect a confidence interval around the average difference between reading and writing scores to include 0. We reject the null hypothesis when the null hypothesis does not fall within our confidence interval. Here we failed to reject because the null hypothesis was included in the confidence interval.
Question 5.32
standard_error <- sqrt((3.58^2/26) + (4.51^2/26))
diff_means <- 19.85 - 16.12
t <- diff_means/standard_error
df <- 25
t
## [1] 3.30302
signif((1 - pt(t,df))*2,3)
## [1] 0.00288
Yes, these data do provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average city mileage (t=3.303, df=25, p two-tailed=0.00288). These results are quite significant (p < .01).
Question 5.48
501.54*4
## [1] 2006.16
501.54*4 + 267382
## [1] 269388.2
267382/1167
## [1] 229.1191
501.54/(267382/1167)
## [1] 2.188992
F <- 501.54/(267382/1167)
1 - pf(F,4,1167)
## [1] 0.06819325
fill_in_table <- data.frame(Df = c(4,1167,1171),
Sum.Sq = c(501.54*4,267382,501.54*4 + 267382),
Mean.Sq = c(501.54,267382/1167,NA),
F.value = c(501.54/(267382/1167),NA,NA),
row.names=c("degree","Residuals","Total"))
fill_in_table
## Df Sum.Sq Mean.Sq F.value
## degree 4 2006.16 501.5400 2.188992
## Residuals 1167 267382.00 229.1191 NA
## Total 1171 269388.16 NA NA
- Null hypothesis is that the mean number of hours worked is the same for all five educational attainment groups. Alternative hypothesis is that the mean number of hours worked varies across some (or all) groups.
- The population of people with each level of educational attainment is quite large, so we can assume that the samples of each individual group are independent. There is also no reason to believe that the 5 group samples are not independent from each other. The assumption of normality is less certain here, as we see some outliers on the boxplots. However, the sample sizes of each group are quite large (at or very close to 100), so they can handle some skew. We should be able to make inferences here using an ANOVA test.
- Df1 is equal to number of groups - 1 = 4. Df2 is equal to total n - number of groups = 1172 - 5 = 1167. Sum Sq for the main variable is equal to Mean Sq * df1 = 501.54 * 4 = 2006.16. Mean Sq for the residuals is equal to Sum Sq / df2 = 267382/1167 = 229.12. F statistic is equal to 501.54/229.12 = 2.19. To check that this F statistic is correct, we calculate the p-value for this F statistic and compare to what is in the table. We find that the p-value is the same, so our F statistic is correct.
- The conclusion of the test is that there is not enough evidence to suggest that people with different levels of educational attainment have different numbers of hours worked. Even using a relatively lenient alpha of .05, the p-value of F is too large here.