0% found this document useful (0 votes)
33 views21 pages

Understanding Hypothesis Testing Basics

Hypothesis testing is a key component of inferential statistics used to make conclusions about populations based on sample data, with applications in clinical research, A/B testing, and machine learning. The process involves defining null and alternative hypotheses, selecting appropriate statistical tests like t-tests and z-tests, and calculating test statistics to determine if the null hypothesis can be rejected. The document also provides detailed examples of t-tests and z-tests, including calculations and interpretations of results.

Uploaded by

ayushverma287630
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)
33 views21 pages

Understanding Hypothesis Testing Basics

Hypothesis testing is a key component of inferential statistics used to make conclusions about populations based on sample data, with applications in clinical research, A/B testing, and machine learning. The process involves defining null and alternative hypotheses, selecting appropriate statistical tests like t-tests and z-tests, and calculating test statistics to determine if the null hypothesis can be rejected. The document also provides detailed examples of t-tests and z-tests, including calculations and interpretations of results.

Uploaded by

ayushverma287630
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

BIOSTATISTICS

What is Hypothesis Testing?


Hypothesis testing is an essential part of inferential statistics where we use observed data in a sample to
draw conclusions about unobserved data — often the population.
The implication of hypothesis testing:
clinical research: widely used in psychology, biology, and healthcare research to examine the effectiveness
of clinical trials
A/B testing: can be applied in a business context to improve conversions through testing different
versions of campaign incentives, website designs etc
feature selection in machine learning: filter-based feature selection methods use different statistical tests
to determine the feature importance
college or university: well, if you major in statistics or data science, it is likely to appear in your exams …
4 Steps in Hypothesis testing
Step 1. Define null and alternative hypothesis
Null hypothesis (H0) can be stated differently depending on the statistical tests, but generalized as the
claim that no difference, no relationship, or no dependency exists between two or more variables.
Alternative hypothesis (H1) is contradictory to the null hypothesis and it claims that relationships
exist. It is the hypothesis that we would like to prove right. However, a more conservational approach is
favored in statistics where we always assume null hypothesis is true and try to find evidence to reject the
null hypothesis.
Step 2. Choose the appropriate statistical test
Common types of statistical testing include t-tests, z-tests, anova test, and chi-square test.
1. T-Test: A t-test is used to compare the means of two groups to determine if there is a significant
difference between them. You can use a t-test when your sample size is small (n < 30) and the population
standard deviation is unknown.
There are two types of t-tests:
• A two-sample t-test
• A paired t-test.
A two-sample t-test is used to compare the means of two independent groups, while a paired t-test is used
to compare the means of two related groups, such as before-and-after measurements.
Z-Test: A z-test is used to compare the mean of a single sample to a known population mean. Unlike a t-
test, a z-test assumes that the population standard deviation is known. A z-test is typically used when the
sample size is large (n > 30) or when the population standard deviation is known from previous studies.
ANOVA: ANOVA (analysis of variance) is used to compare the means of more than two groups
to determine if there is a significant difference between them. ANOVA is appropriate when you have
continuous data and multiple groups to compare.
Chi-Square Test: A chi-square test is used to compare the frequency or count of observations in two or
more categories or groups. It is used to test the independence of two categorical variables. For example,
you can use a chi-square test to determine if there is a relationship between gender and political
affiliation. The chi-square test is appropriate when you have categorical data and you want
to determine if there is a relationship between two variables.
In summary, the choice of statistical test depends on the type of data you have, the research question you
want to answer, and the assumptions of each test. It is important to choose the appropriate test to ensure
that the results are meaningful and accurate.

How to Calculate T-test :


T-Distribution Table
A T-Distribution table is used to obtain a critical t-value that is used as a reference to the calculated t-
value for obtaining further results. Critical t-value depends on values of the level of significance and
degrees of freedom. A concise form of the table for critical t-values is as follows for your reference:
Degrees of α= α=
Freedom (df) 0.05 0.01
1 12.706 63.657
2 4.303 9.925
3 3.182 5.841
4 2.776 4.604
5 2.571 4.032
6 2.447 3.707
7 2.365 3.499
8 2.306 3.355
9 2.262 3.250
10 2.228 3.169
11 2.201 3.106
12 2.179 3.055
13 2.160 3.012
14 2.145 2.977
15 2.131 2.947
16 2.120 2.921
17 2.110 2.898
18 2.101 2.878
19 2.093 2.861
20 2.086 2.845

Solved Problems of T-Test Formula


Ques: Determine whether the average weight of a sample of 20 mangoes is significantly different
from the population's average weight of 70 grams. The sample mean weight is 70.55 grams, and
the sample standard deviation is 2.82 grams. Use one sample T-test.
Solution:
To perform a T-test, first of all, we define two hypotheses:
 Null hypothesis: The sample mean weight of mangoes is equal to the known population mean.
(i.e., 70 grams).
 Alternative hypothesis: The sample mean weight of mangoes is not equal to the known mean
value.
Then, determine the degrees of freedom (df): df = n - 1 = 20 - 1 = 19 and define the level of significance(α)
as 0.05 for this case. Next, determine the t-value from the formula,
t = (70.55 - 70) / (2.82 / √20)
⇒ t ≈ 1.041
From the t-distribution table, we find 1.041 < 2.093. (i.e. p-value for α = 0.05). So, the null hypothesis is
true. Thus, we conclude that the sample does not vary significantly from the population.
Ques. A professor wants to know if her introductory statistics class has a good grasp of basic
math. Six students are chosen at random from the class and given a math proficiency test. The
professor wants the class to be able to score above 70 on the test. The six students get scores of
62, 92, 75, 68, 83, and 95. Can the professor have 90 percent confidence that the mean score for
the class on the test would be above 70?
Ans. Null hypothesis: H 0: μ = 70
Alternative hypothesis: H a: μ > 70
First, calculate the mean and standard deviation:
62+92+75+68+83+95 = 475
X̄ = 475/6 = 79.17
s= 13.17

Next, calculate the t-value:


T= 79.17 - 70 / 13.17/√6
T= 9.17/5.38 = 1.71

For testing the hypothesis, the computed t-value of 1.71 needs to be compared with the critical value in
the t-table. If the calculated t-value is larger than the critical t-value from the table, the null hypothesis will
be discarded.

