In: Statistics and Probability
Please use R program and explain clealry please. thank you.
1. In NZ supermarkets, the average weight of a banana is 120 grams. An agricultural scientist buys bananas from a supermarket. Their weight, in grams, is as follows: c(103.2, 95.2, 89.6, 98.5, 112.8, 111) She suspects that this sample of bananas is lighter than average and wonders if this supermarket is selling bananas that are lighter than the NZ average.
(a) State a sensible null hypothesis
(b) State the precise definition of p-value and explain what “more extreme” means in this context
(c) Perform a student t-test using R and interpret
(c) Perform a Z test and account for any differences you find
Attached is the R code marked in BOLD
# Test of Hypothesis
# Ho : mu=120 vs H1 : mu < 120
# x_bar = sample mean, s= sample standard deviation
# n = sample size
mu <- 120
x <- c(103.2, 95.2, 89.6, 98.5, 112.8, 111)
n <- length(x)
x_bar <- mean(x)
s <- sd(x)
# t=(x_bar-mu)/(s/sqrt(n)) ~ tn-1 under Ho
t <- (x_bar-mu)/(s/sqrt(n))
df <- n-1 # degree of freedom
# p_value of the tes
p_value <- pt(t, df, lower.tail = TRUE)
# alpha = level of significance 0.05
alpha <- 0.05
print(p_value)
if(p_value < alpha){
print("Reject Null Hypotheis")
} else {
print("Do not Reject Null Hypotheis")
}
Ans
p_value = 0.002160016
"Reject Null Hypotheis"
___________________________________________________________________________________________
Z- test code in R marked in BOLD
# z=(x_bar-mu)/(s/sqrt(n)) ~ N(0,1)under Ho
z <- (x_bar-mu)/(s/sqrt(n))
# p_value of the tes
p_value <- pnorm(z, mean = 0, sd = 1, lower.tail =
TRUE)
# alpha = level of significance 0.05
alpha <- 0.05
print(p_value)
if(p_value < alpha){
print("Reject Null Hypotheis")
} else {
print("Do not Reject Null Hypotheis")
}
Ans
p_value = 3.895139e-07
"Reject Null Hypotheis"
The result is the same however the p-value is further reduced and more extreme