rm(list = ls()) # Clear environment
gc() # Clear unused memory
## used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 505632 27.1 1122542 60 644240 34.5
## Vcells 892960 6.9 8388608 64 1634574 12.5
cat("\f") # Clear the console
#Question 1
Q1T <- (110 - 109) / (6/sqrt(190))
Q1P <- 2 * (1 - pnorm(abs(Q1T)))
Q1P
## [1] 0.0215993
##ince the p-value is less than the level of significance, we reject the null hypothesis. We can conclude that the mean time to obtain a license using the new method is significantly different from the traditional method.
#Question 2
Q2T <- (5 - 5.3) / (1.1/sqrt(5))
Q2P <- pnorm(Q2T, lower.tail = T)
Q2P
## [1] 0.270985
##Since the p-value is greater than the level of significance, we fail to reject the null hypothesis.
#Question 3
#h0: is the true mean ozone level = 7.3ppm
#Ha: is the true mean ozonle level is not = 7.3ppm
Q3T <- (7.1-7.3)/(sqrt(.49)/sqrt(51))
Q3P <- 2 * pt(abs(Q3T), df = 51 - 1, lower.tail = FALSE)
Q3P
## [1] 0.04660827
##Since the p-value is less than the level of significance (0.0466 > 0.01), we fail to reject the null hypothesis.
#Question 4
#H0 is the percent of people who own a laptop is greater or equal to 36%
#Ha is the percent of people who own a laptop is less than 36%
Q4Z <- (.29-.36)/sqrt(.36*(1-.36)/100)
Q4P <- pnorm(Q4Z)
Q4P
## [1] 0.07237434
##Since the p-value is greater than the level of significance (0.07237434 > 0.02), we fail to reject the null hypothesis.
#Question 5
Q5p_hat <- 95/380
Q5Z <- (Q5p_hat - .31)/sqrt(.31*(1-.31)/380)
Q5P <- pnorm(Q5Z)
Q5P
## [1] 0.005720462
##The p-value is less than the level of significance, so we reject the null hypothesis.
#Question 7
#H0: SD >= Sd0
#Ha: SD < Sd0
#n = 22, S = 15.4387, SD = 24
Q7S <- sqrt(((22-1) * (15.4387)^2) / 21)
Q7T <- (Q7S - 24) / (Q7S / sqrt(22))
Q7F <- 22-1
Q7CT <- qt(.1, 21, lower.tail = T)
Q7P <- pt(Q7T, 21, lower.tail = T)
Q7P
## [1] 0.008339726
##The p-value is less than the level of significance (0.008339726 < 0.1), so we reject the null hypothesis.
#Question 8
#H0: u1 = u2; Ha: u1 <> u2
Q8T <- (87-84-0)/sqrt((9^2/32)+(10^2/31))
alpha = .1
numdf = ((9^2/32) + (10^2/31))^2
dendf = ((9^2/32)^2 / 31 + (10^2/31)^2 / 30)
df = numdf / dendf
critical_value_satterwaite <- qt(p = (1-alpha/2), df = numdf / dendf )
critical_value_satterwaite
## [1] 1.670703
##Since the test statistic is less than the upper critical value, we fail to reject the null hypothesis.
#Question 9
# (Xbar1-Xbar2) + or - t*(sqrt(s1^2/n1 + s2^2/n2))
n1 <- 11
n2 <- 18
Xbar1 <- 127
Xbar2 <- 157
s1 <- 33
s2 <- 27
Q9df = (s1^2/n1 + s2^2/n2)^2 / ((s1^2/n1)^2 / (n1 - 1) + (s2^2/n2)^2 / (n2 - 1))
Q9df
## [1] 18.0759
Q9CT = qt(0.025, Q9df, lower.tail = FALSE)
Q9CT
## [1] 2.10029
Q9LL <- (127 - 157) + Q9CT * sqrt(33^2/11 + 27^2/18)
Q9UL <- (127 - 157) - Q9CT * sqrt(33^2/11 + 27^2/18)
##The lower limit of the confidence interval is -54.81, and the upper limit is -5.19.
#Question 10
route1 <- c(32, 27, 34, 24, 31, 25, 30, 23, 27, 35)
route2 <- c(28, 28, 33, 25, 26, 29, 33, 27, 25, 33)
diffs <- route1 - route2
diff_mean <- mean(diffs)
diff_sd <- sd(diffs)
n <- length(diffs)
Q10SE <- diff_sd / sqrt(n)
Q10CT <- qt(0.01, df = n - 1, lower.tail = FALSE)
Q10CT
## [1] 2.821438
Q10LL <- diff_mean - Q10CT * Q10SE
Q10LL
## [1] -2.766534
Q10UL <- diff_mean + Q10CT * Q10SE
Q10UL
## [1] 2.966534
##Since the p-value is greater than the significance level of 0.05, we fail to reject the null hypothesis.
#Question 11
p1 <- 195/391
p2 <- 193/510
Q11SE <- sqrt(p1*(1-p1)/391 + p2*(1-p2)/510)
Q11Z <- (p1 - p2) / Q11SE
Q11P <- 1- pnorm(Q11Z)
Q11P
## [1] 0.0001439855
##the p-value is less than the significance level (0.05), we reject the null hypothesis