Ques. A Little League baseball coach wants to know if his team is representative of other teams in
scoring runs. Nationally, the average number of runs scored by a Little League team in a game is
5.7. He chooses five games at random in which his team scored 5, 9, 4, 11, and 8 runs. Is it likely
that his team's scores could have come from the national distribution? Assume an alpha level of
0.05.
Ans. Null hypothesis: H 0: μ = 5.7
Alternative hypothesis: H a: μ ≠ 5.7
Now calculate the mean and standard deviation:
5+9+4+11+8= 37
x̄ = 37/5 = 7.4
S= 2.88

The t-value will be:


T = 7.4 – 5.7 / 2.88/ √5
= 1.7/ 1.29
= 1.32

Now, check the critical value from the t-table. The tabled value for t .025,4 is 2.776. The calculated t of
1.32 is smaller, so we cannot reject the null hypothesis that is the mean of this team is equal to the
population mean. The coach cannot deduce that his team is different from the national distribution of runs
scored.

Ques: Determine if there is a significant difference in the average scores between the two teams.
The following data is given:
Team A: Score: 65, 68, 70, 63, 67
Team B: Score: 62, 66, 69, 64, 68
Solution:
According to the question, we come to know that we need to perform an Independent Samples T-test. Set
up the null hypothesis and alternative hypothesis:
 Null hypothesis: The means of the two groups are equal (μA = μB).
 Alternative hypothesis: The means of the two groups are not equal (μA ≠ μB).
Next, we calculate the sample means (x̄A and x̄B) and sample standard deviations (σA and σB):
Team A:
 Sample size (nA) = 5
 Sample mean (x̄A) = (65 + 68 + 70 + 63 + 67) / 5 = 66.6
 Sample standard deviation (σA) ≈ 2.607
Team B:
 Sample size (nB) = 5
 Sample mean (x̄B) = (62 + 66 + 69 + 64 + 68) / 5 = 65.8
 Sample standard deviation (σB) ≈ 2.588
Now, we calculate the t-value using the formula:
t = (x̄A - x̄B) / √((σA2 / nA) + (σB2 / nB))
⇒ t = (66.6 - 65.8) / √{(2.6072/5) + (2.5882/5)}
⇒ t ≈ 0.296
Then, determine the degrees of freedom (df):
df = nA + nB - 2 = 5 + 5 - 2 = 8
and set the level of significance as 0.05.
From the table, we get the critical t-value as 2.306. As the calculated t-value is less than the critical t-
value, we conclude that the null hypothesis is not rejected, which suggests that there is no significant
difference between the average scores of the two teams.
Ques: You need to assess the effectiveness of a new teaching scheme by comparing the test
scores of the same group of students before and after the implementation of the scheme. The
following data is given:
Before scores: 76, 88, 65, 56, 76
After scores: 85, 95, 75, 60, 81
Determine if there is a significant difference in the average test scores before and after the
implementation of the scheme.
Solution:
Here, we need to perform a Paired Samples T-test, as we need to compare data of the same sample. Set
up the null hypothesis and alternative hypothesis:
 Null hypothesis: The population mean difference between the before and after scores are zero
(μd = 0).
 Alternative hypothesis: The population mean difference between the before and after scores is
not zero (μd ≠ 0).
Next, calculate the differences between the paired observations:
Difference (d) = After score - Before score
 d1 = 85 - 76 = 9
 d2 = 95 - 88 = 7
 d3 = 75 - 65 = 10
 d4 = 60 - 56 = 4
 d5 = 81 - 76 = 5
Now, calculate the sample mean (x̄d) and sample standard deviation (σd) of the differences:
 Sample size (n) = 5
 Sample mean (x̄d) = (d1 + d2 + d3 + d4 + d5) / 5 = (9 + 7 + 10 + 4 + 5) / 5 = 7
 Sample standard deviation (σd) ≈ 2.828
Then, calculate the t-value using the formula:
t = (x̄d - μd) / (σd / √n)
⇒ t = (7 - 0) / (2.828 / √5)
⇒ t ≈ 5.535
Next, calculate the value of degrees of freedom (df):
df = n - 1 = 5 - 1 = 4.
And, define the level of significance(α) as 0.05.
Now, from the t-distribution table, we find that the critical t-value is 2.776. As the calculated t-value is
greater than the critical t-value (5.535 > 2.776), thus, the null hypothesis is rejected. And we conclude that
there is a significant difference in the average test scores before and after the implementation of the
scheme.

Z-test : Formula, Types, Examples


A Z-test is a type of hypothesis test that compares the sample’s average to the population’s average and
calculates the Z-score and tells us how much the sample average is different from the population
average by looking at how much the data normally varies. It is particularly useful when the sample size
is large >30. This Z-Score is also known as Z-Statistics formula.
Let's understand with the help of example: The average family annual income in India is 200k with a
standard deviation of 5k and the average family annual income in Delhi is 300k. Then Z-Score for Delhi
will be.
This indicates that the average family's annual income in Delhi is 20 standard deviations above the mean
of the population (India).
For a z-test to provide reliable results these assumptions must be met:
1. Normal Distribution: The population from which the sample is drawn should be
approximately normally distributed.
2. Equal Variance: The samples being compared should have the same variance.
3. Independence: All data points should be independent of one another.
Steps to perform Z-test
1. First we identify the null and alternate hypotheses.
2. Then we determine the level of significance (αα).
3. Next we find the critical value of Z in the z-test.
4. Then we calculate the z-test statistics using the formula :

5. Now we compare with the hypothesis and decide whether to reject or not reject the null hypothesis.
Type of Z-test
There are mainly two types of Z-tests. Let's understand them one by one:
1. One Sample Z test
A one-sample Z-test is used to determine if the mean of a single sample is significantly different from a
known population mean. When to Use:
 The population standard deviation is known.
 The sample size is large (usually n>30).
 The data is approximately normally distributed.
Suppose a company claims that their new smartphone has an average battery life of 12 hours. A
consumer group tests 100 phones and finds an average battery life of 11.8 hours with a known population
standard deviation of 0.5 hours.
Step 1: Hypotheses:
 H0 : μ=12
 H1 : μ≠12
