Graded Questions: 5.6, 5.14, 5.20, 5.32, 5.48

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.

smean= (77+65)/2

paste('The Sample mean is:', round(smean, 4))
## [1] "The Sample mean is: 71"

We know that the margin of error ME is \(\frac{x2???x1}{2}\), and we have that confidence interval CI is (x1,x2)

n <- 25
x1 <- 65
x2 <- 77

ME <- (x2 - x1) / 2

paste('The margin of error (ME) is:', round(ME, 4))
## [1] "The margin of error (ME) is: 6"

For sample standard deviation, \(ME = t??????SE\), We will usthe qt() function, df = 25 - 1.

df <- 25 - 1
p <- 0.9
p2tails <- p + (1 - p)/2

tval <- qt(p2tails, df)

# Since ME = t * SE
SE <- ME / tval

# Since SE = sd/sqrt(n)
sd <- SE * sqrt(n)

paste('The standard deviation is:', round(sd, 4))
## [1] "The standard deviation is: 17.5348"

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?

Answer:

we have that \(ME = z???SE\) and \(SE = \frac{sd}{\sqrt(n)} => ME = Z.\frac{sd}{\sqrt(n)} => n = (\frac{z.sd}{ME})^2\)

z <- 1.65 # 90% CI
ME <- 25
sd <- 250

n <- ((z * sd) / ME ) ^ 2
paste('Raina should use a sample of size ', n)
## [1] "Raina should use a sample of size  272.25"

From the above, the original calculation yielded 272.25 so it ia approximated to 273 students

  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:

Luke should use a larger sample as it will require a higher z number multiplied by the standard deviation and then squared.

  1. Calculate the minimum required sample size for Luke.
z <- 2.575 # 99% CI
ME <- 25
sd <- 250

n <- ((z * sd) / ME ) ^ 2
n
## [1] 663.0625

Luke’s sample size should be 664 students

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.

knitr::include_graphics('https://raw.githubusercontent.com/henryvalentine/MSDS2019/master/Classes/DATA%20606/Home%20works/data606_h5_20.png')

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

Answer: #### There seems to be a slight difference between the means, while the distribution of differences appear to be quite normal

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

Answer:

I will say No, because the scores of either reading or writing are independant, but one student can have scores for both sides in the sample.

  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?

Answer

H_0: The difference of average in between reading and writing equal zero. That is: ??r?????w=0

H_A: The difference of average in between reading and writing does NOT equal zero. That is: ??r?????w???0

  1. Check the conditions required to complete this test.

Answer:

a) Independence of observations: The difference histogram suggested the data are paired, which implies that they would not be independent.

b) The observations are from nearly normal distribution: The provided box plot has no outliers and thereby imply resonably normal distribution

  1. The average observed difference in scores is ¯xread???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?

Answer:

H0: ??diff=0 => There is no difference between the average scores

HA: ??diff???0 => There exists a difference between the average scores

sd_Diff <- 8.887
mean_Dif <- -0.545
n <- 200

SE_Diff <- sd_Diff / sqrt(n)

# to calculate T statistic
t_value <- (mean_Dif - 0) / SE_Diff

df <- n - 1

p <- pt(t_value, df = df)

paste('p-value is: ', p)
## [1] "p-value is:  0.193418237099674"

The NULL hypothesis stands because the p-value is not less that 0.05, which indicates that no convincing evidence of a difference in student’s reading and writing exam scores exists.

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

Answer:

Type I error: Incorrectly reject the null hypothesis.

Type II error: Incorrectly reject the alternative hypothesis.

Our conclusion that no difference exists between the average student reading and writing exam scores might have been a wrong one. We might have wrongly rejected the alternative hypothesis, HA.

  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.

Answer:

Being that it has been determined that there is no clear evidence of a difference in average means, I would expect the confidence interval to include 0.

5.32 Fuel efficiency 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 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 di???erence 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.

knitr::include_graphics('https://raw.githubusercontent.com/henryvalentine/MSDS2019/master/Classes/DATA%20606/Home%20works/data606_h5_img2.png')

Answer:

H0: ??diff=0 => The difference of average miles is equal to zero.

HA: ??diff???0 The difference of average miles is NOT equal to zero.

n <- 26

# for Manual vehicles
mean_m <- 19.85
sd_m <- 4.51

# for Automatic vehicles
mean_a <- 16.12
sd_a <- 3.58

# difference in sample means
mean_Diff <- mean_m - mean_m

# standard error of this point estimate
SE_Diff <- ( (sd_a ^ 2 / n) + ( sd_m ^ 2 / n) ) ^ 0.5

t_val <- (mean_Diff - 0) / SE_Diff
df <- n - 1
p <- pt(t_val, df = df)
paste('p-value is: ', p)
## [1] "p-value is:  0.5"

The p-value is less than 0.05, which means we can conclude that there is strong evidence of a difference in fuel efficiency between these type of vehicles. Therefore, we reject the null hypothesis H0.

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.

knitr::include_graphics('https://raw.githubusercontent.com/henryvalentine/MSDS2019/master/Classes/DATA%20606/Home%20works/data606_h5_img3.png')

  1. Write hypotheses for evaluating whether the average number of hours worked varies across the five groups.

Answer:

H0: \(\mul=\muh=\muj=\mub=\mug\) => The difference of ALL averages is equal

HA: The avg hours across some or all groups does vary

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

Answer:

The data in each group appears relatively normal and the variability is similar across each group. Assumption for ANOVA, that observations are independent.

The data within each group are nearly normal: The box plots do not support nearly normal data within each group. Each group has outliers some groups seem to follow a normal distribution.

The variability across the groups is about equal: There seems to be a similarity of variability in between some of the groups just by observing the standard deviations.

  1. Below is part of the output associated with this test. Fill in the empty cells.
knitr::include_graphics('https://raw.githubusercontent.com/henryvalentine/MSDS2019/master/Classes/DATA%20606/Home%20works/data606_h5_img4.png')

mu <- c(38.67, 39.6, 41.39, 42.55, 40.85)
sd <- c(15.81, 14.97, 18.1, 13.62, 15.51)
n <- c(121, 546, 97, 253, 155)
df <- data.frame (mu, sd, n)
n <- sum(df$n)
k <- length(df$mu)

#degrees of freedom
df <- k - 1
dfResidual <- n - k

# let's use the qf function on the Pr(>F) to get the F-statistic:

Prf <- 0.0682
F_statistic <- qf( 1 - Prf, df , dfResidual)


MSG <- 501.54
MSE <- MSG / F_statistic


SSG <- df * MSG
SSE <- 267382


SST <- SSG + SSE
dft <- df + dfResidual
  1. What is the conclusion of the test?

Answer:

The null hypothesis will not be rejected since that the p-value = 0.0682, is greater than 0.05, we can say that there is not a significant difference between the groups