Working backwards, Part II. (5.24, p. 203) 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.

n = 25
up = 77
low = 65
mean = (up + low)/2
mean
## [1] 71
margin_error = (up - low)/2
margin_error
## [1] 6
df = n - 1
# df
a = 1-.9
quant =  (1-(a/2))
t = qt(quant, df)
# t
# ME = t*(s/sqrt(n))
s = 6 * sqrt(25)/t
s
## [1] 17.53481

SAT scores. (7.14, p. 261) 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.

  1. Raina wants to use a 90% confidence interval. How large a sample should she collect?
sd = 250
me = 25
# me = z*sd/sqrt(n)
# n = (z*sd/me)^2
ci = .9
alpha = (1-ci)/2
z = qnorm(alpha)
n = (z*sd/me)^2
n
## [1] 270.5543
# round up so 271 students or more
  1. Luke wants to use a 99% confidence interval. Without calculating the actual sample size, determine whether his sample should be larger or smaller than Raina’s, and explain your reasoning.
# His sample size should be larger. The larger confidence interval means a
# larger z-score. Looking at the equation for margin of error and solving for
# n, you get n = (z * sd/me)^2. We see that a larger z increases the
# numerator, thus a larger n
  1. Calculate the minimum required sample size for Luke.
ci = .99
alpha = (1-ci)/2
z = qnorm(alpha)
n = (z*sd/me)^2
n
## [1] 663.4897
# round up so 664 students or more

High School and Beyond, Part I. (7.20, p. 266) 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.

  1. Is there a clear difference in the average reading and writing scores?
There is not a clear difference between reading and writing scores.
The medians and IQRs are around the same area and the
histogram of the differences seems to be unimodal and centered
around 0
  1. Are the reading and writing scores of each student independent of each other?
No. It is the same student giving both a reading and writing score. So the
scores are not independent. You might expect that a better student has higher
scores on both reading and writing.
  1. Create hypotheses appropriate for the following research question: is there an evident difference in the average scores of students in the reading and writing exam?
H0: mean_reading_score - mean_writing_score = 0
HA: mean_reading_score - mean_writing_score != 0
  1. Check the conditions required to complete this test.
n is large enough and less than 10% of the population. We are told
the 200 were sampled randomly. The sampling distribution of the
sample mean should be approximately normal.
  1. The average observed difference in scores is \({ \widehat { x } }_{ read-write }=-0.545\), and the standard deviation of the differences is 8.887 points. Do these data provide convincing evidence of a difference between the average scores on the two exams?
mean_diff = -.545
n = 200
df = n - 1
# We can calculate a confidence interval for the true mean
sample_sd = 8.887
sd_error = sample_sd/sqrt(n)
sd_error
## [1] 0.6284058
t = mean_diff/sd_error
p_val = pt(t, df)
p_val
## [1] 0.1934182
# This is not convincing evidence of a difference. We have a p-value of 19.34%
# so we would not reject the null hypothesis even at an 82% confidence level
  1. What type of error might we have made? Explain what the error means in the context of the application.
We may have made a type 2 error, which is failing to reject the null when we
should have rejected it. So, there would actually be a difference in the means
of the reading and writing scores, but we don't detect it.
  1. Based on the results of this hypothesis test, would you expect a confidence interval for the average difference between the reading and writing scores to include 0? Explain your reasoning.
I expect it to include 0 because our standard error is .6284. Just one 
standard deviation of the difference of means
includes 0, so our margin of error for a 65% confidence interval
already includes 0.

Fuel efficiency of manual and automatic cars, Part II. (7.28, p. 276) The table provides summary statistics on highway fuel economy of cars manufactured in 2012. Use these statistics to calculate a 98% confidence interval for the difference between average highway mileage of manual and automatic cars, and interpret this interval in the context of the data.

# Independence: 26 cars are less than 10% of cars
# Randomized: Assuming randomly sampled
# Normal: Distributions seem mostly symmetric
n1 = 26
sd1 = 5.29
mean1 = 22.92
n2 = 26
sd2 = 5.01
mean2 = 27.88
df = min(n1 - 1, n2 - 2)
SE = sqrt(sd1^2/n1 + sd2^2/n2)
mean = mean1 - mean2
t_score = qt(.01, df)
lower = mean + t_score*SE
upper = mean - t_score*SE
lower
## [1] -8.520999
upper
## [1] -1.399001
# We are 98 % confident that the true difference in mpg for automatic vs manual
# lies between -8.52 and -1.39 mpg

Email outreach efforts. (7.34, p. 284) A medical research group is recruiting people to complete short surveys about their medical history. For example, one survey asks for information on a person’s family history in regards to cancer. Another survey asks about what topics were discussed during the person’s last visit to a hospital. So far, as people sign up, they complete an average of just 4 surveys, and the standard deviation of the number of surveys is about 2.2. The research group wants to try a new interface that they think will encourage new enrollees to complete more surveys, where they will randomize each enrollee to either get the new interface or the current interface. How many new enrollees do they need for each interface to detect an effect size of 0.5 surveys per enrollee, if the desired power level is 80%?

mean = 4
sd = 2.2
power = .8
me = .5
# assume alpha = .05 for H0 (95% CI)
z_h0 = 1.96
# Power of 80% = Z of .84
z_hA = .84
z_tot = z_h0 + z_hA
# Using SE = sqrt(sd^2/n1 + sd^2/n2) and me = z_tot * se, solve for n1/n2
# assuming n1 = n2. n = (z_tot*sqrt(sd^2 + sd^2)/me)^2
n = (z_tot*sqrt(sd^2 + sd^2)/me)^2
n
## [1] 303.5648
# round up to whole human. Need 304 enrollees

Work hours and education. 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.

  1. Write hypotheses for evaluating whether the average number of hours worked varies across the five groups.
H0: There is no difference between the average number of hours worked across the 5 groups
HA: There is a difference between the average number of hours worked for at least one of the groups
  1. Check conditions and describe any assumptions you must make to proceed with the test.
#We assume random sampling over the dataset. 
# n = 1172 which is less than 10 % of population from the 47 states
# sampled so we assume independence
#The data should be nearly normal with similar spread across all groups.
# which looks to be the case over the groups, with maybe an exception
# for bachelors.
  1. Below is part of the output associated with this test. Fill in the empty cells.
# degree
k = 5
n = 1172
df_g = k - 1
# residuals
df_e = n - k
df_tot = df_g + df_e
# We are given SSE = 267382.
SSE = 267382
# We are given MSG = 501.54.
MSG = 501.54
#MSG = SSG/df_g
SSG = MSG*df_g
SST = SSE + SSG
MSE = SSE/df_e
F_val = MSG/MSE
df_g
## [1] 4
df_e
## [1] 1167
df_tot
## [1] 1171
SSG
## [1] 2006.16
SST
## [1] 269388.2
MSE
## [1] 229.1191
F_val
## [1] 2.188992
  1. What is the conclusion of the test?
p-val is greater than our usual .05, so we fail to reject the null.
There is not enough evidence to suggest that the means for one of
the groups is different.