Step2: Calculate the Z-Score:
Where: xˉ=11.8 , μ=12, σ=0.5 and n=100
After putting the value we get:
z=11.8−12 / 0.5/ √100
z=−4
Step3: Decision
Since ∣Z∣=4>1.96 (critical value forα = 0.05) we reject H0 indicate significant evidence against the
company's claim.
2. Two-sampled z-test
In this test we have provided 2 normally distributed and independent populations and we have drawn
samples at random from both populations. Here we consider u1 and u2 to be the population mean
and X1 and X2 to be the observed sample mean. Here our null hypothesis could be like this:
 H0 : μ1−μ2=0 and alternative hypothesis
 H1 : μ1−μ2≠0
and the formula for calculating the z-test score:

Example: There are two groups of students preparing for a competition: Group A and Group B. Group A
has studied offline classes, while Group B has studied online classes. After the examination the score of
each student comes. Now we want to determine whether the online or offline classes are better.
 Group A: Sample size = 50, Sample mean = 75, Sample standard deviation = 10
 Group B: Sample size = 60, Sample mean = 80, Sample standard deviation = 12
Assuming a 5% significance level perform a two-sample z-test to determine if there is a significant
difference between the online and offline classes.
Solution:
Step 1: Null & Alternate Hypothesis
 Null Hypothesis: There is no significant difference between the mean score between the online
and offline classes
μ1−μ2=0
 Alternate Hypothesis: There is a significant difference in the mean scores between the online
and offline classes.
μ1−μ2≠0
Step 2: Significance Level
 Significance Level: 5%
α=0.05
Step 3: Z-Score
= (75−80)−0 / √( 10^2/50 + 12^2/ 60)
= -5 /√ 2+2.4
= -5/ 2.0976
= -2.384
Step 4: Check to Critical Z-Score value in the Z-Table for alpha/2 = 0.025
 Critical Z-Score = 1.96
Step 5: Compare with the absolute Z-Score value
 absolute(Z-Score) > Critical Z-Score
 So we reject the null hypothesis and there is a significant difference between the online and
offline classes.

Solved examples
Problem 1: A company claims that the average battery life of their new smartphone is 12 hours. A
consumer group tests 100 phones and finds the average battery life to be 11.8 hours with a
population standard deviation of 0.5 hours. At a 5% significance level, is there evidence to refute
the company's claim?
Solution:
Step 1: State the hypotheses
H0 : μ=12 (null hypothesis)

H1 : μ≠12 (alternative hypothesis)

Step 2: Calculate the Z-score

tep2: Calculate the Z-Score:


z= 11.8−12 / 0.5/ √100
z=−4
Step 3: Find the critical value (two-tailed test at 5% significance)
Z0.025 =±1.96
Step 4: Compare Z-score with critical value
|-4| > 1.96, so we reject the null hypothesis.
Conclusion: There is sufficient evidence to refute the company's claim about battery life.
Problem 2: A researcher wants to compare the effectiveness of two different medications for
reducing blood pressure. Medication A is tested on 50 patients, resulting in a mean reduction
of 15 mmHg with a standard deviation of 3 mmHg. Medication B is tested on 60 patients, resulting
in a mean reduction of 13 mmHg with a standard deviation of 4 mmHg. At a 1% significance level,
is there a significant difference between the two medications?
Solution:
Step 1: State the hypotheses
H0:μ1−μ2=0(null hypothesis)
H1:μ1−μ2≠0(alternative hypothesis)

Step 2: Calculate the Z-score

=15−13 / 3^2/50 + 4^2/60


=2/ √0.18+0.2667
=2/0.6455
=3.10
Step 3: Find the critical value (two-tailed test at 1% significance)
Z0.005 =±2.576
Step 4: Compare Z-score with critical value
3.10 > 2.576, so we reject the null hypothesis.

Solved Examples on Z-score Formula


Example 1: Basic Z-score calculation
Mean (μ) = 70
Standard deviation (σ) = 5
Data point (x) = 80
Z-score formula: Z = (x - μ) / σ
Solution:
Z = (80 - 70) / 5
Z = 10 / 5
Z=2
This means the data point is 2 standard deviations above the mean.
Example 2: Z-score with negative result
Mean (μ) = 100
Standard deviation (σ) = 15
Data point (x) = 85
Solution:
Z- score formula : Z = (x - μ) / σ
Z = (85 - 100) / 15
Z = -15 / 15
Z = -1
This means the data point is 1 standard deviation below the mean.
Example 3: What percentage of people have a lower IQ than this person having an IQ of 130 ?
Mean IQ (μ) = 100, Standard deviation (σ) = 15, Person's IQ (x) = 130
Calculate Z-score:
Z = (130 - 100) / 15 = 2
Use a standard normal distribution table or calculator to find the area to the left of Z = 2.
Area = 0.9772
Convert to percentage:
97.72% of people have a lower IQ than this person.
Example 4: Finding the corresponding height for a given a Z-score
Mean height (μ) = 170 cm, Standard deviation (σ) = 8 cm, Z-score = -1.5
Use the Z-score formula and solve for x:
-1.5 = (x - 170) / 8
-12 = x - 170
x = 158 cm
The height corresponding to a Z-score of -1.5 is 158 cm.
Example 5: Z-score in a dataset
A dataset of exam scores: 75, 82, 90, 68, 95
Calculate the Z-score for 82.
Step 1: Calculate the mean (μ)
μ = (75 + 82 + 90 + 68 + 95) / 5 = 82
Step 2: Calculate the standard deviation (σ)
σ = √[Σ(x - μ)² / (n-1)]
σ = √[((-7)² + 0² + 8² + (-14)² + 13²) / 4]
σ = √(466 / 4) = √116.5 ≈ 10.79
Step 3: Calculate the Z-score for 82
Z = (82 - 82) / 10.79 = 0
Explanation: The Z-score of 0 indicates that 82 is exactly at the mean of the dataset.

Chi-Square Test for Independence


The Chi-Square Test for Independence is a statistical method used to determine whether there is a
significant association between two categorical variables. It helps assess whether the distribution of one
variable differs depending on the level of another variable. This test is widely applied in various fields,
including market research, social sciences, and healthcare.
Objective of the Chi-Square Test for Independence
The Chi-Square Test for Independence determines if two categorical variables are independent or
associated.
 Null Hypothesis (H0): There is no association between the two variables, implying they are
