7
# Given values
mean_a = 1000
std_a = 100
n_a = 30
mean_b = 950
std_b = 120
n_b = 30
# Step 1: Compute the difference in means
mean_diff = mean_a - mean_b
# Step 2: Compute the standard error (Welch's formula for
unequal variances)
se = ((std_a ** 2) / n_a + (std_b ** 2) / n_b) ** 0.5
# Step 3: Compute the t-statistic
t_stat = mean_diff / se
# Step 4: Compute degrees of freedom using
Welch–Satterthwaite approximation
df_numerator = ((std_a ** 2) / n_a + (std_b ** 2) / n_b) **
2
df_denominator = (( (std_a ** 2) / n_a ) ** 2) / (n_a - 1) +
(( (std_b ** 2) / n_b ) ** 2) / (n_b -
1)
df = df_numerator / df_denominator
# Print results
print(f"T-statistic: {t_stat:.4f}")
print(f"Approximate Degrees of Freedom: {df:.2f}")
# Interpretation guide (manual comparison needed)
# For example: Critical t-value at df ≈ 55, α=0.05
(two-tailed) ≈ ±2.004
# Decision
if abs(t_stat) > 2.004:
print("Result: Reject H₀ → Significant difference in
sales.")
else:
print("Result: Fail to reject H₀ → No significant
difference in sales.")
Comments
Post a Comment