0% found this document useful (0 votes)
8 views8 pages

ANOVA numericals and code

The document outlines the steps to perform a One-Way ANOVA, including stating hypotheses, organizing data, computing sums of squares, degrees of freedom, mean squares, and the F-statistic. It provides examples of comparing teaching methods and diets, demonstrating how to interpret results based on significance levels. Additionally, it includes Python code for conducting ANOVA and interpreting p-values.

Uploaded by

Mahima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

ANOVA numericals and code

The document outlines the steps to perform a One-Way ANOVA, including stating hypotheses, organizing data, computing sums of squares, degrees of freedom, mean squares, and the F-statistic. It provides examples of comparing teaching methods and diets, demonstrating how to interpret results based on significance levels. Additionally, it includes Python code for conducting ANOVA and interpreting p-values.

Uploaded by

Mahima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Steps to Solve One-Way ANOVA

1. State the Hypotheses

o Null Hypothesis (H₀): The means of all groups are equal.

o Alterna�ve Hypothesis (H₁): At least one group has a different mean.

2. Organize the Data

o Create a table with groups (categories) and their respec�ve observa�ons.

o Calculate the mean of each group (𝑋𝑋̄_group).

o Calculate the overall mean (𝑋𝑋̄_overall).

3. Compute the Between-Group Sum of Squares (SSB)

o Formula:

o Where:

 ni= number of samples in group i

 Xi = mean of group i

 Xoverall= overall mean

4. Compute the Within-Group Sum of Squares (SSW)

o Formula:

o For each observa�on, subtract the group mean and square the result.

o Sum up these squared differences for all groups.

5. Find the Degrees of Freedom (df)

o For Between-Groups (df_B): k−1(where k is the number of groups)

o For Within-Groups (df_W): N−k (where N is total observa�ons)

6. Compute Mean Squares (MS)

o Mean Square Between (MSB):


o Mean Square Within (MSW):

7. Compute the F-Sta�s�c


MSB
o Formula: F=MSW

8. Compare with Cri�cal F-Value

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).

o If F > Cri�cal F-Value, reject H0 (significant difference exists).

o If F ≤ Cri�cal F-Value, fail to reject H0(no significant difference).

9. State the Conclusion

o If we reject H0→ At least one group mean is significantly different.

o If we fail to reject H0→ No sufficient evidence to claim a difference.

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.

Method A Method B Method C


4 3 6
5 4 7
3 5 5
At a 5% significance level (α = 0.05), determine whether there is a significant difference in
students’ performance across these teaching methods.

Step 1: Compute Group Means and Overall Mean

Method A Method B Method C Mean Calcula�on


4 3 6
5 4 7
3 5 5
(4+5+3)/3 = 4 (3+4+5)/3 = 4 (6+7+5)/3 = 6 Group Mean (𝑋𝑋̄)
(4+4+6)/3 = 4.67 Overall Mean (𝑋𝑋̄overall)
Step 2: Compute SSB (Between-Group Sum of Squares)

Step 3: Compute SSW (Within-Group Sum of Squares)

Method A Mean (X - 4)² Method B Mean B (X - 4)² Method C Mean C (X - 6)²


A
4 4 (4-4)²=0 3 4 (3-4)²=1 6 6 (6-6)²=0
5 4 (5-4)²=1 4 4 (4-4)²=0 7 6 (7-6)²=1
3 4 (3-4)²=1 5 4 (5-4)²=1 5 6 (5-6)²=1
Total 2 2 2
SSW=2+2+2=6

Step 4: Compute Degrees of Freedom

• Degrees of freedom for SSB: dfB= k−1 = 3−1 = 2

• Degrees of freedom for SSW: dfW= N−k = 9−3 = 6

Step 5: Compute Mean Squares

Step 6: Compute the F-Sta�s�c

Step 7: Compare with Cri�cal F-Value

At α = 0.05, with df1 = 2 and df2 = 6, the F-table value is 5.14.

Since F = 4.005 < 5.14, we fail to reject the null hypothesis.


Ques 2. Suppose a researcher wants to compare the effec�veness of three different diets on
weight loss. Each diet is tested on 3 individuals, and the observed weight loss (in kg) is given
as follows:

Diet A Diet B Diet C


2 3 5
3 4 6
1 5 4
At a 5% significance level (α = 0.05), determine whether there is a significant difference in the
mean weight loss among the three diets.

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

import scipy.stats as stats

# Sample data: Three groups with different observa�ons

group_A = [5, 7, 9, 6, 8]

group_B = [10, 12, 14, 11, 13]

group_C = [15, 17, 19, 16, 18]

# Perform One-Way ANOVA

f_sta�s�c, p_value = stats.f_oneway(group_A, group_B, group_C)

# Display results

print(f"F-Sta�s�c: {f_sta�s�c:.4f}")

print(f"P-Value: {p_value:.4f}")

# Interpreta�on

alpha = 0.05 # Significance level

if p_value < alpha:

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.")

What is the p-value in ANOVA?

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.

How to Interpret the p-value in ANOVA?

• 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.

How is the p-value related to the F-sta�s�c?

• The F-sta�s�c is calculated as the ra�o of between-group variance to within-group


variance.

• 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:

If you run ANOVA and get:

• 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

import scipy.stats as stats

# Step 1: Define sample data for three groups

group_A = [5, 7, 9, 6, 8]

group_B = [10, 12, 14, 11, 13]

group_C = [15, 17, 19, 16, 18]

# Step 2: Compute One-Way ANOVA

F_sta�s�c, p_value = stats.f_oneway(group_A, group_B, group_C)

# Step 3: Compute degrees of freedom

df_between = 3 - 1 # Number of groups - 1


df_within = (len(group_A) + len(group_B) + len(group_C)) - 3 # Total samples - Number of
groups

# Step 4: Get cri�cal F-value from F-table (5% significance level)

alpha = 0.05

cri�cal_F = stats.f.ppf(1 - alpha, df_between, df_within)

# Step 5: Display results

print(f"F-Sta�s�c: {F_sta�s�c:.4f}")

print(f"P-Value: {p_value:.4f}")

print(f"Cri�cal F-Value: {cri�cal_F:.4f}")

# Step 6: Decision Making

if F_sta�s�c > cri�cal_F:

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.")

# Alterna�ve way using p-value

if p_value < alpha:

print("Conclusion using p-value: Reject H₀.")

else:

print("Conclusion using p-value: Fail to reject H₀.")

You might also like