As a product manager, you want to evaluate the user satisfaction for two different seasons of Naruto Shippuden (Season 1 and Season 2).
You collected feedback from 250 viewers who watched Season 1 of Naruto Shippuden, and 120 expressed satisfaction. Similarly, for Season 2, you gathered data from 300 viewers, and 150 of them expressed satisfaction.
Conduct an appropriate test at a 95% confidence interval to determine if there's a higher user satisfaction for Season 2 than for Season 1.
import numpy as np
# Data
n1 = 250
x1 = 120
n2 = 300
x2 = 150
# Calculate sample proportions
p1 = x1 / n1
p2 = x2 / n2
# Calculate pooled sample proportion
pooled_p = (x1 + x2) / (n1 + n2)
# Calculate standard error
se = np.sqrt(pooled_p * (1 - pooled_p) * (1/n1 + 1/n2))
# Calculate Z-test statistic
z_statistic = (p2 - p1) / se
# One-tailed p-value (since the alternative is p2 < p1)
p_value = 1-norm.cdf(z_statistic)
# Print the results
print("Z-statistic:", z_statistic)
print("p-value:", p_value)
# Check if the p-value is less than the significance level
alpha = 0.05
if p_value < alpha:
print("Reject the null hypothesis: There is higher user satisfaction for Season 2.")
else:
print("Fail to reject the null hypothesis: No evidence of higher user satisfaction for Season 2.")
"""
Z-statistic: 0.46717659215115714
p-value: 0.32018676972652416
Fail to reject the null hypothesis: No evidence of higher user satisfaction for Season 2.
"""
successes = np.array([120, 150])
trials = np.array([250, 300])
# Perform two-sample Z-test for proportions
z_statistic, p_value = proportions_ztest(successes, trials, alternative='smaller') # 'smaller' for p2 < p1
# Print the results
print("Z-statistic:", z_statistic)
print("p-value:", p_value)
# Check if the p-value is less than the significance level
alpha = 0.05
if p_value < alpha:
print("Reject the null hypothesis: There is higher user satisfaction for Season 2.")
else:
print("Fail to reject the null hypothesis: No evidence of higher user satisfaction for Season 2.")
"""
Z-statistic: -0.46717659215115714
p-value: 0.3201867697265242
Fail to reject the null hypothesis: No evidence of higher user satisfaction for Season 2.
"""