set working environment

require(rvest)
## Loading required package: rvest
## Loading required package: xml2
require(dplyr)
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
require(stringr)
## Loading required package: stringr
require(tidyr)
## Loading required package: tidyr
require(dplyr)
require(ggplot2)
## Loading required package: ggplot2

5.6 Working backwards, Part II. 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
smean <- (65 + 77)/2
smean
## [1] 71
me <- (77-65)/2
df <- n-1
t<- qt(.95, df)

se <- round(me/t, 3)
se
## [1] 3.507
sd <- round(se*sqrt(n), 3)
sd
## [1] 17.535

Sample mean is equals to 71, the margin of earor is 3.507, the sample standard deviation is 17.535

5.14 SAT scores. 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. (a) Raina wants to use a 90% confidence interval. How large a sample should she collect?

Sd: standard deviation; me: margin error; z: z score

sd <- 250
me <- 25
z <- qnorm(0.95)
n <- round(((sd * z)/me)^2, 0)
n
## [1] 271

The sample size should be 271.

  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.

Answer: because Luke use 99% confidence interval which is bigger than Raina’s (90%), Luke should use larger sample size.

  1. Calculate the minimum required sample size for Luke.
z <- qnorm(0.995)
n <- round(((sd * z)/me)^2, 0)
n
## [1] 663

Sample size is 663.

5.20 High School and Beyond, Part I. 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 di???erences in scores are shown below.

  1. Is there a clear di???erence in the average reading and writing scores?

No, there is no a clear difference in average reading and writing scores.

  1. Are the reading and writing scores of each student independent of each other?

The reading and writing scores do not looklike independent to each other. Acutually, it looks like paired with each other.

  1. Create hypotheses appropriate for the following research question: is there an evident di???erence in the average scores of students in the reading and writing exam?

\(H_O\): \(\mu_r - \mu_w = 0\), There is no difference betweten reading and writing scores.

\(H_A\): \(\mu_r - \mu_w \neq 0\), There is a difference in average reading and writing scores.

  1. Check the conditions required to complete this test.

Because the Students are independent of each other, it looks like normal distribution, the sample size less than 10% of population and the sample size bigger than 30. So the normality condistion is satisfied.

  1. The average observed di???erence in scores is ¯xread!write = !0.545, and the standard deviation of the di???erences is 8.887 points. Do these data provide convincing evidence of a di???erence between the average scores on the two exams?
n <- 200
xbar <- -0.545
sd <- 8.887
t <- xbar/(sd/sqrt(n))
round(pt(t, n-1), 3)
## [1] 0.193

because 0.193 is greater than 0.05. So we can not reject the null hypothesis. There is no difference between reading and writing scores.

  1. What type of error might we have made? Explain what the error means in the context of the application.

Type II error might be made. Because the difference might be fail to dectect by false negetive error.

  1. Based on the results of this hypothesis test, would you expect a confidence interval for the average di???erence between the reading and writing scores to include 0? Explain your reasoning.

I would expect 0 to be in the confidence interval, because I did not find no statisically significent evedience of diffrence in means.

5.32 Fuel e!ciency of manual and automatic cars, Part I. Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. Below are summary statistics on fuel e“ciency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2012. Do these data provide strong evidence of a di???erence between the average fuel e”ciency of cars with manual and automatic transmissions in terms of their average city mileage? Assume that conditions for inference are satisfied.42

H_O : The data shows no difference between the average city mileage of cars with manual and automatic transmissions H_A : The data shows differences between the average city mileage of cars with manual and automatic transmissions

n = 26
mean_auto = 16.12
mean_manual = 19.85
SD_auto = 3.58
SD_manual = 4.51
diff_Means = mean_auto - mean_manual
sE = sqrt((SD_auto^2/n)+(SD_manual^2/n))
t = (diff_Means)/(sE)
p = pt(t,df=25)*2
p
## [1] 0.002883615

p valuae is 0.00288 which is much smaller than 0.05. So we reject the null hyposthesis. We conclude that there is difference of fuel efficiancy between the cars equipment with manual transmission compared to the cars equiped with automatic transmission.

5.48 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.

H_0: There is no difference in mean hours among all the groups H_A: There is difference in mean hours among all the groups

  1. Check conditions and describe any assumptions you must make to proceed with the test.

condition: each study subjects are independant. the samples looks like normal distribution. more than 30 subjects in the study. Choose less than 10% of subjects from main population.

  1. Below is part of the output associated with this test. Fill in the empty cells.
msq = 501.54
prf = 0.0682
n = 1172
groups = 5
space_between = 4
dF = n - groups
f = qf(1-prf,space_between,dF)
mse= msq/f
ssg = space_between*msq
sse = dF*mse
dF
## [1] 1167
space_between
## [1] 4
f
## [1] 2.188931
mse
## [1] 229.1255
ssg
## [1] 2006.16
sse
## [1] 267389.5
  1. What is the conclusion of the test?

because pr_f = 0.0682 which is bigger than 0.05, so we can not reject the null hypotheis. There is no difference for mean hours among all the groups.