title: “Chapter 7 - Inference for Numerical Data”

author: “Sufian”

output:

html_document:

df_print: paged

pdf_document:

extra_dependencies:

- geometry

- multicol

- multirow

- xcolor

Rpub link:

http://rpubs.com/ssufian/543890


Working backwards, Part II. (5.24, p. 203) 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.

ans:

# Sample Mean
mu = (65 + 77) / 2
mu
## [1] 71
# Calculate the Margin or Error
ME <- 77-71
ME
## [1] 6
# Calculate the Tcritical value
t <- qt(.05, df=24) # for t-distribution; n-1 is 25-1 = 24
-t
## [1] 1.710882
# Use the tcritical value to calculate the sample standard error (sample std. dev.)
s = ME/-t * sqrt(25)
round(s, 2)
## [1] 17.53

SAT scores. (7.14, p. 261) 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.

  1. Raina wants to use a 90% confidence interval. How large a sample should she collect?

ans:

z <- qnorm(.95, mean = 0, sd = 1)
ME <- 25
s <- 250

n <- ((z*s)/ME)^2

n # the sample size needed
## [1] 270.5543
  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.

anw:

z99 <- qnorm(.99, mean = 0, sd = 1)
z99
## [1] 2.326348
ME <- 25
s <- 250

n <- ((z99*s)/ME)^2

n # the sample size needed
## [1] 541.1894
  1. Calculate the minimum required sample size for Luke.

ans:

The larger sample size needed by Luke is 541 as shown above


High School and Beyond, Part I. (7.20, p. 266) 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.

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

ans:

There is no clear difference in the average reading and writing scores based on the boxplots and histogram of the

distribution of differences alone. The distribution of the differences between read and write looks fairly normal

centered around zero and the boxplots have similar medians and variances.

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

ans:

No, the reading and writing scores are dependent of each other because they were paired observations.

  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?

ans:

H0: No differences in reading and writing scores

Ha: There are differences in reading and writing scores

  1. Check the conditions required to complete this test.

Independence/Randomeness - assume it is for this as the problem stated that the 200 samples were randomly picked

Normality - There we no extreme outliers as there we no data points outside the tukey fences

  1. The average observed difference in scores is \({ \widehat { x } }_{ read-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?
diff <- -0.545
sd_diff <- 8.887
ndiff <- 200

SE_diff <- sd_diff/sqrt(ndiff )

#test statiscic, T-score:

T <- (sd_diff-diff)/SE_diff 
T
## [1] 15.00941
#calculate p-value using the computed T-score

p <- pt(q=t, df= 199, lower.tail=T)

2*p
## [1] 0.08866116

ans:

Since p-value > than 0.05, fail to reject H0, therefore, there’s no statiscal difference between reading & writing

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

ans:

Type II, failing to reject the Null when there’s actual differences

  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.
diff <- -0.545 # avg difference is given

tcrit <- 1.64

upper_limit <- diff + tcrit*SE_diff 

lower_limit <- diff - tcrit*SE_diff 


upper_limit
## [1] 0.4855855
lower_limit
## [1] -1.575586

ans:

I would say yes, Since the confidence interval (based on 95%) included a zero, as shown above


Fuel efficiency of manual and automatic cars, Part II. (7.28, p. 276) The table provides summary statistics on highway fuel economy of cars manufactured in 2012. Use these statistics to calculate a 98% confidence interval for the difference between average highway mileage of manual and automatic cars, and interpret this interval in the context of the data.

auto_mu <- 22.92
auto_s <- 5.29
man_mu <- 27.88
man_s <- 5.01
n <- 26

# paired differences
diff <- man_mu - auto_mu 

# Calculate the Tcritical value
t <- qt(.03, df=25) # for t-distribution; n-1 is 261 = 25
tcrit <- t

# standard error
se <- (man_s-auto_s)/sqrt(n)

upper_limit1 <- diff + tcrit*se
lower_limit1 <- diff - tcrit*se


upper_limit1 
## [1] 5.068183
lower_limit1 
## [1] 4.851817

ans:

upperlimit = 5.07 and lowerlimit = 4.85


Email outreach efforts. (7.34, p. 284) A medical research group is recruiting people to complete short surveys about their medical history. For example, one survey asks for information on a person’s family history in regards to cancer. Another survey asks about what topics were discussed during the person’s last visit to a hospital. So far, as people sign up, they complete an average of just 4 surveys, and the standard deviation of the number of surveys is about 2.2. The research group wants to try a new interface that they think will encourage new enrollees to complete more surveys, where they will randomize each enrollee to either get the new interface or the current interface. How many new enrollees do they need for each interface to detect an effect size of 0.5 surveys per enrollee, if the desired power level is 80%?

ME <- 0.5
z <- qnorm(.80, mean = 0, sd = 1)

s <- 2.2

n <- ((z*s)/ME)^2

n # the sample size needed
## [1] 13.7132

ans:

Needed sample size = 14


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.

ans:

Ho: avg no. of hours worked does not varies across groups

Ha: avg no. of hours worked does varies across groups

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

ans:

observations in each group, so it can be assumed to be independent.

but since this group has 253 observations and there are no extreme outliers a strong skew is not a major concern.

group has a larger difference in its variance as compared with all the other groups.

  1. Below is part of the output associated with this test. Fill in the empty cells.
dof <- 4
res <- 1172 - 4

total <- 1172
MSB <- 501.54 # given in problem
SSBetween <- MSB*(dof-1)

SSerror <- 267382 #given in problem
  
SStotal <- SSBetween + SSerror
  
MSB <- 501.54
  
MSE <- SSerror/res 
  
F <- MSB/MSE

F
## [1] 2.190868
p <- pf(q=F,dof, res, lower.tail = FALSE) 

p
## [1] 0.06798618
  1. What is the conclusion of the test?

ans:

Because P-value > 0.05, failed to reject H0, which means

there were differences in hours worked across various

groups