Chapter 5 - Inference for Numerical Data
Practice: 5.5, 5.13, 5.19, 5.31, 5.45
Graded: 5.6, 5.14, 5.20, 5.32, 5.48
A 90% confidence interval for a population mean is (65, 77). The population distribution is approximately normal and the population standard deviation is unknown. This confidence interval is based on a simple random sample of 25 observations. Calculate the sample mean, the margin of error, and the sample standard deviation.
#sample mean midpoint of confidence interval
sm_5.6 = (65 + 77)/2
sm_5.6
## [1] 71
#margin of error - upper CI - mean
me_5.6 = 77 - sm_5.6
me_5.6
## [1] 6
#find t score two-sided so .05, 25-1 df
ts_5.6 <- abs(qt(.05,df=24))
#me/z score * sqrt(n)
ssd_5.6 = me_5.6/ts_5.6 * sqrt(25)
ssd_5.6
## [1] 17.53481
SAT scores of students at an Ivy League college are distributed with a standard deviation of 250 points. Two statistics students, Raina and Luke, want to estimate the average SAT score of students at this college as part of a class project. They want their margin of error to be no more than 25 points.
#need margin of error <= 25 at 2-sided 90% CI
#SD = me/t-score * sqrt(sample)
#sample = ((SD * t-score)/me)^2
#because sample will be above 30 and we don't know df, we'll use z score here
z_5.14 <- qnorm(.95,mean = 0, sd = 1)
samp_5.14 <- ((250 * z_5.14)/25)^2
samp_5.14
## [1] 270.5543
We round up here obviously, so Raina should collect 271.
More certainty requires a bigger sample. Larger. As shown below, the z score would be larger, leading to a larger sample if calculated as well.
#.995 because it's two-sided
z_5.14b <- qnorm(.995,mean = 0, sd =1)
z_5.14b
## [1] 2.575829
samp_5.14b <- ((250 * z_5.14b)/25)^2
samp_5.14b
## [1] 663.4897
664 sample size - more than double the required sample to get the extra 4% confidence.
The National Center of Education Statistics conducted a survey of high school seniors, collecting test data on reading, writing, and several other subjects. Here we examine a simple random sample of 200 students from this survey. Side-by-side box plots of reading and writing scores as well as a histogram of the differences in scores are shown below.
Reading scores appear to be slightly lower though this is not clearly significant. The differences between scores show a nearly normal distirbution.
The scores of the students are likely independent from each other, but the reading and writing scores of the same student are paired and may not be independent.
H0: writing_score = reading_score
HA: writing_score <> reading_Score
The first condition - that it’s from a random sample with less than 10% of total population seems true. The observations from student to student are independent from each other, satisfying the second conditon - I think. With the paired data, it might be tricky.
#SE = SD/sqrt(n)
SE_5.20 <- 8.887/sqrt(200)
#t score by taking diff / SE
t_5.20 <- .545/SE_5.20
#t score
t_5.20
## [1] 0.867274
#p value for df 199 two-tailed
p_5.20 <- 2* pt(-abs(t_5.20),df=199)
p_5.20
## [1] 0.3868365
Fail to reject null hypothesis that there are clear differences between the average scores on the two exams.
A Type II error is when you fail to reject the null hypothesis even though it is not true. If there is a significant difference between reading and writing scores, we failed to detect it.
Yes, we would expect the CI for the average difference to include 0 given that it’s a two-tailed test and that we failed to reject the hypothesis that there was a clear difference between math and reading scores.
Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2012. Do these data 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? Assume that conditions for inference are satisfied.
H0: manual_mpg = auto_mpg HA: manual_mpg <> auto_mpg
auto_mean <- 16.12
manual_mean <- 19.85
auto_sd <- 3.58
manual_sd <- 4.51
n <- 26
diff_mean <- manual_mean - auto_mean
#standard error for differences is square root of sum of each SD squared divided by n
se_5.32 <- sqrt((manual_sd^2/n) + (auto_sd^2/n))
t_5.32 <- diff_mean/se_5.32
t_5.32
## [1] 3.30302
#p value for df 25 two-tailed
p_5.32 <- pt(q=-abs(t_5.32),df=25,lower.tail = TRUE)
p_5.32
## [1] 0.001441807
P value is .0014, so we fail to reject null hypothesis that cars with automatic and manual transmissions have the same average fuel efficiency. Extremely strong evidence that manual cars get better miles per gallon.
The General Social Survey collects data on demographics, education, and work, among many other characteristics of US residents.47 Using ANOVA, we can consider educational attainment levels for all 1,172 respondents at once. Below are the distributions of hours worked by educational attainment and relevant summary statistics that will be helpful in carrying out this analysis.
H0: 5 groups have same average number of hours worked HA: At least 1 group has a clear difference in number of hours worked
We will assume that the 1,172 were randomly selected - that’s certainly fewer than 10% of the population. All groups have more than 30 responses. While the bachelor’s group looks to be skewed, the other groups look normally distributed.
#f = msg/mse
n_5.48 <- 1172
groups_5.48 <- 5
#known knowns
sum_squares_residuals <- 267382
mean_squares_degress <- 501.54
df_degree <- groups_5.48 - 1
df_degree
## [1] 4
df_residuals <- n_5.48 - groups_5.48
df_residuals
## [1] 1167
sum_squares_degrees <- df_degree * mean_squares_degress
sum_squares_degrees
## [1] 2006.16
mean_squares_residuals <- sum_squares_residuals/df_residuals
mean_squares_residuals
## [1] 229.1191
df_total <- df_degree + df_residuals
df_total
## [1] 1171
sum_squares_total <- sum_squares_degrees + sum_squares_residuals
sum_squares_total
## [1] 269388.2
f_value <- mean_squares_degress/mean_squares_residuals
f_value
## [1] 2.188992
#check work with p-value
p_value <- pf(q = f_value, df_degree, df_residuals, lower.tail = FALSE)
p_value
## [1] 0.06819325
Ties out.
Assuming we’re looking at a .95 confidence level, our p-value of .068 exceeds .05, so we fail to reject the null hyptohesis that there are significant differences in hours worked by education attainment.