independent.
 Alternative Hypothesis (H1): There is an association between the two variables, implying they
are dependent.
Mathematical Formula
The Chi-Square statistic is calculated using the formula:

Assumptions of the Chi-Square Test


 Categorical Variables: Both variables should be categorical.
 Independence: The observations should be independent.
 Sufficient Sample Size: The expected frequency in each cell should be at least 5 for the Chi-
Square approximation to be valid.

Steps for Chi-Square Test


Steps and an illustration of an example of how sex influences which type of ice-cream a person will
choose using a chi-square test are added below:
Step 1: Define Hypothesis
 Null Hypothesis (H₀): The observed frequencies match the expected distribution.
 Alternative Hypothesis (H₁): The observed frequencies do not match the expected distribution.
Step 2: Gather and Organize Data
Gather Information about the Two Category Variables:
Before performing a chi-square test, you should have on hand information about two categorical variables
you wish to observe.
 You must collect details on people’s sex (male or female) and their best flavors (e.g., chocolate,
vanilla, strawberry).
 Once this information is collected, it can be inserted into a contingency table.
The hypothesis is that men prefer vanilla while women prefer chocolate. So we need to record how many
have chosen vanilla among all male respondents versus the number who chose chocolate out of all
female respondents.
Here's an example of what a contingency table might look like:
Chocolate Vanilla Strawberry
Male 20 15 10
Female 25 20 30
Step 3: Calculate Expected Frequencies
 Get Observed Frequency: In any specific cell, the expected frequency can be described as the
number of occurrences that would be expected if the two variables were independent.
 Expected Frequency Calculation: This involves multiplying the sums of rows and columns in
proportion, then dividing by the total number of observations in a table.
Observed frequency is the table given above:
Eij=(Row Total)×(Column Total) / Grand Total
 Male and chocolate: 45×45/ 120=16.875
 Male and Vanilla: 45×35/120=13.125

 Male and chocolate: 45×45/120=16.875


 Male and Vanilla: 45×35/120=13.125
Summarizing,
 Male: Chocolate: 16.875, Vanilla: 13.125, Strawberry: 15.0,
 Female: Chocolate:12.125, Vanilla: 21.875, Strawberry: 25.0
Step 4: Perform Chi-Square Test
Use Chi-Square Formula:
χ² = Σ (Oi - Ei)² / Ei
χ2=∑(O−E)^2/E
=(20−16.875)² /16.875 + (15−13.125)²/13.125 + (30−25)²//25
=4.69
Step 5: Determine Degrees of Freedom (df)
df = (number of rows - 1) × (number of columns - 1)
df=(r−1)(c−1)=(2−1)(3−1)=2
Step 6: Find p-value
 Compare χ² to the Chi-Square Distribution Table for the given df.
χ² = 4.69 with df=2: Critical value at α=0.05 is 5.991. Since 4.69 < 5.991, p > 0.05
Step 7: Interpret Results
 If the p-value is less than a certain significance level (e.g., 0.05), then we reject the null
hypothesis, which is commonly denoted by α. Thus, it means that category variables highly correlate
with each other.
 When a p-value is above α, it implies that we cannot reject the null hypothesis; hence, there
is insufficient evidence for establishing the relationship between these variables.
No significant evidence supports the claim that men prefer vanilla or women prefer chocolate (p>0.05).

When to Use Chi-Square Test for Independence?


 When you need to check for associations between two categorical variables.
 When analyzing survey responses or contingency tables.
 Useful in fields like market research, sociology, and healthcare.
Limitations of the Chi-Square Test
1. Sample Size Dependency: The test can be unreliable if expected cell frequencies are too small.
2. Non-Causality: It only identifies associations, not causal relationships.
3. Categorical Limitation: Only applicable to categorical data.

Ques : A study investigates the relationship between eye color (blue, brown, green) and hair color
(blonde, brunette, Redhead). The following data is collected:
Eye Blonde Brunette Redhead Total
Color
Blue 35 52.5 12.5 100
Brown 28.1 42.1 9.8 80
Green 6.9 10.4 2.7 20
Solution:
Calculate the chi-square value for each cell in the contingency table using the formula
χ² = (Oi - Ei)² / Ei
For instance, consider someone with brown hair and blue eyes:
χ² = (15 - 28.1)² / 28.1 ≈ 6.07.
To complete the total chi-square statistic, find each cell’s chi-squared value and sum them up across all
the nine cells in the table.
Degrees of Freedom (df):
df = (number of rows - 1) × (number of columns - 1)
df = (3 - 1) × (3 - 1)
df = 2 × 2 = 4
Finding p-value:
You may reference a chi-square distribution table to get an estimated chi-square stat of (χ²) using
the appropriate degrees of freedom. Look for the closest value and its corresponding p-value since most
tables do not show precise numbers.
If your Chi-square value was 20.5, you would observe that the nearest number in the table for df = 4 is
14.88 with a p-value in 0.005; an illustration is.
Interpreting Results:
 Selecting a level of significance (α = 0.05 is common)or than if the null hypothesis holds, the
probability of either rejecting it at all is limited (Type I error).
 Compare the alpha value and p-value.
 When the p-value is less than the significance level, which in this case is written as p-value <
0.05, we can reject the null hypothesis. There is sufficient evidence to say that hair and eye color are
related in one direction according to statistical terms. If the p-value is greater than the significance level
it means that we cannot reject the null hypothesis therefore p-value > 0.05.
 Based on the data at hand, we cannot say that there is a statistically significant correlation
