#111078517 helps me a lot.(Assistance )
Question 1) a. Imagine that Verizon claims that they take 7.6 minutes to repair phone services for its customers on average. The PUC seeks to verify this claim at 99% confidence (i.e., significance α = 1%) using traditional statistical methods.
i.Visualize the distribution of Verizon’s repair times, marking the mean with a vertical line
data=read.csv("verizon.csv", header=TRUE)
plot(density(data$Time),col="purple",lwd=3,main=" Distribution of Verizon’s repair time") +
abline(v=mean(data$Time),col="red",lwd=2)
## integer(0)
ii.Given what the PUC wishes to test, how would you write the hypothesis? (not graded) Null hypothesis: The average repair time for Verizon’s phone services in New York is equal to 7.6 minutes
iii.Estimate the population mean, and the 99% confidence interval (CI) of this estimate.
data=read.csv("verizon.csv", header=TRUE)
mean_data <- mean(data$Time)
se_data <- sd(data$Time) / sqrt(length(data$Time))
upbound <-mean_data + 2.58 * se_data
lowbound<-mean_data - 2.58 * se_data
cat("平均值:", mean_data, "\n")
## 平均值: 8.522009
cat("99%置信区间:", lowbound , "~", upbound, "\n")
## 99%置信区间: 7.593073 ~ 9.450946
iv.Find the t-statistic and p-value of the test
mean_data <- mean(data$Time)
se_data <- sd(data$Time) / sqrt(length(data$Time))
hypothesized_mean = 7.6
t_stat <- (mean_data - hypothesized_mean) / se_data
p_value <- 2 * pt(-abs(t_stat), df = length(data$Time) - 1)
cat("T-statistic:", round(t_stat, 3), "\n","p-value:",p_value)
## T-statistic: 2.561
## p-value: 0.01053068
v.Briefly describe how these values relate to the Null distribution of t (not graded) If the p-value is greater than 0.01, it means that the observed t-value is likely to occur by chance alone. This suggests that there is not enough evidence to reject the null hypothesis.
vi.What is your conclusion about the company’s claim from this t-statistic, and why? Based on the calculated t-statistic of 2.561 and a two-tailed hypothesis test with a sample size of 1687, we cannot reject the null hypothesis that the population mean repair time for Verizon’s phone services is 7.6 minutes at the 1% level of significance since the p-value is slightly larger than the significance level.
b.Let’s re-examine Verizon’s claim that they take no more than 7.6 minutes on average, but this time using bootstrapped testing:
i.Bootstrapped Percentile: Estimate the bootstrapped 99% CI of the population mean
boot_mean <- function(sample0) {
resample <- sample(sample0, length(sample0), replace=TRUE)
return( mean(resample) )
}
set.seed(410731)
num_boots <- 3000
mean_boots <- replicate(
num_boots,
boot_mean(data$Time)
)
ci_99 <- quantile(mean_boots, probs=c(0.005, 0.995));ci_99
## 0.5% 99.5%
## 7.622106 9.430059
ii.Bootstrapped Difference of Means: What is the 99% CI of the bootstrapped difference between the sample mean and the hypothesized mean?
boot_mean_diffs <- function(sample0,mean_hyp) {
resample <- sample(sample0, length(sample0), replace=TRUE)
return( mean(resample) - mean_hyp )
}
set.seed(410731)
num_boots <- 3000
mean_diffs <- replicate(
num_boots,
boot_mean_diffs(data$Time,hypothesized_mean)
)
diff_ci_99 <- quantile(mean_diffs, probs=c(0.005, 0.995));diff_ci_99
## 0.5% 99.5%
## 0.02210593 1.83005854
iii.Plot distribution the two bootstraps above on two separate plots.
par( mfrow= c(2,2) )
plot(density(mean_boots),col="gray",main="Bootstrapped Percentile")+
abline(v=ci_99, lty="dashed")
## integer(0)
plot(density(mean_diffs),col="gray",main="Bootstrapped Difference of Means")+
abline(v=diff_ci_99, lty="dashed")
## integer(0)
iv.Does the bootstrapped approach agree with the traditional t-test in part [a]? The 99% CI of the difference does not contain zero: we can reject the Verizon’s claim.
i.Bootstrapped Percentile: Estimate the bootstrapped 99% CI of the population median
boot_median <- function(sample0) {
resample <- sample(sample0, length(sample0), replace=TRUE)
return( median(resample) )
}
set.seed(410731)
num_boots <- 3000
median_boots <- replicate(
num_boots,
boot_median(data$Time)
)
med_ci_99 <- quantile(median_boots, probs=c(0.005, 0.995));med_ci_99
## 0.5% 99.5%
## 3.2198 3.9300
ii.Bootstrapped Difference of Medians: What is the 99% CI of the bootstrapped difference between the sample median and the hypothesized median?
hyp_med <- 3.5
boot_median_diffs <- function(sample0,median_hyp) {
resample <- sample(sample0, length(sample0), replace=TRUE)
return( median(resample) - median_hyp)
}
set.seed(410731)
num_boots <- 3000
median_diffs <- replicate(
num_boots,
boot_median_diffs(data$Time,hyp_med)
)
meddiff_ci_99 <- quantile(median_diffs, probs=c(0.005, 0.995));meddiff_ci_99
## 0.5% 99.5%
## -0.2802 0.4300
iii.Plot distribution the two bootstraps above on two separate plots.
par( mfrow= c(1,2) )
plot(density(median_boots),col="purple",main="Bootstrapped Percentile")+
abline(v=med_ci_99, lty="dashed")
## integer(0)
plot(density(median_diffs),col="blue",main="Bootstrapped Difference of Medians")+
abline(v=meddiff_ci_99, lty="dashed")
## integer(0)
iv.What is your conclusion about Verizon’s claim about the median, and why? The 99% CI of the median difference do contain zero: we cannot reject the Verizon’s claim.
Question 2) Load the compstatslib package and run interactive_t_test(). You will see a simulation of null and alternative distributions of the t-statistic, along with significance and power. If you do not see interactive controls (slider bars), press the gears icon (⚙) on the top-left of the visualization.
Scenario a) You discover that your colleague wanted to target the general population of Taiwanese users of the product. However, he only collected data from a pool of young consumers, and missed many older customers who you suspect might use the product much less every day.
i.This could introduce a systematic error in the hypothesis test. The sample that my colleague collected may not be representative of the entire population of Taiwanese users of the product, which could bias the results of the test.
ii.”older customers who may use the product much less every day”, this would primarily affect the sample size (n) and potentially the standard deviation (sd) of the sample.
iii.This would likely decrease the statistical power of the hypothesis test, making it more difficult to reject the null hypothesis
iv.A low statistical power indicates that there is a higher likelihood of committing a type II error, which occurs when the null hypothesis is not rejected even though it is false. This is because the sample size is too small and not representative of the entire population, which reduces the ability of the hypothesis test to detect a significant difference between the means of the two groups.
Scenario b)
i.This would likely create a systematic error in the study. Systematic errors are errors that are consistent and repeatable, meaning that they are introduced consistently across all parts of the study.
ii.Removing 20 respondents reporting data from the wrong wearable device would affect the sample size (n) of the study, potentially reducing statistical power. The difference we wish to test (diff), the standard deviation of our sample data (sd), and the significance level of our test (alpha) would not be affected assuming the remaining sample is representative of the population of interest.
iii.This would typically reduce the statistical power of the hypothesis test. Therefore, in general, removing these individuals would likely decrease our power to reject the null hypothesis.
iv.Removing 20 respondents from the data would decrease the sample size (n), which would increase the risk of Type II errors. Type II errors occur when we fail to reject the null hypothesis even when it is false (i.e., we fail to detect a true effect).
Scenario c)
i.This scenario would not create any error. It is a decision made by the professor to change the confidence level from 95% to 90%. However, it is important to note that changing the confidence level affects the level of certainty in our decision-making
ii.The significance level (alpha) would be affected. Instead of using a significance level of 0.05 (95% confidence), we would use a significance level of 0.1 (90% confidence).
iii.It would increase our power to reject the null hypothesis. With a lower significance level, it is easier to reject the null hypothesis because we require less evidence to do so.
iv.With a lower significance level, Type II error becomes more likely. This is because we are less likely to reject the null hypothesis, even if it is false.
Scenario d)
i.This scenario would create a systematic error because the sampling procedure is biased towards weekdays, which underreports usage for younger people who are very active on weekends, and overreports usage of older users.
ii.The sample size (n) and the standard deviation (sd) would be affected because the sample is biased and may not accurately reflect the true population standard deviation and sample size.
iii.It depends on the direction of the bias. If the bias causes the sample mean to be higher than the true population mean, it would increase the power to reject the null hypothesis. If the bias causes the sample mean to be lower than the true population mean, it would decrease the power to reject the null hypothesis.
iv.This scenario could potentially increase the likelihood of Type II error because the biased sample may not be representative of the true population, leading to incorrect conclusions about the hypothesis test.