[go: up one dir, main page]

0% found this document useful (0 votes)
29 views59 pages

Hypothesis Testing

Hypothesis testing is a statistical method used to determine if there is enough evidence in a sample to support a specific claim about a population. It involves formulating a null hypothesis (H₀) and an alternative hypothesis (H₁), and can utilize various tests such as Z-tests, t-tests, ANOVA, and chi-square tests depending on the data characteristics. Key concepts include understanding Type I and Type II errors, significance levels, and the appropriate use of statistical tables for decision-making.

Uploaded by

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

Hypothesis Testing

Hypothesis testing is a statistical method used to determine if there is enough evidence in a sample to support a specific claim about a population. It involves formulating a null hypothesis (H₀) and an alternative hypothesis (H₁), and can utilize various tests such as Z-tests, t-tests, ANOVA, and chi-square tests depending on the data characteristics. Key concepts include understanding Type I and Type II errors, significance levels, and the appropriate use of statistical tables for decision-making.

Uploaded by

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

Hypothesis Testing

Links:

https://www.w3schools.com/statistics/statistics_hypothesis_testing.php

https://www.geeksforgeeks.org/understanding-hypothesis-testing/

https://www.geeksforgeeks.org/data-science-for-beginners/?
utm_source=geeksforgeeks&utm_medium=gfgcontent_shm&utm_campaign=shm

https://www.geeksforgeeks.org/machine-learning/?ref=shm

https://www.geeksforgeeks.org/hypothesis/

https://www.colorado.edu/amath/sites/default/files/attached-files/lesson9_hyptests.pdf

https://www.cse.iitk.ac.in/users/nsrivast/HCC/lec07-09.pdf

https://www.analyticsvidhya.com/blog/2021/07/hypothesis-testing-made-easy-for-the-data-science-
beginners/

https://www.simplilearn.com/tutorials/statistics-tutorial/hypothesis-testing-in-statistics

https://www.cuemath.com/data/hypothesis-testing/

https://www.vedantu.com/maths/hypothesis-testing

https://www.analyticsvidhya.com/blog/2021/09/hypothesis-testing-in-machine-learning-everything-
you-need-to-know/

https://www.ncl.ac.uk/webtemplate/ask-assets/external/maths-resources/statistics/hypothesis-
testing/one-tailed-and-two-tailed-tests.html

can you teach me hypothesis testing,one tailed two tailed,z ,t,f,anova,chi


square tests,when to use these with examples,there distributions,how to use
ztable,t table etc
🧠 1. Basics of Hypothesis Testing

https://www.w3schools.com/statistics/statistics_hypothesis_testing.php

Hypothesis Testing

A hypothesis is a claim about a population parameter.

A hypothesis test is a formal procedure to check if a hypothesis is true or not.

Examples of claims that can be checked:

The average height of people in Denmark is more than 170 cm.

The share of left handed people in Australia is not 10%.


The average income of dentists is less the average income of lawyers.

What is Hypothesis Testing?

A method to decide whether there's enough evidence in a sample of data to infer that a certain
condition holds true for the entire population.

 Null Hypothesis (H₀): Status quo, no effect or difference.

 Alternative Hypothesis (H₁ or Hₐ): The claim you're testing for (effect or difference exists).

🎯 2. One-tailed vs Two-tailed Tests

 One-tailed test: You check for effect in one direction (greater than / less than).

 Two-tailed test: You check for any difference (either greater or smaller).

📌 Example:

 Testing if new teaching method > old method: one-tailed

 Testing if there's any difference (better or worse): two-tailed

Steps for a Hypothesis Test

The following steps are used for a hypothesis test:

1. Check the conditions

2. Define the claims

3. Decide the significance level

4. Calculate the test statistic

5. Conclusion
📊 3. Key Tests and When to Use Them

Test Use When Distribution Example

Large sample (n > 30), population std Test mean of sample vs


Z-test Z (Normal)
dev known population

Small sample (n ≤ 30), std dev


t-test t-distribution Compare means
unknown

F-test Compare variances F-distribution Test equality of variances

ANOVA Compare more than 2 means F-distribution Test 3+ groups' mean equality

Chi- Chi-square Test independence or


Categorical data
square distribution goodness of fit

Great question! Understanding Type I and Type II errors is crucial for mastering hypothesis testing
and statistical thinking in machine learning and beyond. Let’s break it down simply and visually:

🎯 The Setup:

In hypothesis testing, we start with:

 Null Hypothesis (H₀): The default assumption (e.g., no effect, no difference).

 Alternative Hypothesis (H₁): What you’re trying to prove.

🔍 Two Types of Errors:

H₀ True H₀ False (H₁ True)