between eye and hair colors.
Q1. Market Research on Beverages
A company conducts a survey to determine whether there's a relationship between age groups and
preferred beverages. The data collected is as follows:
Age Coffee Tea Soft Water
Group Drinks
18-25 30 20 25 15
26-35 25 30 20 25
36-45 20 25 30 25
46-55 15 20 25 40
Use a chi-square test to determine if there is an association between age groups and preferred
beverages.
Q2. Student Performance
A teacher wants to find out if there is a relationship between study habits and grades. The data collected
is as follows:
Study A B C D F
Habits
Regular 15 20 25 10 5
Occasional 10 15 20 15 10
Rare 5 10 15 20 25
Perform a chi-square test to determine if study habits and grades are associated.
Q3. Gender and Major
A university wants to see if there is an association between gender and chosen major. The data collected
is:
Major Male Female
Engineering 60 30
Business 40 50
Arts 20 40
Sciences 30 30
Conduct a chi-square test to examine if gender and chosen major are related.
Q4. Voting Preferences
A political analyst wants to know if there is a relationship between gender and voting preference. The
data is:
Preference Male Female
Candidate
80 90
A
Candidate
70 60
B
Undecided 50 40
Test the hypothesis that gender and voting preference are independent.
Q5. Diet and Exercise
A health study examines the relationship between diet type and exercise frequency. The data is:
Exercise Vegan Vegetarian Omnivore
Frequency
Regular 40 30 50
Occasionally 30 40 30
Never 20 30 20
Use a chi-square test to determine if diet type and exercise frequency are associated.

Anova Test
ANOVA (Analysis of Variance) is a statistical method used to determine whether there are significant
differences between the means of three or more independent groups by analyzing the variability within
each group and between the groups. It helps in testing the null hypothesis that all group means are
equal.
It does this by comparing two types of variation: (F-statistics)
1. Differences BETWEEN groups (how much group averages differ from each other)
2. Differences WITHIN groups (how much individuals in the same group vary naturally).
If the between-group differences are significantly larger than within-group variation, ANOVA tells us: At
least one group is truly different. Otherwise, it concludes: The differences are likely due to
random chance.

For example:
Compare test scores of students taught with 3 methods (Traditional, Online, Hybrid). ANOVA is used
to determine if at least one teaching method yields significantly different average scores.
ANOVA Formula
The ANOVA formula is made up of numerous parts. The best way to tackle an ANOVA test problem is to
organize the formulae inside an ANOVA table.
Here's a general structure of an ANOVA table:

where,
 F = ANOVA Coefficient
 MSB = Mean of the total of squares between groupings
 MSW = Mean total of squares within groupings
 MSE = Mean sum of squares due to error
 SST = total Sum of squares
 p = Total number of populations
 n = The total number of samples in a population
 SSW = Sum of squares within the groups
 SSB = Sum of squares between the groups
 SSE = Sum of squares due to error
 s = Standard deviation of the samples
 N = Total number of observations

Assumptions of ANOVA
These must be validated before analysis:
1. Independence: Observations are randomly sampled, and groups are independent.
2. Normality: Residuals (errors) are approximately normally distributed (checked via Q-Q plots or
Shapiro-Wilk test).
3. Homoscedasticity: Equal variances across groups (verified using Levene’s or Bartlett’s test).
ANOVA is robust to minor violations of normality and homoscedasticity with balanced sample sizes.
Calculating ANOVA
Let's explore calculating ANOVA for the scenario:
Compare plant growth under 3 fertilizers (A, B, C):
 Fertilizer A: [10, 11, 12]
 Fertilizer B: [7, 8, 9]
 Fertilizer C: [4, 5, 6]
1. State Hypothesis
 Null Hypothesis (H0): μA = μB = μC
 Alternative Hypothesis (Ha ): At least one μ differs.
2. Calculate Group means and Grand mean.
 Group Means: x̄A, x̄B and x̄C
 Grand Mean: x̄grand
X‾A=10+11+12/3=11
X‾B=7+8+9/3=8
X‾C=4+5+6/3=5

X‾grand=10+11+12+7+8+9+4+5+6/9 =72/9 = 8

3. Compute Sum of Squares (SS):


SSB (Sum of Squares Between Groups): Accounts for variation due to the treatment or independent
variable.
SSB=∑ni(x̄i− x̄grand) 2
SSE (Sum of Squares Error or Within Groups): Accounts for variation within groups (random error or
residuals).
SSE=∑(xi− x̄) 2

SST (Total Sum of Squares): Accounts for total variation from overall mean.
SST = SSB + SSW
SSB = 3(11 − 8)2 + 3(8 − 8)2 + 3(5 − 8)2 = 3(9) + 3(0) + 3(9) = 54
SSE:
 Fertilizer A: (10 − 11)2 + (11−11)2 + (12−11)2 = 1 + 0 + 1 = 2
 Fertilizer B: (7 − 8)2 + (8 − 8)2 + (9 − 8)2 = 1 + 0 + 1 = 2
 Fertilizer C: (4 − 5)2 + (5 − 5)2 + (6 − 5)2 = 1 + 0 + 1 = 2
SSW = 2 + 2 + 2 = 6
SST = 54 + 6 = 60

4. Calculate Degrees of Freedom (df):


df1 (Between Groups) = k - 1, where k is number of groups.
df2 (Within Groups) = N - k, where N is the total observations.
df3 (Total) = N - 1.
 df1 = 3 - 1 = 2
 df2 = 9 - 3 = 6
 df3 = 9 - 1 = 8
5. Calculate Mean Squares (MS):
MSB (Mean Square Between Groups) = SSB / df1.
MSE (Mean Square Error) = SSE / df2.
 MSB=SSB/df1=54/2=27
 MSW=SSW/df2=6/6=1

6. F-statistic:
The F-statistic is calculated as the ratio of MSB to MSE:
F=MSBMSEF=MSEMSB
 F=27/1=27
7. P-value:
The p-value is used to decide whether differences among groups are statistically significant. When the
p-value is smaller than the significance level (α), the null hypothesis is rejected.
If F > Fcritical → p < 0.05 : Null Hypothesis Rejected
Use the F-distribution table or software with: Numerator df1 = 2 , Denominator df2 = 6, α=0.05
Critical F-value, Fcritical: 5.14 (From F-distribution table)
F > Fcritical : 27 > 5.14 → p < 0.05; Reject null hypothesis

Types of ANOVA
An ANOVA test can be classified as either one-way or two-way based on the number of independent
variables involved.
One-Way ANOVA
This test is used to see if there is a variation in the mean values of three or more groups. Such a test is
used where the data set has only one independent variable. If the test statistic exceeds the critical value,
the null hypothesis is rejected, and the averages of at least two different groups are statistically
significant.
Two-Way ANOVA
Two independent variables are used in the two-way ANOVA. A two-way ANOVA test is used to
determine the main effect of each independent variable and whether there is an interaction effect. Each
factor is examined independently to determine the main effect, as in a one-way ANOVA. Furthermore, all
components are analyzed at the same time to test the interaction impact.
Solved Examples on ANOVA
Example 1: Three different kinds of food are tested on three groups of rats for 5 weeks. The objective is
to check the difference in mean weight(in grams) of the rats per week. Apply one-way ANOVA using a
0.05 significance level to the following data:
Food I Food II Food III
8 4 11
12 5 8

