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.
mean <- (65 + 77)/2
# CI = mean +/- (Margin of Error) --> (Margin of Error) = CI - mean
margin.error <- 77 - mean
#(Margin of Error) = T * (standard deviation)/sqrt(n observations)
st.dev <- (margin.error/2.06) * sqrt(25)
paste("Sample Mean: ", mean)
## [1] "Sample Mean: 71"
paste("Margin of Error: ", margin.error)
## [1] "Margin of Error: 6"
paste("Sample Standard Deviation: ", round(st.dev,2))
## [1] "Sample Standard Deviation: 14.56"
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.
z <- qnorm(.95, mean = 0, sd = 1)
sat.sd <- 250
margin.error2 <- 25
sat.size <- (sat.sd/(margin.error2/z))^2
paste("Raina should collect", round(sat.size,0), "students.")
## [1] "Raina should collect 271 students."
Luke’s sample will need to be bigger.
z1 <- qnorm(.995, mean = 0, sd = 1)
sat.sd <- 250
margin.error3 <- 25
sat.size1 <- (sat.sd/(margin.error3/z1))^2
paste("Luke should collect", round(sat.size1,0)+1, "students.")
## [1] "Luke should collect 664 students."
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.
There is no clear difference in the average reading and writing scores on visual inspection.
Given that this is a 200 student sampling form a large database from the National Center of Education Statistics, it is presumed that they are independent as well as the sampling is likely less than 10% of the total sample in the survey.
H0 (Null hypothesis): The difference in the average scores of students in the reading and writing exam == 0 HA (Alternative hypothesis): The difference in the average scores of students in the reading and writing exam != 0
Because these are samples picked from a survey and represent less than 10% of of the entire survey, it is likely independent. Given that this is a large database, it is presumed that it likely has a normal (or near normal) distribution. And even if there is a skew, this can be ignored given the fact that there is 200 in the sample size. The box plots demonstrate little skew as well.
st.er <- 8.887/sqrt(200)
Tscore <- (0.545 - 0)/st.er
paste("T score:", round(Tscore,3))
## [1] "T score: 0.867"
This may potentially be a type II error. This means that we may have not enough samples to power our study to detect a difference.
Yes, since we failed to reject H0, which had a null value of 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.
library(openintro)
fuel_eff <- read.csv("https://github.com/jbryer/DATA606Fall2019/raw/master/course_data/fuel_eff.csv", stringsAsFactors = TRUE)
man_rows <- which(fuel_eff$transmission == "M")
aut_rows <- which(fuel_eff$transmission == "A")
set.seed(3583)
man_rows_samp <- sample(man_rows, 26)
aut_rows_samp <- sample(aut_rows, 26)
fuel_eff_samp <- fuel_eff[c(man_rows_samp,aut_rows_samp), ]
fuel_eff_samp$transmission <- droplevels(fuel_eff_samp$transmission)
levels(fuel_eff_samp$transmission) <- c("automatic", "manual")
boxPlot(fuel_eff_samp$hwy_mpg, fact = fuel_eff_samp$transmission, ylim = c(10, 37),
xlab = "Hwy MPG", axes = FALSE, xlim = c(0.5, 2.5))
axis(1, at = c(1,2), labels = c("automatic","manual"))
axis(2, at = c(15,25,35))
X = 22.92 - 27.88
SE = (5.29^2/26 + 5.01^2/26)^0.5
Z = 2.326
ME = Z*SE
CI = X + c(-ME,ME)
CI
## [1] -8.283576 -1.636424
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%?
X = 4
SD = 2.2
Z = 1.282
ME = 0.5
n = (Z * SD / ME) ^ 2
ceiling(n)
## [1] 32
They would need 32 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.
The average number of hours worked do not vary across groups. HA: The average number of hours worked do vary across groups
The observations are independent within and across groups: true assuming no one works two of these jobs. The data within each group are nearly normal: true. The variability is similar across groups: true as assumption.
total_mean <- 40.1
mean_all <- c(38, 39.6, 41, 42.50, 41)
SD_all <- c(15.81, 14.97, 18.1, 13.62, 15.51)
n_all <- c(120, 550, 100, 255, 160)
Groups <- 5
SSG = sum(n_all*(mean_all - total_mean)^2)
MSG = 501.54
SSE = 267382
SST = SSE + SSG
MSE = SSE/1167
F = MSG/MSE
PrF = pf(F, 4, 1167, lower.tail = FALSE)
SSG
## [1] 2346.1
SST
## [1] 269728.1
MSE
## [1] 229.1191
SSG
## [1] 2346.1
F
## [1] 2.188992
PrF
## [1] 0.06819325
Assuming a significance level of 0.05, we cannot reject the hypothesis as p > 0.05 (p = 0.068). Therefore, we conclude that there is no significant variation in work hours between groups.