Reject H₀ ❌ Type I Error (α) ✅ Correct decision (Power)

Fail to Reject H₀ ✅ Correct decision ❌ Type II Error (β)


🟥 Type I Error (False Positive)

 Definition: Rejecting a true null hypothesis.

 You think you found an effect, but it was just random noise.

 Significance level (α) = Probability of making a Type I error.

📌 Example:
You say a new drug works, but in reality, it doesn’t.
(You're fooled by random chance.)

🟦 Type II Error (False Negative)

 Definition: Failing to reject a false null hypothesis.

 You miss a real effect that actually exists.

 β = Probability of making a Type II error.

📌 Example:
You say the drug doesn’t work, but actually, it does.
(You missed a real signal.)

🔁 Relationship between α and β:

 Decreasing α (being more strict) → Increases β (harder to detect real effects).

 Increasing sample size helps reduce both.

🎯 Visual Intuition:

|------------------------|

| TYPE I ERROR | Reject H₀ when it is true

|------------------------|

Critical Region

|------------------------|

| TYPE II ERROR | Accept H₀ when H₁ is true

|------------------------|

💡 Memory Tip:
 Type I (False Positive) = "Cried wolf" 🐺 when there was none.

 Type II (False Negative) = "Missed the wolf" 🐺 when it was actually there.

Would you like a quick Python simulation to visualize this with actual data?

📏 4. Z-distribution & Z-table

 Z-distribution is the standard normal distribution (mean=0, std=1).

 Z-table gives you area (probability) under the curve to the left of the z-value.

📌 Z-test Formula:

Z-Distribution and Table for Negative Z-values

Z-Distribution and Table of Positive Z-Values


Example of How to Use the Z-Table
The Z-value is found combining the numbers in the first column and the
first row.
For example, the probability for getting a z-value smaller than 1.85 is
found by finding the number in the table where the row is 1.8 and the
column is 0.05.
So the probability is: 0.9678 is 96.78%.

📈 5. t-distribution & t-table

 Used when population std dev is unknown.

 T-distribution has thicker tails, depends on degrees of freedom (df = n-1).

 The Student's t-distribution is similar to a normal distribution. But it


is adjusted for uncertainty with smaller sample sizes.
 Smaller sample sizes give fewer degrees of freedom (df), which
makes the tails larger.

In simple terms, degrees of freedom (df) refer to the number of independent values that can
vary in a calculation. For example, in a t-distribution:

 Degrees of freedom = n−1n - 1n−1 for a one-sample t-test (where nnn is the sample size).

🧠 Why do smaller sample sizes give larger tails?

When you have a smaller sample size:

 You have fewer degrees of freedom.

 The t-distribution becomes wider and has fatter tails compared to the normal distribution.

 This means there's more uncertainty (or variability) in your estimate of the population
parameter (like the mean).

📈 Visual idea:
 With large df (i.e., large sample sizes), the t-distribution starts to look like the standard
normal (z) distribution.

 With small df, the t-distribution has heavier tails, meaning there's a higher probability of
getting values far from the mean.

🎯 Why does it matter?

 Critical values (like the t-score you need to reject the null hypothesis) are higher for smaller
samples.

 So, with a smaller sample, you need a larger observed effect to claim significance at the
same confidence level.

 T-Distribution and Table of Critical


T-Values
 The numbers in the table cells correspond to critical t-values for
different tail-areas (α).
 The tail areas are probabilities. For example, 0.05 is 5% percent
probability.
 Each row corresponds to different degrees of freedom (df).
📌 One-sample t-test:

🧪 6. ANOVA (Analysis of Variance)

Used when comparing 3 or more group means.

📌 Example: Testing effect of 3 diets on weight loss.

 H₀: All group means are equal

 Hₐ: At least one group mean is different

If F-statistic is high and p-value < 0.05, reject H₀.

🧮 7. Chi-Square Test

Two types:

1. Goodness of Fit – does observed data match expected?

2. Test of Independence – are two categorical variables independent?

📌 Example: Survey on preference (Tea vs Coffee) across gender.


Where:

 O = Observed

 E = Expected

📚 Using Z and t Tables

Z-table:

 Look for row = first 2 digits, column = second decimal.

 For Z = 1.96 → Go to row 1.9, column 0.06 → value ≈ 0.975

t-table:

 Look up by degrees of freedom and significance level (e.g., 0.05).

 For df=10 and 0.05 (two-tailed), t ≈ 2.228

Z-test example

✅ Z-Test Walkthrough

🎯 Use When:

 Sample size is large (n > 30)

 Population standard deviation (σ) is known

🧪 Example Problem (One-sample Z-test)

A company claims that their light bulbs last 1000 hours on average. A random sample of 36 bulbs has
a mean life of 980 hours. The population standard deviation is 60 hours. At a 0.05 significance level,
test whether the company's claim is valid.

🔢 Step-by-Step Solution

Step 1: Set Hypotheses

 H₀ (Null): μ = 1000 (claim is valid)

 H₁ (Alt): μ ≠ 1000 (claim is false) → Two-tailed test


Step 2: Calculate the Z-statistic

Step 4: Compare with significance level (α = 0.05)

 Since p-value = 0.0456 < 0.05, Reject H₀

🔚 Conclusion: There is enough evidence to doubt the company’s claim. The average bulb life is likely
not 1000 hours.

Excellent question! Let's clarify the difference between the value you get from the Z-table, the p-
value, and the critical value, because they are related but not the same.

🧭 The Z-table gives you:

🔹 The cumulative probability (area under the curve to the left of a z-score).

This value is not directly the p-value or the critical value—but it helps you calculate both.

✅ Definitions
Term What It Is How It's Used

Z-table Area to the left of a z-score (i.e., cumulative Used to find p-values and critical
value probability) values

Used to make decisions in


Probability of observing a result as extreme (or more
p-value hypothesis testing (compare with
extreme) than the test statistic, assuming H₀ is true
α)

Critical Cutoff z (or t) value at a specific significance level Used to draw rejection regions on
value (e.g., α = 0.05) the distribution

✅ In our example (recap):

 You had a z = -2.0

 From Z-table: area to the left of z = -2.0 is 0.0228

 This is not the p-value, but it's half of it (since it’s a two-tailed test)

 So:

p-value=2×0.0228=0.0456\text{p-value} = 2 \times 0.0228 = 0.0456

📍 How about Critical Values?

If you set:

 Significance level α = 0.05

 Two-tailed test → split α into 0.025 in each tail

Then the critical z-values are:

 ±1.96 → because area to the left of z = 1.96 is 0.975, and to the right is 0.025

So:

 If your z-score is beyond ±1.96, you reject H₀

 Your test statistic was -2.0 → it falls outside → reject H₀ ✅

🧠 Summary:

You want... Use Z-table to... Example

p-value Find area from z → double if two-tailed z = -2.0 → area = 0.0228 → p = 0.0456

Critical value Find z at α (e.g., 0.025 per tail) α = 0.05 → critical z = ±1.96

Here’s the plot:


 The red shaded regions on both tails are the rejection regions for a two-tailed test at α =
0.05. The cutoff (critical values) are at ±1.96.

 The green area in the center is where we fail to reject the null hypothesis.

 The blue dashed line is the calculated test statistic (z = -2.0).

Since the blue line lies in the red zone, we reject H₀—our result is statistically significant.

Would you like to go through a similar visual explanation for the t-test next?

Great question! The value ±1.96 comes from the Z-table and is used as the critical z-value for a two-
tailed hypothesis test at a significance level α = 0.05.

Let me break it down step by step:

🎯 We want to find:

The z-value such that 2.5% is in each tail (for a two-tailed test), meaning:

 Left tail: 2.5% = 0.025

 Right tail: 2.5% = 0.025

 Total significance level = 0.05


✅ Step-by-step to find critical z-value

Step 2: Find the z-value corresponding to 0.975

From the Z-table:

 Look for the value 0.9750 in the body of the table

 Corresponds to z ≈ 1.96

So:

zcritical=±1.96\boxed{z_{critical} = ±1.96}

🎨 Visualization

If you're doing a two-tailed test at α = 0.05, the distribution looks like this:

|<---- 2.5% ----|====== 95% ======|---- 2.5% ---->|

-1.96 1.96

🧠 Summary

α (Significance Level) Two-tailed? Critical z-values

0.10 Yes ±1.645

0.05 Yes ±1.96

0.01 Yes ±2.576

Awesome! Let’s break down the types of Z-tests — there are mainly three common types,
depending on what you're comparing:

✅ 1. One-Sample Z-Test

🔍 Use When:

 You're comparing the sample mean to a known population mean


 Population standard deviation (σ) is known

 Large sample (n > 30)

📦 Example:

A company claims the average height of their employees is 170 cm. You take a sample and test if it’s
significantly different from 170 cm.

✅ 2. Two-Sample Z-Test

🔍 Use When:

 You're comparing the means of two independent samples

 You know the population standard deviations for both

 Both sample sizes are large

📦 Example:

Compare average test scores of students from School A vs School B to see if there's a significant
difference.

✅ 3. Z-Test for Proportions

https://www.w3schools.com/statistics/statistics_hypothesis_testing_proportion.php

🔍 Use When:

 You’re comparing proportions (percentages) rather than means

 For one sample or two independent samples

 Population size is large enough for normal approximation

🎯 Types:

 One-proportion Z-test: Compare a sample proportion to a population proportion

 Two-proportion Z-test: Compare proportions between two groups

📦 Example:

Test if 60% of voters support a candidate (claim), and your sample shows 53% do.

 Population: Nobel Prize winners

 Category: Born in the United States of America

 Null hypothesis: 20% of Nobel Prize winners were born in


the US.
 Alternative hypothesis: More than 20% of Nobel Prize
winners were born in the US.

🧠 Summary Table

Population σ
Z-Test Type Used For Sample Size
Known?

Sample mean vs population


One-sample Z-test Yes Large (n > 30)
mean

Two-sample Z-test Mean of group A vs group B Yes Large (n > 30)

Z-test for Comparing proportions (%, Large (np > 5, n(1-p) >
N/A
Proportions ratios) 5)

Would you like to try an example of one of these (you can pick which one), or shall we move to t-
tests next?

The difference between qualitative and quantitative data lies in the type of information they
represent and how they are measured:

🔹 Qualitative Data (Categorical)

 Definition: Descriptive data that cannot be measured with numbers.

 Describes: Qualities or characteristics.

 Examples:

o Colors (e.g., red, blue, green)


o Gender (e.g., male, female)

o Eye color

o Type of car

o Taste (sweet, sour)

 Types:

o Nominal: No natural order (e.g., blood type: A, B, AB, O)

o Ordinal: Has a meaningful order, but differences between values aren't measurable
(e.g., satisfaction levels: low, medium, high)

🔹 Quantitative Data (Numerical)

 Definition: Numeric data that can be counted or measured.

 Describes: Quantities or amounts.

 Examples:

o Age (e.g., 25 years)

o Height (e.g., 160 cm)

o Weight (e.g., 60 kg)

o Number of students

o Income

 Types:

o Discrete: Countable, finite values (e.g., number of children)

o Continuous: Can take any value within a range (e.g., temperature, time)

Quick Comparison:

Feature Qualitative Data Quantitative Data

Nature Descriptive Numerical

Measured with Categories/labels Numbers

Examples Colors, gender, status Height, weight, income

Statistical Analysis Mode, frequency Mean, median, SD, etc.

Would you like to practice identifying data types or dive deeper into examples like in a dataset?

Perfect! Let’s walk through examples of left-tailed, right-tailed, and two-tailed tests for each type of
Z-test so it’s super clear and organized. 🔍✨
🔹 1. One-Sample Z-Test

✅ Scenario: A company claims the average weight of its product is 500g. Population standard
deviation is known (σ = 10g).

📉 Left-tailed test (H₁: μ < 500)

 Claim: The average weight is less than 500g (underdelivering).

 H₀: μ = 500

 H₁: μ < 500

📦 Example: A customer group thinks the company is cheating and delivering less. You test if the
mean weight is significantly lower.

📈 Right-tailed test (H₁: μ > 500)

 Claim: The average weight is more than 500g.

 H₀: μ = 500

 H₁: μ > 500

📦 Example: A nutritionist believes the company might be adding more than needed, and you test if
it’s significantly higher.

🔁 Two-tailed test (H₁: μ ≠ 500)

 Claim: The average is not equal to 500g.

 H₀: μ = 500

 H₁: μ ≠ 500

📦 Example: A regulator audits whether the weight is different from 500g, in either direction.

🔹 2. Two-Sample Z-Test (for Means)

✅ Scenario: Compare average exam scores of students from School A and School B. Population
standard deviations for both schools are known.

📉 Left-tailed test (H₁: μ₁ < μ₂)

 Claim: School A performs worse than School B.

 H₀: μ₁ = μ₂
 H₁: μ₁ < μ₂

📦 Example: You believe School A students score lower on average.

📈 Right-tailed test (H₁: μ₁ > μ₂)

 Claim: School A performs better than School B.

 H₀: μ₁ = μ₂

 H₁: μ₁ > μ₂

📦 Example: You believe a new teaching method in School A makes scores higher.

🔁 Two-tailed test (H₁: μ₁ ≠ μ₂)

 Claim: There is a difference in average scores.

 H₀: μ₁ = μ₂

 H₁: μ₁ ≠ μ₂

📦 Example: An education board checks if there's any significant difference in performance.

🔹 3. Z-Test for Proportions

✅ Scenario: A company claims 60% of customers are satisfied. You survey 100 customers.

📉 Left-tailed test (H₁: p < 0.60)

 Claim: Fewer customers are satisfied than claimed.

 H₀: p = 0.60

 H₁: p < 0.60

📦 Example: A watchdog agency believes the company is exaggerating satisfaction.

📈 Right-tailed test (H₁: p > 0.60)

 Claim: More than 60% of customers are satisfied.

 H₀: p = 0.60

 H₁: p > 0.60

📦 Example: The marketing team believes satisfaction is higher than reported.

🔁 Two-tailed test (H₁: p ≠ 0.60)


 Claim: Satisfaction level is different than 60%.

 H₀: p = 0.60

 H₁: p ≠ 0.60

📦 Example: A researcher checks whether the claim is statistically off, in either direction.

🎁 Summary Table

Z-Test Type Left-Tailed (H₁: <) Right-Tailed (H₁: >) Two-Tailed (H₁: ≠)

One-sample μ < μ₀ μ > μ₀ μ ≠ μ₀

Two-sample μ₁ < μ₂ μ₁ > μ₂ μ₁ ≠ μ₂

Proportion p < p₀ p > p₀ p ≠ p₀

Awesome! Let's work through one example with full calculation for a Z-test for proportion — this
will include hypothesis setup, Z-score calculation, critical value, p-value, and conclusion. ✅

🧪 Example: One-Proportion Z-Test (Right-Tailed)

📌 Problem:

A company claims that at least 60% of customers are satisfied with their product. You believe it’s
higher. You take a sample of 100 customers, and 68 of them are satisfied.

🎯 Step 1: Define Hypotheses

 Null Hypothesis (H₀): p = 0.60

 Alternative Hypothesis (H₁): p > 0.60 (right-tailed test)


🎯 Step 4: Determine Critical Value & p-Value

 Significance level: α = 0.05

 Right-tailed test → Critical z-value = 1.645

 From Z-table:

📌 Step 5: Decision
 Since z = 1.633 < 1.645, we fail to reject H₀

 Also, p-value (0.0516) > α (0.05) → not statistically significant

✅ Conclusion:

There is not enough evidence at the 5% level to support the claim that more than 60% of customers
are satisfied.

Would you like to try this same example using Python/plotting, or shall we move to t-tests next
(types, examples like we did for Z-tests)?

Great! Let’s break down each Z-test scenario (One-Sample, Two-Sample, Proportion) and show how
to compute for left-tailed, right-tailed, and two-tailed cases — including formulas, step-by-step
calculation, and conclusions.

🔹 1. One-Sample Z-Test

Used when population standard deviation (σ) is known and we want to test the mean (μ).

✅ Given:

 Population mean (μ₀) = 500 g

 Population standard deviation (σ) = 10 g

 Sample size (n) = 36

 Sample mean (x̄ ) varies by case

 Significance level (α) = 0.05

📉 Left-Tailed Test (H₁: μ < 500)


🔹 2. Two-Sample Z-Test (for Means)

Comparing means of two independent populations, σ₁ and σ₂ known.

✅ Given:

 School A: x̄ ₁ = 72, σ₁ = 10, n₁ = 40

 School B: x̄ ₂ = 75, σ₂ = 12, n₂ = 50


🔹 3. Z-Test for Proportions

Comparing sample proportion to known proportion.


✅ 1.63 < 1.645 → fail to reject H₀

👉 Not enough evidence satisfaction is higher.


👉 Satisfaction rate significantly different from 60%.

T TEST
Awesome! Let’s now walk through t-tests, just like we did with Z-tests — covering:

 📘 When to use each type

 📊 Formulas

 ✅ Examples for left-tailed, right-tailed, and two-tailed

 📏 Interpretation with t-critical values and conclusions

🔹 1. One-Sample t-Test

Use when population standard deviation (σ) is unknown and sample size is small (n < 30), or
population is not perfectly known.
✅ Given:

 Claimed population mean μ0=100\mu_0 = 100

 Sample mean xˉ=96\bar{x} = 96

 Sample standard deviation s=8s = 8

 Sample size n=16n = 16

 Degrees of freedom (df) = n - 1 = 15

 Significance level α = 0.05


🔹 2. Two-Sample t-Test (Independent)

Comparing means from two unrelated groups, variances assumed equal or unequal.
✅ 0.896 < 1.729, fail to reject

🔹 3. Paired t-Test

Comparing before-after results or related samples.

✅ Example:

 Exam scores before and after training:

o Before: [70, 75, 80, 72, 68]

o After: [74, 78, 82, 74, 70]

o n=5
👉 Conclusion: Training has a significant effect.

Would you like me to continue with F-test, ANOVA, and chi-square tests next?

Awesome! Let's continue the learning journey. Here's a quick plan for the next set of topics:

🔸 F-Test

 Used for: Comparing two variances (e.g., variance of two samples).

 Distribution: F-distribution

 Formula:
.

🔸 ANOVA (Analysis of Variance)

 Used for: Comparing means of three or more groups

 Types: One-way, Two-way ANOVA

 Output: F-statistic

 Null Hypothesis: All group means are equal

🔸 Chi-Square Test (χ²)

 Used for:

o Goodness of fit (does data fit a distribution?)

o Test for independence (association between categorical variables)

 Distribution: Chi-square distribution

Ftest
Great! Let’s break down the F-test step-by-step, along with its types, when to use, formulas, and
examples.

🔹 What is the F-Test?

The F-test is a statistical test used to compare two population variances or used as part of other
tests (like ANOVA).
It uses the F-distribution, which is a ratio of two chi-square distributions.
🧠 When to Use F-Test?

Purpose Use F-Test?

Compare two variances ✅ Yes

Check assumption for ANOVA ✅ Yes

In ANOVA to compare means ✅ Yes


Purpose Use F-Test?

Regression model fit ✅ Yes

3. F-test in Regression

 Tests if the overall regression model is significant.

 H0H_0: All regression coefficients = 0 (no relationship)

 H1H_1: At least one coefficient ≠ 0

✍️Example: Compare Variances (Two-Sample F-test)

Two machines are producing bottle caps:

 Machine A: sample variance = 25, n = 20

 Machine B: sample variance = 10, n = 15


Degrees of freedom:

 df1 = 19, df2 = 14

Using an F-table or p-value:

 If p < α (say 0.05), reject H0H_0; variances are significantly different.

F distribution:
https://statisticsbyjim.com/hypothesis-testing/f-table/
Sure! Let's go through a One-Tailed F-test(right tailed) example step by step — including the
scenario, hypotheses, calculations, and decision-making.

🔹 Scenario:
You are a quality control analyst comparing the consistency (variability) of two machines producing
metal rods.

 You want to test if Machine A produces rods with greater variance (less consistency) than
Machine B.

📘 Step 3: Test Statistic

📉 Step 4: Degrees of Freedom


🧾 Conclusion:

There is enough evidence at α = 0.05 to conclude that Machine A has significantly greater variance
than Machine B.

Would you like a left-tailed F-test example next?

Great! Let’s go through a Left-Tailed F-Test example step by step.

🔹 Scenario:

You are testing if a new machine (Machine A) is more consistent (i.e., has less variance) than the old
one (Machine B).

You want to test if the variance of A is less than B — which is a left-tailed F-test.

✅ Step 1: State Hypotheses


📊 Step 2: Sample Data

Suppose we have the following:

📉 Step 4: Degrees of Freedom

 df1=n1−1=11df_1 = n_1 - 1 = 11

 df2=n2−1=9df_2 = n_2 - 1 = 9
Since:

0.5>0.316⇒Do not reject H00.5 > 0.316 \Rightarrow \text{Do not reject } H_0

🧾 Conclusion:

At the 0.05 level of significance, we do not have enough evidence to conclude that Machine A has
significantly less variance than Machine B.

Would you like to try a Two-Tailed F-test next or shall we move on to ANOVA?

Great question! When the exact degrees of freedom (df₁ = 11, df₂ = 9, etc.) are not listed in the F-
table, we have a few options to find the critical value:

✅ Option 1: Use Statistical Software or Python

This is the most accurate and preferred method.

For example, in Python using SciPy:

from scipy.stats import f

# For left-tailed test

alpha = 0.05

dfn = 11 # numerator

dfd = 9 # denominator
critical_value = f.ppf(alpha, dfn, dfd)

print(critical_value)

For a left-tailed test, you use f.ppf(α, df1, df2).

If it were a right-tailed test, use f.ppf(1 - α, df1, df2).

✅ Option 2: Interpolation from F-Tables

If you're using printed F-tables, you can interpolate between the two closest degrees of freedom.

Example:
You want F0.05(11,9)F_{0.05}(11, 9), but only 10 and 12 are in the table.

1. Find:

o F0.05(10,9)F_{0.05}(10, 9)

o F0.05(12,9)F_{0.05}(12, 9)

2. Take an average or do linear interpolation.

🔹 This gives a rough estimate, not exact, but is acceptable for manual testing.

✅ Option 3: Round to Nearest Available df

If you're doing a quick test:

 Round down for the numerator df (conservative approach).

 Round up for the denominator df.

E.g., use F0.05(10,10)F_{0.05}(10, 10) as an approximate for F0.05(11,9)F_{0.05}(11, 9).

This method tends to increase the critical value, which makes the test slightly more conservative
(i.e., less likely to wrongly reject the null).

Would you like me to calculate the exact critical value for df₁ = 11, df₂ = 9 using Python and show it?

https://saylordotorg.github.io/text_introductory-statistics/s15-03-f-tests-for-equality-of-two-va.html

https://stats.libretexts.org/Bookshelves/Introductory_Statistics/Mostly_Harmless_Statistics_
%28Webb%29/09%3A_Hypothesis_Tests_and_Confidence_Intervals_for_Two_Populations/
9.04%3A_Two_Variance_or_Standard_Deviation_F-Test

Awesome! Let’s walk through a full example of a Two-Tailed F-Test — step by step.
🔷 🎯 Goal:

To test whether two populations have different variances (could be higher or lower), using sample
data.

🔹 Scenario:

You want to check if two different packaging machines (A and B) have significantly different
variances in the weight of packets they produce.
✅ Conclusion:

At the 5% significance level, we do not have enough evidence to say that the variances of Machines
A and B are different.

Would you like to see this visualized on an F-distribution plot with both tails marked?

Great follow-up! Let's talk about how to get upper and lower critical values for a two-tailed F-test
using only an F-table, especially when you don't have software like Python or Excel.

✅ Step-by-Step: Using the F-Table for a Two-Tailed F-Test

🎯 Scenario

You are testing whether two variances are different using a two-tailed F-test at α=0.05\alpha = 0.05.
You have:

 df1=15df_1 = 15 (numerator)

 df2=20df_2 = 20 (denominator)

🔹 F-tables only give you the right-tail critical values, like F0.05F_{0.05} or F0.01F_{0.01}.

So we need to split the two-tailed test:

 Upper tail uses: α/2=0.025\alpha/2 = 0.025 → F0.025(15,20)F_{0.025}(15, 20) from the right
tail

 Lower tail uses: F0.025(20,15)F_{0.025}(20, 15), but inverted!

✅ How to Get the Critical Values from the F-table


🔹 Step 1: Find the upper critical value

Look up F0.025(15,20)F_{0.025}(15, 20) in the F-table.

If your F-table does not have 0.025, you can interpolate between 0.05 and 0.01 or use an extended
F-table that includes 0.025.

Let’s say the table gives:

 F0.025(15,20)=2.57F_{0.025}(15, 20) = 2.57 ← (example value from full F-tables)

This is your upper critical value.

🔹 Step 2: Find the lower critical value

Since F-distribution is not symmetric, we invert the upper-tail critical value for swapped degrees of
freedom:

Flower=1F0.025(20,15)F_{\text{lower}} = \frac{1}{F_{0.025}(20, 15)}

So from the F-table:

 Find F0.025(20,15)F_{0.025}(20, 15) → suppose it's 2.90

Then:

Flower=12.90≈0.345F_{\text{lower}} = \frac{1}{2.90} ≈ 0.345

✅ Final Result

Value Formula Result

Upper Critical F0.025(15,20)F_{0.025}(15, 20) 2.57

Lower Critical 1F0.025(20,15)\frac{1}{F_{0.025}(20, 15)} ≈ 0.345

If your computed F-value falls outside this range (i.e., < 0.345 or > 2.57), then you reject H0H_0.

❓ Don’t Have 0.025 Column in Your Table?

If your F-table has only 0.05 and 0.01 columns:

 Interpolate between F0.05F_{0.05} and F0.01F_{0.01}

 Or approximate by averaging if it's close

 Or use online full tables like:


https://www.sjsu.edu/faculty/gerstman/StatPrimer/t-table.pdf (for t)
https://www.socscistatistics.com/pvalues/fdistribution.aspx (for F)

Would you like me to show an interpolation example for a missing F0.025F_{0.025} value?
Awesome! Let's dive into ANOVA (Analysis of Variance) — a powerful statistical method used when
you want to compare three or more group means.

🔷 What is ANOVA?

ANOVA helps determine whether the differences between group means are statistically significant.

🔍 Purpose: Test if at least one group mean is different from the others.

🧪 When to Use ANOVA?

 Comparing 3 or more groups

 Dependent variable is continuous (e.g., weight, score)

 Independent variable is categorical (e.g., teaching method, treatment type)

 Groups are independent

 Variances are approximately equal


complete worked-out example of One-Way ANOVA using the fertilizer and plant growth scenario.
Awesome! Let’s now dive into Two-Way ANOVA, which extends One-Way ANOVA by evaluating two
independent categorical variables (factors) and their interaction effect on a continuous dependent
variable.
🔍 What is Two-Way ANOVA?

Two-Way ANOVA (also called Factorial ANOVA) helps you understand:

1. The main effect of each factor.

2. The interaction effect between the factors.

✅ When to Use Two-Way ANOVA

 You have two independent categorical variables (factors).

 Your dependent variable is continuous.

 You're interested in:

o The effect of each factor individually (main effects).

o Whether the two factors interact to influence the outcome.

Here:

 Factor 1: Fertilizer (A, B)

 Factor 2: Sunlight (Low, Medium, High)

 Dependent variable: Plant Growth


🧮 Two-Way ANOVA Tests

We test three null hypotheses:

1. H₀₁ (Main Effect of Fertilizer): Fertilizer type has no effect.

2. H₀₂ (Main Effect of Sunlight): Sunlight level has no effect.

3. H₀₃ (Interaction Effect): There is no interaction between fertilizer and sunlight.

🧠 Assumptions

 The observations are independent.

 The data in each group is normally distributed.

 Homogeneity of variances across groups.

✅ Decision Rule

Compare each F-value to the critical F-value or use p-values:

 If p-value < α (e.g., 0.05), reject H₀.

 Interpret main effects and interaction based on significance.

Great! Let’s dive into the Chi-Square (χ²) Test, which is used for categorical data rather than
numerical data (unlike Z, t, and F tests).

🧪 What is the Chi-Square Test?

It helps us test how likely it is that an observed distribution is due to chance.


There are two main types:
🔹 1. Chi-Square Test of Independence

✅ Purpose: Tests whether two categorical variables are independent or associated.

🔍 Step-by-Step

Step 1: State hypotheses

 H₀: Gender and product preference are independent

 H₁: Gender and product preference are associated


🔹 2. Chi-Square Goodness-of-Fit Test

📊 Scenario Recap: Checking if a die is fair, i.e., all outcomes are equally likely.

✅ Null Hypothesis (H₀):

The die is fair, meaning each face (1–6) has an equal probability of 1/6.

Or in general:

The observed distribution matches the expected distribution.


✅ Alternative Hypothesis (H₁):

The die is not fair, i.e., at least one outcome appears more or less often than expected.

https://www.scribbr.com/statistics/chi-square-distribution-table/

Awesome question! Understanding how Z-test, t-test, F-test, ANOVA, and Chi-Square fit into
machine learning (ML) and data science gives you superpowers for feature selection, data
validation, and model building.

Let’s break it down by test:

🔍 Z-test and t-test in Machine Learning

✅ Use Case: Hypothesis Testing & Feature Selection

📌 Example Scenarios:

 You're testing if a numerical feature has significantly different means across two groups (e.g.,
churned vs. not churned).

 You’re evaluating A/B test results for performance metrics.