19 4 7
8 6 13
6 9 7

11 7 9
Solution:
H0: μ1= μ2=μ3
H1: The means are not equal
Since, X̄1 = 5, X̄2 = 9, X̄3 = 10
Total mean = X̄ = 8
 SSB = 6(5 - 8)2 + 6(9 - 8)2 + 6(10 - 8)2 = 84
 SSE = 68
 MSB = SSB/df1 = 42
 MSE = SSE/df2 = 4.53
 f = MSB/MSE = 42/4.53 = 9.33
Since f > F, the null hypothesis stands rejected.
Example 2: Calculate the ANOVA coefficient for the following data:
Average
Plant Number span s
Hibiscus 5 12 2
Marigold 5 16 1

Rose 5 20 4
Solution:
Plant n x s s2
Hibiscus 5 12 2 4
Marigold 5 16 1 1
Rose 5 20 4 16
p=3
n=5
N = 15
x̄ = 16
SST = Σn(x−x̄)2
 SST= 5(12 − 16)2 + 5(16 − 16)2 + 11(20 − 16)2 = 160
 MST = SST/p-1 = 160/3-1 = 80
 SSE = ∑ (n−1) = 4 (4 + 1) + 4(16) = 84
 MSE = 7
 F = MST/MSE = 80/7
 F = 11.429
Example 3: The following data show the number of worms quarantined from the GI areas of four groups
of muskrats in a carbon tetrachloride anthelmintic study. Conduct a two-way ANOVA test.
I II III IV
338 412 124 389

324 387 353 432

268 400 469 255


147 233 222 133

309 212 111 265


Solution:
Source of Sum of Degrees of Mean
Variation Squares Freedom Square
Between
62111.6 8 9078.067
the groups

Within the
98787.8 16 4567.89
groups
Total 167771.4 24
Since F = MST / MSE
= 9.4062 / 3.66
F = 2.57
Example 4: Enlist the results in APA format after performing ANOVA on the following data set:
[ nmeansd 3050.2610.45 3045.3212.76 3053.6711.47]⎣⎡ n 30 30 30mean50.2645.3253.67sd10.4512.7611.47⎦⎤
Solution:
 Variance of first set = (10.45)2 = 109.2
 Variance of second set = (12.76)2 = 162.82
 Variance of third set = (11.47)2 = 131.56
MSerror = {109.2 + 162.82 + 131.56} / {3}
= 134.53
MSbetween = (17.62)(30) = 528.75
F = MSbetween / MSerror
= 528.75 / 134.53
F = 4.86
APA writeup: F(2, 87)=3.93, p >=0.01, η2=0.08.
Practice Problem Based On ANOVA
Question 1. Method A = {80, 85, 90, 87}, Method B = {75, 78, 72, 74}, and Method C = {88, 85, 90, 92}
are given. State the null and alternative hypotheses for performing a One-Way ANOVA test.
Question 2. Calculate the F-statistic for the given data using One-Way ANOVA. Group 1 = {5, 6, 7, 8},
Group 2 = {4, 5, 6, 5}, and Group 3 = {7, 7, 6, 8}.
Question 3. Interpret the significance of the p-value for the interaction effect in a Two-Way ANOVA,
where the p-value for the interaction effect is 0.02 and the significance level (α\alphaα) is 0.05.
Question 4. Group A = {10, 12, 14, 13}, Group B = {15, 17, 16, 18}, and Group C = {20, 22, 21, 23} are
given. Interpret the p-value of the ANOVA test and explain whether the null hypothesis is rejected, where
F-statistic = 4.86 and p-value = 0.01.
Answer:-
1. Null Hypothesis (H₀): μ₁ = μ₂ = μ₃ (The means of all groups are equal). Alternative Hypothesis (H₁): At
least one mean is different.
2. F-statistic = 4.58.
3. If the p-value (0.02) is less than the significance level (0.05), reject the null hypothesis and conclude
that there is a significant interaction effect.
4. Since the p-value (0.01) is less than 0.05 and the F-statistic is significant, we reject the null hypothesis,
indicating a significant difference between the group means.

One-Way ANOVA Example


Consider the example given below to understand step by step how to perform this test. The marks of 3
subjects (out of 5) for a group of students is recorded. (as given in the table below)
[Take α = 0.05]
English Science
Std/Sub (e) Math (m) (s)

Student 1
2 2 1

Student 2
4 3 2

Student 3
2 4 5

Step 1: Define the hypothesis


 Null hypothesis, H0:μE=μM=μS (where μ = mean)
 Alternate hypothesis, Ha: At least one difference among the means of the 3 subjects.
Step 2: Degres of Freedom
As per the table, k = 3, n = 9
dfbetween=k−1=3−1=2
dfwithin=n−k=9−3=6
dftotal=dfbetween+dfwithin
=2+6=8
Step 3 Find the F-value corresponding to Degree of Freedom and alpha
On referring to the F-Distribution table, using df1 = 2 and df2 = 6 at α = 0.05: we get, Ftable = 5.14
Step 4 Compute the mean
μe=(2+4+2)/3=(8/3)=2.67
μm=(2+3+4)/3=(9/3)=3.00
μs=(1+2+5)/3=(8/3)=2.67
μgrand=(8+8+9)/9=(25/9)=2.
Step 5 Compute the Sum of Squares
SSTotal=∑(xi−μGrand) 2 =(2−2.78) 2 +(4−2.78) 2 +(2−2.78) 2 +(2−2.78) 2 +(3−2.78) 2 +(4−2.78) 2 +(1−2.78) 2
+(2−2.78) 2 +(5−2.78) 2 =13.60

SSwithin=∑(xi−μi) 2 =(2−2.67) 2 +(4−2.67) 2 +(2−2.67) 2 +(2−3.00) 2 +(3−3.00) 2 +(4−3.00) 2 +(1−2.67) 2 +(2−2.67)


