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 is upper bound + lower bound / 2.
cat("The sample mean is",(77+65)/2,"\n")
## The sample mean is 71
#Margin of error is upper bound - mean.
cat("The margin of error is",77-((77+65)/2),"\n")
## The margin of error is 6
#Standard deviation is standard error (margin of error / qt(.95, n - 1)) * sqrt(n).
cat("The standard deviation is",((77-((77+65)/2))/(qt(.95,24)))*sqrt(25))
## The standard deviation is 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.
\[ME=z \times SE \implies SE=\frac{ME}{z}\]
\[SD=SE\times \sqrt{n} \implies n = \bigg( \frac{SD}{SE} \bigg)^2 \implies n = \bigg( \frac{SD}{\frac{ME}{z}} \bigg)^2 \implies n = \bigg( \frac{z \times SD}{ME} \bigg)^2\]
#z-score for 90% confidence interval is 1.645.
cat("For a 90% confidence interval, Raina's sample size should be",round(((1.645*250)/25)^2))
## For a 90% confidence interval, Raina's sample size should be 271
Luke’s sample size must be larger to accommodate the variation in the sample; as z-score increases, confidence intervals increase.
#z-score for 99% confidence interval is 2.576.
cat("For a 99% confidence interval, Luke's sample size should be",round(((2.576*250)/25)^2))
## For a 99% confidence interval, Luke's sample size should be 664
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 mean reading and writing scores; median score for writing scores is slightly higher and the range for writing scores is smaller.
Yes, the reading and writing scores of each student are independent.
\(H_0\): there is no evident difference in the mean difference of scores in reading and writing on the two exams (difference = 0)
\(H_A\): there is an evident difference in the mean difference of scores in reading and writing on the two exams (difference \(\neq\) 0)
As stated before, the scores of each student are independent, the sample size is sufficient, and the distribution is approximately normal.
#find standard error
se <- 8.8817/(sqrt(200))
#find t stat
tval <- (-.545-0)/se
pval <- pt(tval, df = 199)
pval
## [1] 0.1932769
There is no evident difference in mean difference of reading and writing scores on the two exams (p-val = 0.1932769 > .05).
A type I error implies that we have incorrectly rejected the null hypothesis; a type II error implies that we incorrectly failed to reject the null hypothesis. In the context of this application, we may have committed a type II error by incorrectly failing to reject the null hypothesis, which means that we may have concluded–incorrectly–that there is no difference in the mean difference of the reading and writing scores of the two exams.
Yes; we are asserting that random sample mean score differences will be approximately 0, so any confidence interval should include this value in the specified range.
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.
Our premise:
\(H_0\): there is no significant difference in the auto and manual mean MPG (difference = 0)
\(H_A\): there is a significant difference in the auto and manual mean MPG (difference = 0)
#from the text
n <- 26
mean.auto <- 16.12
sd.auto <- 3.58
mean.manual <- 19.85
sd.manual <- 4.51
mean.df <- mean.auto - mean.manual
SE.df <- (((sd.auto^2)/n) + ((sd.manual^2)/n))^0.5
t.stat <- (mean.df-0)/SE.df
pval <- pt(t.stat, df = n-1)
pval
## [1] 0.001441807
We reject the null hypothesis and conclude that there is a significant difference in automatic and manual fuel efficiency; cars with automatic transmissions are more efficient (p = 0.0014418 < .05).
The General Social Survey collects data on demographics, education, and work, among many other characteristics of US residents. 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.
\(H_0\): mean hours worked is the roughly equivalent across all groups
\(H_A\): mean hours worked is not equivalent across groups
Distribution is approximately normal, observations are independent and sample size is sufficient for analysis.
library(kableExtra)
mean.gss <- c(38.67, 39.6, 41.39, 42.55, 40.85)
s.dev <- c(15.81, 14.97, 18.1, 13.62, 15.51)
n.gss <- c(121, 546, 97, 253, 155)
data_table <- data.frame (mean.gss, s.dev, n.gss)
n <- colSums(data_table[3])
k <- nrow(data_table)
df <- k-1
dfResidual <- n-k
dftotal <- df + dfResidual
# Use P to determine F Stat
pval <- .0682
Fstat <- qf(1-pval, df, dfResidual)
# Use MSR and F to determine MSG
MSG <- 501.54
MSR <- MSG/Fstat
# Use MSR to determine SSR
SSG <- df*MSG
SSR <- 267382
SST <- SSG+SSR
ANOVA <- c("degree", "residuals", "total")
Df <- c(df, dfResidual, dftotal)
Sum.Sq <- c(SSG, SSR, SST)
Mean.Sq <- c(MSG, MSR, "")
F.value <- c(Fstat, "", "")
p.value <- c(pval, "", "")
ANOVA.df <- data.frame(ANOVA, Df, Sum.Sq, Mean.Sq, F.value, p.value)
kable(ANOVA.df)%>%
kable_styling("bordered")
| ANOVA | Df | Sum.Sq | Mean.Sq | F.value | p.value |
|---|---|---|---|---|---|
| degree | 4 | 2006.16 | 501.54 | 2.18893121413288 | 0.0682 |
| residuals | 1167 | 267382.00 | 229.125518774549 | ||
| total | 1171 | 269388.16 |
We accept the null hypothesis; mean hours worked are roughly equivalent across all educational attainment levels (p = 0.0682 > .05).