🔹 When to Use:

Test Use When...

Z-test Population standard deviation is known (rare in ML)

t-test Sample sizes are small or std dev is unknown (common in ML)

⚙️ML Integration:
 Binary classification: Use t-test to check if features differ between the two classes.

 A/B testing: Validate which version performs better.

 Feature selection: Keep only features with significant differences between groups.

🔍 F-test and ANOVA in Machine Learning

✅ Use Case: Comparing Variance & Feature Importance

🔹 F-test (used inside ANOVA or model metrics)

 Checks if two or more population variances are significantly different.

 Used internally in:

o Linear regression (to test overall model significance)

o Ridge/Lasso regression for checking coefficients

o Feature selection (e.g., f_classif in sklearn.feature_selection)

🔹 ANOVA (Analysis of Variance)

📌 Example:

You want to see if the average purchase amount differs across 3 customer segments (A, B, C).

⚙️ML Integration:

 Multiclass classification: ANOVA F-test helps check if features differ significantly across
classes.

 Feature selection: Use SelectKBest with f_classif to pick top features.

🔍 Chi-Square Test in Machine Learning

✅ Use Case: Categorical Feature Selection

🔹 Chi-Square Test of Independence

📌 Example:

 You want to check if a categorical feature (like "Gender") is related to the target variable
(like "Buy or Not").

⚙️ML Integration:
 Classification: Test if input features are independent from the output.

 Feature selection: Use chi2 in sklearn.feature_selection to keep categorical features that


matter.

Degrees of freedom refer to the maximum number of logically independent values, which may vary
in a data sample. Degrees of freedom are calculated by subtracting one from the number of items
within the data sample.

Degrees of freedom are the maximum number of logically independent values, which may vary in a
data sample. Suppose we have two choices of shirt to wear at a party then the degree of freedom is
one, now suppose we have to again go to the party and we can not repeat the shirt then the choice
of shirt we are left with is One then in this case the degree of freedom is zero as we do not have any
choice to choose on the last day.

Degree of freedom formula is shown in the image s

hown below. In the image, N is total number of options available to us then degree of freedom is N –
1.

https://www.geeksforgeeks.org/degrees-of-freedom/

You might also like