2
+(5−2.67) 2 =13.34

SSbetween=SSTotal−SSwithin=13.60−13.34=0.23
Step 6 Find the variance
S2between=SSbetween/dfbetween=0.23/2=0.115≈0.12
S2within=SSwithin/dfwithin=13.34/6=2.22
Step 7 Compute F-statistics
Fcalc=S2between/S2with in=0.12/2.22=0.05
Since, Fcalc < Ftable (0.05 < 5.14)
We cannot reject the null hypothesis.
Thus, we can say that the means of all three subjects is the same.
Conclusion
One-way ANOVA compares three or more than three categorical groups to establish whether there is a
difference between them. The fundamental strategy of ANOVA is to systematically examine variability
within groups being compared and also examine variability among the groups being compared.

Limitations of One Way ANOVA Test


Various limitations of one way ANOVA test are:
 Assumes homogeneity of variance.
 Sensitive to outliers.
 Assumes normality of data distribution.
 Works best with equal sample sizes.
 Does not identify specific group differences.
 Multiple post-hoc tests increase Type I errors.
 Cannot assess interactions between variables.
Two Way ANOVA
Two-way ANOVA is a statistical analysis method used to assess how two independent variables
(factors) affect a dependent variable simultaneously. It examines both the main effects of each factor
and any interaction effects between them.
This method allows researchers to understand not only the individual effects of each factor but also how
they may interact to influence the outcome. Two-way ANOVA is commonly applied in experimental
research to study complex relationships between variables.
When to Use a Two-Way ANOVA
Two way ANOVA formula is used to in various cases including:
 Use a Two-Way ANOVA when you want to analyze the effects of two categorical independent
variables on a continuous dependent variable.
 It helps determine if there are significant interactions between the two independent variables and if
each independent variable has a significant main effect.
 Useful when studying how two factors simultaneously influence the dependent variable.
 Allows for comparison of means across multiple groups formed by the combinations of the two
independent variables.
 Helps in understanding whether the effects observed are due to one variable, the other, or both.
Two-Way ANOVA Assumptions
Various assumptions to use Two-way ANOVA are:
 Equal Variance: The variability within each group is roughly the same.
 Normality: The data within each group are normally distributed.
 Independence: Observations within each group are independent of each other and across groups.
 Homogeneity of Regression Slopes: The relationship between the independent and dependent
variables is consistent across all groups.
Two-Way ANOVA: Examples
Various examples where two way ANOVA concepts are used:
 Medicine Experiment: Testing the effect of two types of medicine (A and B) on patients from different
age groups (young and old).
 Crop Yield Study: Analyzing the impact of two fertilizers (X and Y) on crop yield across different soil
types (sandy and loamy).
 Education Intervention: Evaluating the effectiveness of two teaching methods (traditional and online)
on students from different socioeconomic backgrounds (low-income and high-income).
 Marketing Campaign: Assessing the influence of two advertising strategies (social media and
television) on customer response among different geographical regions (urban and rural).
 Fitness Program Evaluation: Investigating the effects of two exercise routines (aerobic and strength
training) on fitness levels among various age categories (teens, adults, seniors).
F-Test in Statistics

F test is a statistical test that is used in hypothesis testing that determines whether the variances
of two samples are equal or not. The article will provide detailed information on f test, f statistic,
its calculation, critical value and how to use it to test hypotheses. To understand F test firstly we
need to have some basic understanding of F-distribution.

F-distribution
The F-distribution is a continuous statistical distribution used to test whether two samples have the same
variance. The F-Distribution has two parameters the numerator degrees of freedom (df1) and the
denominator degrees of freedom (df2).
Formula for F-distribution:
f-value=sample1/df1 / sample2/df2
 The independent random variables Samples 1 and 2, have a chi-square distribution.
 The related samples' degrees of freedom are denoted by df1 and df2.
Understanding F-Test
In F test the data follows an F distribution. This test uses the F statistic to compare two variances by
dividing them. An F test can either be one-tailed or two-tailed depending upon the parameters of the
problem. The F value obtained after conducting an F test is used to perform the one-way ANOVA
(analysis of variance) test. We can use this test when:
 The population is normally distributed.
 The samples are taken at random and are independent samples.
Hypothesis Testing Framework for F-test
For various hypothesis tests the F test formula is provided as follows:
1. Left Tailed Test:
Null Hypothesis: H0 : σ12=σ22
Alternate Hypothesis: H1 : σ12<σ22
Decision-Making Standard: The null hypothesis is to be rejected if the F statistic is less than the F critical
value.
2. Right Tailed Test:
Null Hypothesis: H0 : σ12=σ22
Alternate Hypothesis: H1 : σ12>σ22
Decision-Making Standard: Dismiss the null hypothesis if the F test statistic is greater than the F test
critical value.
3. Two Tailed Test:
Null Hypothesis: H0 : 𝜎1^2 = 𝜎2^2
Alternate Hypothesis: H1 : σ1^2≠σ2^2

Decision-Making Standard: When the F test statistic surpasses the F test critical value the null
hypothesis is declared invalid.

F Test Statistics
The F test statistic or simply the F statistic is a value that is compared with the critical value to check if
the null hypothesis should be rejected or not. The F test statistic formula is given below:
F statistic for large samples: Fcalc= 𝜎1^2 /𝜎2^2 where 𝜎1^2 is the variance of the first population
and 𝜎2^2 is the variance of the second population.
F statistic for small samples: Fcalc= s1^2 /s2^2 where s1^2 is the variance of the first sample and s2^2
is the variance of the second sample.
Steps to calculate F-Test
Step 1: Use Standard deviation (𝜎1) and find variance (𝜎2) of the data. (if not already given)
Step 2: Determine the null and alternate hypothesis.
 H0: no difference in variances.
 H1: difference in variances.
Step 3: Find Fcalc using Equation 1 (F-value).
NOTE : While calculating Fcalc, divide the larger variance with small variance as it makes calculations
easier.
Step 4: Find the degrees of freedom of the two samples.
Step 5: Find Ftable value using d1 and d2 obtained in Step-4 from the F-distribution table. Take learning
rate, α = 0.05 (if not given)
Looking up the F-distribution table:
In the F-Distribution table as per the given value of α in the question.
 d1 (Across) = df of the sample with numerator variance. (larger)
 d2 (Below) = df of the sample with denominator variance. (smaller)
