##
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics
## This package is designed to support this course. The text book used
## is OpenIntro Statistics, 3rd Edition. You can read this by typing
## vignette('os3') or visit www.OpenIntro.org.
##
## The getLabs() function will return a list of the labs available.
##
## The demo(package='DATA606') will list the demos that are available.
Grade: 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.
#### sample mean calculation ####
n <- 25 # sample size
ll <- 65 # lower limit
ul <- 77 # upper limit
m <- (ul + ll) / 2
m## [1] 71
#### margin of error calculation ####
me <- (ul - ll) / 2
me## [1] 6
#### standard deviation calculation ####
df <- (n - 1) # degrees of freedom
t <- abs(qt(.1/2, n)) # critical t value (two-sided)
se <- me / t # standard error
sd <- se * sqrt(n)
sd## [1] 17.56296
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.
z <- 1.65 # z-score for a 90% CI
me <- 25
sd <- 250
n <- (z*(sd/me))^2 #calculate
ceiling(n)## [1] 273
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.
Luke would need a larger sample size to use a higher CI than Raina and keep the same margin of error.
Calculate the minimum required sample size for Luke.
z <- 2.58 #z-score for a 99% CI
n <- (z*(sd/me))^2 #calculate
ceiling(n)## [1] 666
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 differences in scores are shown below.
Is there a clear difference in the average reading and writing scores?
There is not a clear difference in the average reading and writing scores. The boxplots appear similiar and the histogram of scores seem to be centered around 0.
Are the reading and writing scores of each student independent of each other?
Yes, the reading and writing scores of each student should be independent of one another.
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?
Check the conditions required to complete this test.
The average observed difference in scores is -.545 and the standard deviation of the difference is 8.887 points. Do these data provide convincing evidence of a difference between the average scores on the two exams?
No, the data does not provide convincing evidence between different average scores on the two exams. The null hypothesis is not rejected, because the p value is greater than .05.
n <- 200
m <- -.545
df <- n-1
sd <- 8.887
se <- sd/sqrt(n)
t <- (m-0)/se
p <- pt(t, df)
p## [1] 0.1934182
What type of error might we have made? Explain what the error means in the context of the application.
We could have made a type 2 error. This error means that we failed to reject the hypothesis when it was false.
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.
Yes, we would expect the CI to include 0 because the null hypothesis assumes that the average mean difference between scores is 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 difference between the average fuel efficiency of cars with manual and automatic transmission in terms of their average city mileage? Assume that conditions of inference are satisfied.
n <- 26
# automatic transmission
a.mean <- 16.12
a.sd <- 3.58
# manual transmission
m.mean <- 19.85
m.sd <- 4.51
diff.mean <- a.mean - m.mean
diff.mean## [1] -3.73
a.se <- a.sd /sqrt(n)
m.se <- m.sd / sqrt(n)
diff.se <- sqrt((a.se^2)+(m.se^2))
diff.se## [1] 1.12927
t <- (diff.mean-0)/diff.se
t## [1] -3.30302
# p test
df <- n-1
p <- pt(t,df)
p## [1] 0.001441807
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.
Write hypotheses for evaluating whether the average number of hours worked varies across the five groups.
Check conditions and describe any assumptions you must make to proceed with the test.
Below is part of the output associated with this test. Fill in the empty cells.
m <- sum(c(38.67, 39.6, 41.39, 42.55, 40.45))
sd <- sum(c(15.81, 14.97, 18.1, 13.62, 15.51))
n <- sum(c(121, 546, 97, 253, 155))
k <- 5
# degree of Df
df <-k-1
df## [1] 4
# residuals
r <- n - k
r## [1] 1167
# f value
f<-0.0682
f<-qf(1-f,df,r)
f## [1] 2.188931
# mean square
msd <- 501.54
msr <- msd/f
msr## [1] 229.1255
# sum square total
ssd<-df*msd
ssd## [1] 2006.16
ssr <- 267382
sst <- ssd+ssr
sst## [1] 269388.2
What is the conclusion of the test?
There is no statistical significance between the two groups. We do not reject the null hypothesis because the f value .0682 is larger than .05.