HAZAL GUNDUZ
Chapter 7 - Inference for Numerical Data
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.
Sample mean:
a<- c(65,77)
sample_mean <- mean(a)
sample_mean
## [1] 71
Margin of error:
me <- (77 - 65) / 2
me
## [1] 6
Standard Deviation:
n <- 25
df <- n - 1
p <- 0.9
p_2tails <- p + (1 - p)/2
t_val <- qt(p_2tails, df)
se <- me / t_val # me = t * se
SD <- round((se * sqrt(n)),2) # se = sd/sqrt(n)
SD
## [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.
SD <- 250
z <- 1.65
Q2margin <- 25
Q2a <- ((z*SD)/Q2margin)^2
Q2a
## [1] 272.25
SD <- 250
zb <- 2.58
Q2margin <- 25
=> Higher confidence interval will require more sample size to get closer to the true parameter.
Q2c <- ((zb*SD)/Q2margin)^2
Q2c
## [1] 665.64
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.
=> The mean of the writing score is slightly higher than reading score, but overall there isn’t a clear difference.
=> The reading and writing scores are usually around the same, so they are likely not independent of each other.
=> H0: Difference between average reading and writing scores is zero.
HA: Difference between average reading and writing scores is not zero.
=> Independence: If the student’s scores aren’t independent each other, this condition may be threatened. Normal distribution: The histogram seems close approximation of a normal distribution.
samp<- 200
q3diff<- -.545
df <- samp-1
q3SD <- 8.887
SE <- q3SD/(sqrt(samp))
t<- ((q3diff-0)/SE)*-1
SE
## [1] 0.6284058
t
## [1] 0.867274
=> ‘t’ value is small, we will fail to reject the null hypothesis as there is not any convincing evidence of difference between the average scores.
=> Since we didn’t reject the null, we may run into two error. Meaning there is difference between the scores.
=> There is no difference in the reading and writing scores, I would expect that the confidence interval would include 0.
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.
Hwy MPG
Automatic Manual
Mean 22.92 27.88
SD 5.29 5.01
n 26 26
n <- 26
x1 <- 22.92
x2 <- 27.88
s1 <- 5.29
s2 <- 5.01
df <- 49
t_crit <- 2.4049 # For the 0.02 level of significance.
SE <- sqrt((s1^2/n)+(s2^2/n))
high <- x1-x2+t_crit*SE
low <- x1-x2-t_crit*SE
interval <- c(low,high)
interval
## [1] -8.396315 -1.523685
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%?
s <- 2.2
ci <- 0.5
alpha <- 0.05
beta <- 0.2
z_alpha <- qnorm(alpha/2)
z_beta <- qnorm(beta)
n <- 2 * ((z_alpha+z_beta)^2*s^2/0.5^2)
ceiling(n) # Number of new enrollees.
## [1] 304
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.
Educational attainment
Less than HS HS Jr Coll Bachelor’s Graduate Total
Mean 38.67 39.6 41.39 42.55 40.85 40.45
SD 15.81 14.97 18.1 13.62 15.51 15.17
n 121 546 97 253 155 1,172
=> H0: The difference between all averages is zero.
HA: One or more averages are different from the others.
=> We should assume a normal distribution, independence of observations, and close to equal variability across the groups.
n<- 1172
r<- 5
meanSqd <- 501.54
p<- 0.0682
(dfd <- r-1)
## [1] 4
(dfr <- n-r)
## [1] 1167
(dft <- dfd + dfr)
## [1] 1171
(sumSqd <- dfd * meanSqd)
## [1] 2006.16
(sumSqR <- 267382)
## [1] 267382
(sumSQt <- sumSqd+sumSqR)
## [1] 269388.2
meanSqd
## [1] 501.54
(meanSqr <- sumSqR/dfr)
## [1] 229.1191
=> The conclusion of this test is the average hours worked is different for at least one group.
Rpubs => https://rpubs.com/gunduzhazal/845245