Consider the F-Distribution table given below, while performing One-Tailed F-Test.

GIVEN:
α = 0.05
d1 = 2
d2 = 3
d2 /d1
1 2
161.4 199.5
1

18.51 19.00
2

10.13 9.55
3
Then, Ftable = 9.55
Step 6: Interpret the results using Fcalc and Ftable.
Interpreting the results:
If Fcalc < Ftable :
Cannot reject null hypothesis.
∴ Variance of two populations are similar.

If Fcalc > Ftable :


Reject null hypothesis.
∴ Variance of two populations are not similar.
Example Problem for calculating F-Test
Consider the following example In this we conduct a two-tailed F-Test on the following samples:
Sample 1 Sample 2

σ 10.47 8.12
n 41 21
Step 1: The statement of the hypothesis is formatted as:
 H0: no difference in variances.
 H1: difference in variances.
Step 2: Let's calculated the value of the variances in numerator and denominator as F-value= σ12σ22σ22
σ12
 σ12 = (10.47)2 = 109.63
 σ22 = (8.12)2 = 65.99
Fcalc = (109.63 / 65.99) = 1.66
Step 3: Now, let's calculate the degree of freedom: Degree of freedom = sample - 1 Here we have
Sample 1 = n1 = 41 and
Sample 2 = n2 = 21
Degree of sample 1 = d1 = (n1 - 1) = (41 – 1) = 40
Degree of sample 2 = d2 = (n2 — 1) = (21 – 1) = 20
Step 4: The usual alpha level of 0.05 is selected because the question does not specify an alpha level.
The alpha level should be lowered during the test to half of its starting value. Using d1 = 40 and d2 = 20
in the F-Distribution table. (link here) and Take α = 0.05 as it's not given. Since it is a two-tailed F-test
then:
α = 0.05/2 = 0.025
Step 5: The critical F value is found with alpha at 0.025 using the F table. For (40, 20), the critical value
at alpha equal to 0.025 is 2.287. Therefore, Ftable = 2.287
Step 6: Since Fcalc < Ftable (1.66 < 2.287):
We cannot reject null hypothesis.
∴ Variance of two populations is similar to each other.
F-Test is the most often used when comparing statistical models that have been fitted to a data set to
identify the model that best fits the population.

 Example 1: A research team wants to study the effects of a new drug on insomnia. 8 tests were
conducted with a variance of 600 initially. After 7 months 6 tests were conducted with a variance of 400.
At a significance level of 0.05 was there any improvement in the results after 7 months?
Solution: As the variance needs to be compared, the f test needs to be used.
H0 : s1^2= s2^2
H1 : s1^2 > s2^2
n1 = 8, n2 = 6
df1 = 8 - 1 = 7
df2 = 6 - 1 = 5
s1^2 = 600, s2^2= 400
The f test formula is given as follows:
F = s1^2 / s2^2 = 600 / 400
F = 1.5
Now from the F table the critical value F(0.05, 7, 5) = 4.88

As 1.5 < 4.88, thus, the null hypothesis cannot be rejected and there is not enough evidence to
conclude that there was an improvement in insomnia after using the new drug.
Answer: Fail to reject the null hypothesis.

 Example 2: Pizza delivery times of two cities are given below


City 1: Number of delivery times observed = 28, Variance = 38
City 2: Number of delivery times observed = 25, Variance = 83
Check if the delivery times of city 1 are lesser than city 2 at a 0.05 alpha level.
Solution: This is an example of a left-tailed F test. Thus, the alpha level is 1 - 0.05 = 0.95
H0 : s1^2 = s2^2

H1 : s1^2 < s2^2


As 38 < 83 thus, city 1 will be sample 1 and city 2 is sample 2.
n1 = 28, n2 = 25
df1 = 28 - 1 = 27
df2 = 25 - 1 = 24
s1^ = 38, s2^2 = 83
F = s1^2 /s2^2 = 38 / 83
F = 0.4578
As an F table for 0.95 alpha level is not available, the critical value is determined as follows:
F(0.95, 27, 24) = 1 / F(0.05, 24, 27)
F(0.05, 24, 27) = 1.93
F(0.95, 27, 24) = 1 / 1.93 = 0.5181
As 0.4578 < 0.5181, thus, the null hypothesis can be rejected and it can be concluded that there is
enough evidence to support the claim that the delivery times in city 1 are less than in city 2.
Answer: Reject the null hypothesis

 Example 3: A toy manufacturer wants to get batteries for toys. A team collected 41 samples from
supplier A and the variance was 110 hours. The team also collected 21 samples from supplier B with a
variance of 65 hours. At a 0.05 alpha level determine if there is a difference in the variances.
Solution: This is an example of a two-tailed F test. Thus, the alpha level is 0.05 / 2 = 0.025
H0 : s1^2 = s2^2
H1 : s1^2 ≠ s2^2
n1 = 41, n2 = 21
df1 = 41 - 1 = 40
df2 = 21 - 1 = 20
s1^2 = 110, s2^2= 65
F = s1^2 / s2^2 = 110 / 65
F = 1.69
Using the F table F(0.025, 40, 20) = 2.287
As 1.69 < 2.287 thus, the null hypothesis cannot be rejected,
Answer: Fail to reject the null hypothesis.

F Test vs T-Test

F test and t-test are different types of statistical tests used for hypothesis
testing depending on the distribution followed by the population data. The
table given below outlines the differences between the F test and the t-test.

F Test T-Test
The T-test is
An F test is
used when
a test
the sample
statistic
size is small
used to
(n < 30) and
check the
the
equality of
population
variances
standard
of two
deviation is
populations
not known.
The data The data
F Test T-Test
follows an follows a
F Student t-
distribution distribution
The t-test
statistic for 1
sample is
given by t

=
x̄ −μ / s/√n,
where 𝑥̄ is
The F test the sample
statistic is
given as F mean, μ is
= 𝜎1^2 / 𝜎2^2 the
population
mean, s is
the sample
standard
deviation
and n is the
sample size.

The f test is
It is used for
used for
testing means.
variances.

You might also like