Skip to main content
Hypothesis testing is a statistical method used to determine whether there is enough evidence from sample data to support a claim about a population.

Table of Contents

  • Null & Alternative Hypotheses
  • Hypothesis Testing Workflow
  • One-sample t-test
  • Two-sample t-test
  • p-value
  • Significance Level (α)
  • Type I & Type II Errors
  • Confidence Intervals
  • Choosing the Correct Test
  • Complete Python Examples
  • Interview Questions
  • Summary

1. Null & Alternative Hypotheses

A hypothesis is an assumption about a population parameter. There are always two hypotheses.

Null Hypothesis (H₀)

The null hypothesis assumes no effect, no difference, or no relationship. Examples:
  • Average salary = ₹50,000
  • New medicine is not better than old medicine.
  • Two algorithms have equal accuracy.
Example:
where
  • μ = population mean

Alternative Hypothesis (H₁ or Hₐ)

The alternative hypothesis represents what we want to prove. Examples
or
or

Types of Alternative Hypotheses

Two-tailed

Testing for any difference.

Right-tailed

Testing if value is greater.

Left-tailed

Testing if value is smaller.

Hypothesis Testing Workflow


2. One-Sample t-test

Used when comparing one sample mean against a known population value.

Example

A company claims average battery life is 10 hours. Sample:
Question: Is the actual average different from 10?

Formula

t=fracbarxmus/sqrtnt = \\frac{\\bar{x}-\\mu}{s/\\sqrt{n}} where
  • x̄ = sample mean
  • μ = population mean
  • s = sample standard deviation
  • n = sample size

Python Example


Interpretation

If
Reject H₀ Otherwise Fail to reject H₀.

3. Two-Sample t-test

Used to compare means of two independent groups. Example Do students using Method A score differently than students using Method B?
Sample Method A
Method B

Python


Equal Variance Assumption

If variances are unequal
This performs Welch’s t-test.

Difference Between One-Sample and Two-Sample t-test


4. p-value

The p-value measures how likely the observed data would occur if the null hypothesis were true. It is not the probability that the null hypothesis is true.

Interpretation


Example
Since
Reject H₀.
Another Example
Cannot reject H₀.

5. Significance Level (α)

The significance level is the threshold for deciding whether to reject the null hypothesis. Common choices
Most commonly
Meaning Accept a 5% chance of incorrectly rejecting a true null hypothesis.
Decision Rule
Otherwise

6. Type I & Type II Errors

Type I Error (False Positive)

Rejecting a true null hypothesis. Reality:
Conclusion:
Wrong conclusion. Probability

Type II Error (False Negative)

Failing to reject a false null hypothesis. Reality
Conclusion
Probability

Statistical Power

Power
Higher power means a better chance of detecting a true effect.

Error Table


7. Confidence Intervals

A confidence interval gives a range where the true population parameter is likely to lie. Example
Interpretation: Using this method repeatedly, about 95% of the intervals constructed would contain the true population mean.

Formula

Where:
  • = Sample mean
  • t* = Critical t-value (depends on confidence level and degrees of freedom)
  • s = Sample standard deviation
  • n = Sample size

Python Example


Interpretation

If the confidence interval contains the hypothesized value
Since
Fail to reject H₀ at the 5% significance level.

Choosing the Correct Test


Complete Python Example


Interview Questions

What is the null hypothesis?

A statement that assumes there is no difference or no effect.

What does a p-value represent?

The probability of observing results at least as extreme as those obtained if the null hypothesis is true.

Why use a t-test?

To compare means when the population standard deviation is unknown.

Difference between α and p-value?

  • α is chosen before the experiment (decision threshold).
  • p-value is computed from the observed sample data.

What is a 95% confidence interval?

An interval produced by a method that, over many repeated samples, would contain the true population parameter about 95% of the time.

Summary


Key Takeaways

  • Start by defining H₀ and H₁.
  • Choose the correct statistical test based on the data.
  • Compare the p-value with α to make a decision.
  • Understand the risks of Type I and Type II errors.
  • Use confidence intervals to estimate plausible values for the population parameter.
  • Report both the test result and the confidence interval for a more complete statistical interpretation.