ANOVA numericals and code
ANOVA numericals and code
o Formula:
o Where:
Xi = mean of group i
o Formula:
o For each observa�on, subtract the group mean and square the result.
o Use an F-table to find the cri�cal F-value based on df_B and df_W at a given
significance level (e.g., 0.05).
Ques 1. A teacher wants to compare the performance of three different teaching methods.
She selects 3 students per method and records their test scores.
Solu�on:
Since the F-sta�s�c is greater than the cri�cal value, we conclude that there is a significant
difference in the mean weight loss among the three diets.
ANOVA through python code
Python Code for One-Way ANOVA using inbuilt func�ons with p-value
import numpy as np
group_A = [5, 7, 9, 6, 8]
# Display results
print(f"F-Sta�s�c: {f_sta�s�c:.4f}")
print(f"P-Value: {p_value:.4f}")
# Interpreta�on
print("Reject the null hypothesis: At least one group mean is significantly different.")
else:
print("Fail to reject the null hypothesis: No significant difference among group means.")
The p-value in ANOVA tells us the probability of observing the given F-sta�s�c (or a more
extreme value) under Ho if the null hypothesis (H₀) is true.
• If p-value ≤ α (e.g., 0.05): Reject H₀ → At least one group mean is significantly different.
• If p-value > α: Fail to reject H₀ → No significant difference among group means.
• The p-value is derived from the F-distribu�on and tells us whether the observed F-value
is large enough to reject H₀.
• A high F-value generally results in a low p-value, indica�ng strong evidence against H₀.
Example:
• F = 4.25, p = 0.012
o Since p < 0.05, we reject H₀, meaning at least one group has a significantly
different mean.
• F = 1.02, p = 0.40
o Since p > 0.05, we fail to reject H₀, meaning there is no strong evidence of a
difference among groups.
Python Code for One-Way ANOVA using inbuilt func�ons with p-value and F-value
import numpy as np
group_A = [5, 7, 9, 6, 8]
alpha = 0.05
print(f"F-Sta�s�c: {F_sta�s�c:.4f}")
print(f"P-Value: {p_value:.4f}")
print("Reject the null hypothesis: At least one group mean is significantly different.")
else:
print("Fail to reject the null hypothesis: No significant difference among group means.")
else: