Problem 1a:
weights <- c(456.1, 454.9, 463.4, 454.4, 439.9, 439.4, 433.6, 454.4, 441.2, 451.7,
451.1, 454.1, 449.7, 450.1, 449.6, 449.8, 448.2, 451.5, 447.9, 449.2,
455.1, 454.5, 459.2, 453.7, 456.5)
n <- length(weights)
x_bar <- mean(weights)
s <- sd(weights)
df <- n - 1
t_critical <- qt(0.95, df)
margin_of_error <- t_critical * (s / sqrt(n))
lower_bound <- x_bar - margin_of_error
upper_bound <- x_bar + margin_of_error
confidence_interval <- c(lower_bound, upper_bound)
confidence_interval
## [1] 448.5111 453.0249
Interpretation: I am 90% confident that the mean population weight is between the lower bound (448.51) and upper bound (453.02) that were calculated above.
Problem 1b:
weights <- c(456.1, 454.9, 463.4, 454.4, 439.9, 439.4, 433.6, 454.4, 441.2, 451.7,
451.1, 454.1, 449.7, 450.1, 449.6, 449.8, 448.2, 451.5, 447.9, 449.2,
455.1, 454.5, 459.2, 453.7, 456.5)
n <- length(weights)
sample_mean <- mean(weights)
population_mean <- 454
alpha <- 0.05
t_test_result <- t.test(weights, mu = population_mean)
print(t_test_result)
##
## One Sample t-test
##
## data: weights
## t = -2.45, df = 24, p-value = 0.02196
## alternative hypothesis: true mean is not equal to 454
## 95 percent confidence interval:
## 448.0454 453.4906
## sample estimates:
## mean of x
## 450.768
if (t_test_result$p.value < alpha) {
cat("Reject null hypothesis.")
} else {
cat("Correct null hypothesis.")
}
## Reject null hypothesis.
It is rejected because the value is less than the 0.05 (95% confidence) significance value.The means the Peanuts are not being packaged correctly.
Prob 2a:
total_students <- 568
students_chose_7 <- 42
confidence_level <- 0.99
p <- students_chose_7 / total_students
se <- sqrt(p * (1 - p) / total_students)
z_score <- qnorm(1 - (1 - confidence_level) / 2)
margin_of_error <- z_score * se
lower_bound <- p - margin_of_error
upper_bound <- p + margin_of_error
c(lower_bound, upper_bound)
## [1] 0.04566153 0.10222579
The 99% confidence interval for the PROPORTION of students who chose the number 7 is between 0.0457 and 0.1022: The lower and upper bounds.
Problem 2b:
n <- 568
x <- 42
p_null <- 1/20
p_hat <- x / n
se <- sqrt(p_null * (1 - p_null) / n)
z <- (p_hat - p_null) / se
p_value <- 1 - pnorm(z)
alpha <- 0.01
if (p_value < alpha) {
print("Reject the null hypothesis. There is statistical evidence of bias in favor of the lucky number 7.")
} else {
print("Fail to reject the null hypothesis. There is no statistical evidence of bias in favor of the lucky number 7.")
}
## [1] "Reject the null hypothesis. There is statistical evidence of bias in favor of the lucky number 7."
print(paste("Z-score:", z))
## [1] "Z-score: 2.61829113743216"
print(paste("P-value:", p_value))
## [1] "P-value: 0.00441856860130307"
Because the probability is less than the significance value given in the problem, there is statistical evidence that there was bias in favor of the number 7.
Problem 3:
data("faithful")
summary(faithful$eruptions)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.600 2.163 4.000 3.488 4.454 5.100
t_test <- t.test(faithful$eruptions, mu = 5, alternative = "less")
print(t_test)
##
## One Sample t-test
##
## data: faithful$eruptions
## t = -21.851, df = 271, p-value < 2.2e-16
## alternative hypothesis: true mean is less than 5
## 95 percent confidence interval:
## -Inf 3.602007
## sample estimates:
## mean of x
## 3.487783
Due to the values of the median, mean, and third quartile, I think that it is a significant amount of time shorter than 5 minutes, and therefore, it is reasonable to give 2 stars on the review. It went as low as 1.6 minutes, averaged 3.488 minutes, and it only maxed out at 5.1 minutes. It was significantly lower than 5 minutes the majority of the time it seems.