See https://data606.net/assignments/homework/ for more information. Chapter 5 - Inference for Numerical Data Practice: 5.5, 5.13, 5.19, 5.31, 5.45 Graded: 5.6, 5.14, 5.20, 5.32, 5.48
Refer to “Getting Started with R” in https://data606.net/post/
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 # sample size
x <- (65 + 77) / 2 # sample mean is calculated as (a+b)/2 for confidence interval (a,b)
ME <- (77-65)/2 # margin of error is (b-a)/2 where the confidence interval is (a,b)
ci <- 0.90
t <- qt(ci + (1 - ci)/2, n-1) # sample standard devation we use ME = t(.05)*s/sqrt(n). Using the qt function and df = 25-1
sd <- (ME/t)*sqrt(n)
paste("The Sample Mean: m = ", x, ";
The Margin of Error: ME =", ME, ";
The Stndard Deviation is:", sd)## [1] "The Sample Mean: m = 71 ; \n The Margin of Error: ME = 6 ;\n The Stndard Deviation is: 17.5348145569379"
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.
z90 <- 1.65 # due to 90% Confidence interval
ME <- 25
SD <- 250
n <- ((z90 * SD) / ME)^2 # sample size = (Z(.05)*(standard deviation)/ME)^2
paste(" The sample size :",n)## [1] " The sample size : 272.25"
Without calculating the actual sample size, determine whether his sample should be larger or smaller than Raina’s, and explain your reasoning.
paste("Sample size n = ((z90 * sd) / ME)^2")## [1] "Sample size n = ((z90 * sd) / ME)^2"
paste("Luke's sample size should be much larger because it will need a higher z number multiplied by the standard deviation and then squared.")## [1] "Luke's sample size should be much larger because it will need a higher z number multiplied by the standard deviation and then squared."
z99 <- 2.575 # due to 99% Confidence interval
ME <- 25
sd <- 250
n <- ((z99 * sd) / ME )^2
paste("The minimum Sample size of students for Luke :", n)## [1] "The minimum Sample size of students for Luke : 663.0625"
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.
paste("As the images show, we do not see a clear difference in the average of the reading and writing scores. Although, the means seem slightly different, the distribution of differences is quite normal around the 0 difference, though it seems to be slightly skewed to the right.")## [1] "As the images show, we do not see a clear difference in the average of the reading and writing scores. Although, the means seem slightly different, the distribution of differences is quite normal around the 0 difference, though it seems to be slightly skewed to the right."
paste("YES - The scores of either reading or writing are independent of each other although one student is likely to have scores for both sides in the sample as an outlier")## [1] "YES - The scores of either reading or writing are independent of each other although one student is likely to have scores for both sides in the sample as an outlier"
is there an evident difference in the average scores of students in the reading and writing exam?
paste("HO : ??r?????w=0, No difference between the average reading and writing scores.")## [1] "HO : ??r?????w=0, No difference between the average reading and writing scores."
paste("HA: ??r?????w???0, There is a difference.")## [1] "HA: ??r?????w???0, There is a difference."
paste("here are 200 students in the sample and were randomly collected. The box plots indicate a little enough skew that we can use the t distribution. Conditions are satisfied.")## [1] "here are 200 students in the sample and were randomly collected. The box plots indicate a little enough skew that we can use the t distribution. Conditions are satisfied."
of the differences is 8.887 points. Do these data provide convincing evidence of a di???erence between the average scores on the two exams?
sd_Diff <- 8.887
mu_Dif <- -0.545
n <- 200
SE <- sd_Diff / sqrt(n)
t <- (mu_Dif-0)/SE
df <- n - 1
p <- round(pt(t, df), 3)
paste("ALTENRATE Hypothesis Ha cane be rejected, because not convicing evidence of diff in avg means.")## [1] "ALTENRATE Hypothesis Ha cane be rejected, because not convicing evidence of diff in avg means."
paste("Type I error: Incorrectly reject the null hypothesis.")## [1] "Type I error: Incorrectly reject the null hypothesis."
paste("Type II error: Incorrectly reject the alternative hypothesis.")## [1] "Type II error: Incorrectly reject the alternative hypothesis."
paste("Since we have rejected ALTERNATE Hypothesis HA, if it were actually true, we would have made a type II error. If we took a larger sample, we would decrease our chances of making a type II error.")## [1] "Since we have rejected ALTERNATE Hypothesis HA, if it were actually true, we would have made a type II error. If we took a larger sample, we would decrease our chances of making a type II error."
Explain your reasoning.
paste("We would expect confidence intervals for the average difference between reading and writing scores to include 0, as it has been determined that there is no convincing evidence of a difference in average means.")## [1] "We would expect confidence intervals for the average difference between reading and writing scores to include 0, as it has been determined that there is no convincing evidence of a difference in average means."
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
paste("- Ho: The difference of average miles is equal to zero. That is: (??diff) mu_diff=0
- Ha : The difference of average miles is NOT equal to zero. That is: (??diff) mu_diff???0")## [1] "- Ho: The difference of average miles is equal to zero. That is: (??diff) mu_diff=0\n- Ha : The difference of average miles is NOT equal to zero. That is: (??diff) mu_diff???0"
n <- 26
# Automatic
mu_a <- 16.12
sd_a <- 3.58
# Manual
mu_m <- 19.85
sd_m <- 4.51
# difference in sample means
mu_Diff <- mu_a - mu_m
# standard error of this point estimate
SE_Diff <- ( (sd_a ^ 2 / n) + ( sd_m ^ 2 / n) ) ^ 0.5
t_val <- (mu_Diff - 0) / SE_Diff
df <- n - 1
p <- pt(t_val, df = df)
p## [1] 0.001441807
paste("With ??=.05 and p = 0.003, we can safely reject NULL Hypothesis - H0. There is convincing evidence of a difference in the means of miles per gallon in manual and automatic transmissions.")## [1] "With ??=.05 and p = 0.003, we can safely reject NULL Hypothesis - H0. There is convincing evidence of a difference in the means of miles per gallon in manual and automatic transmissions."
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.
paste("Ho:??<HS=??HS=??JR=??B=??G . The avg hours worked arcross all five groups does not vary a nd difference of averages are equal
Ha: The avg hours across some or all groups does vary since there is one average that is NOT equal to the other ones")## [1] "Ho:??<HS=??HS=??JR=??B=??G . The avg hours worked arcross all five groups does not vary a nd difference of averages are equal\nHa: The avg hours across some or all groups does vary since there is one average that is NOT equal to the other ones"
paste("3 conditions needs to be satisfied for inference
- Independence : Assumption for ANOVA is that observations are independent within and across the groups based on the nature of the provided data.
- Randomization : Variability is similar across each group by observing the standard deviations.
- Normally Distributed : The data in each group appears relatively normal although there are very few outliers as per the boxplots")## [1] "3 conditions needs to be satisfied for inference\n- Independence : Assumption for ANOVA is that observations are independent within and across the groups based on the nature of the provided data.\n- Randomization : Variability is similar across each group by observing the standard deviations.\n- Normally Distributed : The data in each group appears relatively normal although there are very few outliers as per the boxplots"
k = 5
df_G = k-1
n = 1172
df_E = n - k
df_T = df_G + df_E
gmean = 40.45
SSE = round(sum((121-1)*15.81^2, (546-1)*14.97^2, (97-1)*18.1^2,
(253-1)*13.62^2, (155-1)*15.51^2), 0)
SSG = round(sum(121*(38.67-gmean)^2, 546*(39.6-gmean)^2, 97*(41.39-gmean)^2,
253*(42.55-gmean)^2, 155*(40.85-gmean)^2), 0)
SST = round(SSE + SSG, 0)
MSG = round(SSG / (k-1), 2)
MSE = round(SSE / (n-k), 2)
f = round(MSG / MSE, 3)
df=data.frame(c("ANOVA","degree","Residuals","Total"))
df[2]=c("Df",df_G,df_E,df_T)
df[3]=c("Sum Sq",SSG,267382,269378)
df[4]=c("Mean Sq",501.54,MSE,NA)
df[5]=c("F Value",f,NA,NA)
df[6]=c("Pr(>F)",0.0682,NA,NA)
knitr::kable(df)| c..ANOVA….degree….Residuals….Total.. | V2 | V3 | V4 | V5 | V6 |
|---|---|---|---|---|---|
| ANOVA | Df | Sum Sq | Mean Sq | F Value | Pr(>F) |
| degree | 4 | 2004 | 501.54 | 2.187 | 0.0682 |
| Residuals | 1167 | 267382 | 229.11 | NA | NA |
| Total | 1171 | 269378 | NA | NA | NA |
paste("Since the p-value = 0.0682 is greater than 0.05, there is not a significant difference between the groups. There is not enough evidence for us to reject NULL Hypothesis (H0), hence we can conclude there is no difference in average work hours per week among different groups.")## [1] "Since the p-value = 0.0682 is greater than 0.05, there is not a significant difference between the groups. There is not enough evidence for us to reject NULL Hypothesis (H0), hence we can conclude there is no difference in average work hours per week among different groups."