1|P ag e
mR. M. MOHSIN
2|P ag e
In data analytics, hypothesis testing is used to test a claim and decide
whether there is a significant relationship between independent and
dependent variables. It helps determine if the independent variable has a
real effect on the dependent variable or if the result is due to chance. A
hypothesis is a scientific and testable prediction related to a research
problem. It must be measurable and is tested using statistical methods to
decide whether to accept or reject it. The main purpose is to check whether
there is a true effect or difference between variables.
3|P ag e
Purpose Test Example
1 mean compare t-test
Boys vs girls average marks
Pure vs processed milk fat
2 means compare Independent t-test
level
3 types of fertilizers and
3+ means compare ANOVA
yield
Proportion compare Z-test COVID vaccine success rate
Association Chi-square Gender vs purchase decision
Correlation Pearson/Spearman Height vs Weight
Study hours → marks
Regression Linear Regression
prediction
THE t-TEST FAMILY
The t-test is a parametric inferential test used to compare means when the
population standard deviation (σ) is unknown and must be estimated from the
sample. It uses the t-distribution with df n-1, which is wider and heavier-
tailed than the normal distribution especially for small samples because it
accounts for the extra uncertainty of estimating σ. As sample size increases,
the t-distribution converges toward the standard normal (z) distribution.
The t-test is robust for small sample sizes and is appropriate when dealing
with less than 30 samples or when the population standard deviation is
unknown
Assumptions / Properties of T-test
• Data is continuous
• Data is normally distributed
• Independent or paired (depends on test)
• Small sample size
• Population variance unknown
4|P ag e
1. ONE-SAMPLE t-TEST
• Mostly used then one group vs. a fixed known value
• You have ONE group and want to compare it to a fixed reference (national norm,
government standard, theoretical value)
• Population SD is unknown, Data is approximately normal OR n ≥ 30
SPSS: How to Run
Analyze → Compare Means → One-Sample T Test → Enter variable → Test Value = 3.30
→ OK
A professor at a Superior University wants to determine whether the mean CGPA of 40 MS
students (3.45) is significantly different from the HEC national average of 3.30.
How to Interpret
• t = 2.953 → The sample mean is 2.953 standard errors above the test value. Large
deviation.
• df = 39 → n − 1 = 40 − 1 = 39
• Sig. = 0.005 → p = .005 < α (.05) → REJECT H₀. Significant difference exists.
• Mean Diff = 0.150 → Students' CGPA is 0.15 points above national average.
• 95% CI [0.047, 0.253] → True difference is between 0.047 and 0.253. Zero is excluded
→ confirms significance.
Interpretation the results
A one-sample t-test revealed that the mean CGPA of MS students (M = 3.45, SD = 0.32) was
significantly higher than the national HEC average of 3.30, t(39) = 2.95, p = .005, d = 0.47
(medium effect). The 95% CI [0.05, 0.25] did not include zero.
5|P ag e
2. INDEPENDENT SAMPLES t-TEST
Compares the means of two separate, unrelated groups. Most widely used t-test with (df n1+n2+1)
in social science research. "Independent" means different people in each group.
When to Use
• Two independent groups (male vs. female, treatment vs. control, school A vs. school B)
• DV is interval/ratio scale
• Each group approximately normal OR n ≥ 30 each
• Check for equal/unequal variances with Levene's Test
Critical Step Levene's Test for Equality of Variances
Before reading your t-result, SPSS runs Levene's test automatically:
Levene's Result Meaning Which Row to Read
p > .05 (non- Variances are EQUAL Row 1: "Equal variances assumed"
significant) (Student's t)
p ≤ .05 (significant) Variances are NOT Row 2: "Equal variances not assumed"
equal (Welch's t)
Researcher compares exam scores: Cooperative Learning (n=45, M=78.3, SD=9.2) vs.
Traditional Lecture (n=42, M=71.6, SD=11.4) H₀: μ₁ = μ₂ | H₁: μ₁ ≠ μ₂ | α = 0.05, two-tailed
SPSS: How to Run
Analyze → Compare Means → Independent-Samples T Test → Test Variable: Score →
Grouping Variable: Method → Define Groups (1,2) → OK
6|P ag e
How to Interpret — Step by Step
1. Levene's F = 2.341, p = .129 → p > .05 → Variances are equal → Read top row
2. t = 3.210 → Group 1 scores are 3.21 SEs above Group 2. Large deviation from H₀.
3. df = 85 → (n₁−1)+(n₂−1) = 44+41 = 85
4. Sig. = .002 → p = .002 < α = .05 → REJECT H₀. Groups differ significantly.
5. Mean Diff = 6.700 → Cooperative learning students scored 6.7 points higher on average.
6. 95% CI [2.549, 10.851] → True difference is between 2.5 and 10.9 points. Zero excluded
→ significant.
7. Effect Size: Cohen's d ≈ 0.64 → Medium-to-large effect.
Students taught via cooperative learning (M = 78.30, SD = 9.20) scored significantly higher
than those taught via traditional lecture (M = 71.60, SD = 11.40), t(85) = 3.21, p = .002, d =
0.64. The 95% CI [2.55, 10.85] confirmed the significance of the 6.7-point difference.
3. PAIRED SAMPLES t-TEST (Dependent t-Test)
Compares two related measurements from the same participants (before/after, pre/post). Each
person is their own control removes individual difference variability, greatly increasing power.
Used when Same group, measured twice
When to Use
• Same participants measured TWICE (pre-test/post-test design)
• OR matched pairs (one from each pair per condition)
• The differences between pairs are approximately normally distributed
Clinical researcher measures systolic blood pressure (mmHg) of 30 hypertensive patients
before and after a 6-week mindfulness program. Pre mean = 148.6 mmHg | Post mean = 139.2
mmHg | Mean diff = −9.4 H₀: μ(diff) = 0 | H₁: μ(diff) ≠ 0 | α = 0.05
7|P ag e
Analyze → Compare Means → Paired-Samples T Test → Select both variables as a pair
How to Interpret
• Correlation r = .812, p < .001 → Pre and post scores are highly correlated → paired
design was appropriate
• Mean Difference = 9.400 → BP dropped by 9.4 mmHg on average
• t = 8.288 → Mean difference is 8.3 standard errors from zero. Extremely large.
• df = 29 → n − 1 = 29
• Sig. < .001 → Strongly REJECT H₀
• 95% CI [7.078, 11.722] → BP reduction between 7.1 and 11.7 mmHg. Zero far
outside interval.
• Cohen's d = 9.40 / 6.21 = 1.51 → VERY LARGE effect
conclude
A paired samples t-test demonstrated a statistically significant reduction in systolic blood
pressure following the mindfulness program (Mpre = 148.60; Mpost = 139.20), t(29) = 8.29, p
< .001, d = 1.51 (very large). Mean reduction = 9.40 mmHg, 95% CI [7.08, 11.72].
8|P ag e
4. WELCH'S t-TEST (Advanced — Unequal Variances)
Student's original t-test assumes equal population variances in both groups. When this is violated
(Levene's test significant), Student's t inflates Type I error. Welch's t-test corrects for this by
adjusting both the test statistic and the df using the Welch-Satterthwaite equation.
Modern recommendation: Many statisticians now suggest always using Welch's t as the
default, since it works well whether variances are equal or not.
Real-Life Example
HR researcher compares salaries: Engineers (n=25, M=85,000 PKR, SD=12,000) vs. Admin
staff (n=60, M=42,000 PKR, SD=28,000) Very different SDs signal unequal variances. Levene's:
F=18.4, p<.001 → Use Welch's t SPSS output row "Equal variances NOT assumed": t(56.3) =
9.21, p < .001
9|P ag e
THE z-TEST FAMILY
A Z-test is a statistical test used to determine whether there is a significant difference between
sample and population means, or between the means of two samples. Z-tests are used to test
hypotheses about population means or proportions. They help infer whether observed differences
are statistically significant or due to random chance. Use a Z-test when the population standard
deviation (σ) is known.
• The population standard deviation (σ) is known, OR
• The sample size is large (n ≥ 30) so the sample SD reliably estimates σ
The z-test uses the standard normal distribution (z-distribution) instead of the t-distribution. It is
appropriate when:
The Z-test is more appropriate for large sample sizes (typically n > 30), where the Central Limit
Theorem ensures that sample means are normally distributed.
The Z-test is suitable for analyzing continuous numerical data, such
as heights, weights, test scores, etc.
Feature t-Test z-Test
Distribution t-distribution (wider) Standard normal (z)
σ (population SD) Unknown estimated from sample Known, or n ≥ 30
Sample size Any n Typically n ≥ 30
DF Yes (df = n−1 etc.) No fixed standard normal
SPSS support Full built-in Limited often calculated manually
10 | P a g e
Critical z-Values to Memorize
Test Type α = 0.05 α = 0.01 α = 0.10
Two-tailed ±1.96 ±2.576 ±1.645
One-tailed (upper) +1.645 +2.326 +1.282
One-tailed (lower) −1.645 −2.326 −1.282
ONE-SAMPLE z-TEST
Compares the mean of one large sample to a known population mean (μ₀), using the known
σ.
A principal claims his students have above average IQ.A sample of 30 students and mean
112.5. The mean population IQ is 100 with standard deviations of 15. Do hypothesis testing
for the claim
To test the principal's claim that his students have above-average IQs, we can perform a one-
sample z-test because we know the population standard deviation. Here's the step-by-step
process:
Another Example
A factory produces bolts with known σ = 0.5 mm. Target diameter μ₀ = 10 mm. Inspector
samples n = 64 bolts: x̄ = 10.15 mm. H₀: μ = 10 | H₁: μ ≠ 10 | α = 0.05
Calculation: z = (10.15 − 10) / (0.5/√64) = 0.15 / 0.0625 = 2.40
Since |z| = 2.40 > critical value 1.96 → REJECT H₀ Conclusion: Bolt diameter deviates
significantly from 10 mm. Production adjustment needed.
11 | P a g e
TWO-SAMPLE z-TEST
Compares means of two independent large samples (n ≥ 30 each, σ known or estimated).
Compare average BP of patients from Hospital A vs Hospital B
Sample size is large.
Example
Bank compares daily transactions: Lahore branch (n=80, x̄=145, σ=18) vs. Karachi (n=90,
x̄=138, σ=22) H₀: μ(Lahore) = μ(Karachi) | H₁: μ(Lahore) ≠ μ(Karachi) | α = 0.05
SE = √[(18²/80) + (22²/90)] = √[4.05 + 5.38] = √9.43 = 3.07 z = (145 − 138) / 3.07 = 7 / 3.07 =
2.28
Since |z| = 2.28 > 1.96 → REJECT H₀. Lahore branch processes significantly more transactions.
Z-test for Proportion
60% patients recover using a medicine (claimed).
Sample data is checked.
Tests whether a sample proportion (p̂) differs from a hypothesized
proportion (p₀), or whether two sample proportions differ. Used when data is
categorical (yes/no, pass/fail, vaccinated/not).
Conditions for Use
• Data is binary (two categories)
• For one sample: n × p₀ ≥ 5 AND n × (1−p₀) ≥ 5
• For two samples: all four cells ≥ 5
Example — One Sample
University pass rate for statistics course: 72% (p̂ = 0.72, n = 150). National benchmark: p₀ =
0.65. H₀: p = 0.65 | H₁: p > 0.65 | α = 0.05, one-tailed
z = (0.72 − 0.65) / √[0.65×0.35/150] = 0.07 / 0.0389 = 1.80
Critical z (one-tailed, α=0.05) = 1.645. Since 1.80 > 1.645 → REJECT H₀ University pass rate
is significantly higher than national benchmark.
12 | P a g e
Two-Sample Proportions
Vaccination rates: District A (320/500 = 0.64) vs. District B (280/500 = 0.56)
H₀: p₁ = p₂ | H₁: p₁ ≠ p₂ | α = 0.05
Pooled(p̂)=(320+280)/(500+500) = 0.60 z = (0.64−0.56) /
√[0.60×0.40×(1/500+1/500)] = 0.08 / 0.0310 = 2.58
Since |z| = 2.58 > 1.96 → REJECT H₀. Vaccination rates differ significantly.
13 | P a g e
14 | P a g e
Chi-Square test
The Chi-Square test is used to determine whether there is a significant association between two
categorical variables.
Example: Suppose we want to test if there is a significant association between gender
(male/female) and smoking status (smoker/non smoker) in a population.
We collect data and create a table showing the counts of males and females who are smokers and
non-smokers.
We then use the chi-square test to determine if there is a significant relationship between gender
and smoking status.
Oi = Observed value
Ei = Expected value
Goodness of
Feature Independence Homogeneity
Fit
Variables Two categorical One categorical One categorical
Groups One population One population Multiple populations
Purpose Relationship Match expected Compare distributions
Example Smoking vs Blood groups Gender across
Disease hospitals
Table Contingency table Frequency table Contingency table
type
ASSUMPTIONS / PROPERTIES OF CHI-SQUARE
Applies to all types:
• Data must be categorical
• Observations must be independent
• Expected frequency ≥ 5
15 | P a g e
• Sample size should be reasonably large
• Uses χ² distribution
Chi-Square Test:
A non-parametric test used to analyze categorical data.
Independence Test
Relationship between TWO variables. Tests association between two
categorical variables.
Goodness of Fit Test
Observed vs Expected. Tests whether observed frequencies match expected
frequencies.
Homogeneity
Same variable, different groups. In spss Independence and Homogeneity use
same procedure
Ques: Let us have data about marital status and education, means as
“Never married, Married, Divorced, Widowed” and “Primary School,
High School, Grad, Master, Ph.D.”.
Null: There is no relation between marital status and Education.
16 | P a g e
Alternate: There is significant relation between marital status and
Education.
Significance Level = 0.05
Confidence level: 95%
Table of expected value
17 | P a g e
18 | P a g e
19 | P a g e
Errors
Any false decision related to null hypothesis is consider as error.
As our confidence level will never be 100% so there is always scope of error.
Like if CL is 95% than there is a possibility that out of 100 there may be 5
times we can make wrong inferences about null hypothesis.
Type I error(alpha) it's a false alarm or a false positive result when we
conclude that there is a significant effect or difference while actually there isn't
one in reality.
Type II error (beta) It's a miss or a false negative result where we fail to
detect a significant effect or difference when it actually exists.
20 | P a g e
There is often a trade-off between Type I and Type II errors.
Lowering the significance level (α) to reduce Type I errors can
increase the likelihood of Type II errors and vice versa.
Power of a test is the probability of correctly rejecting a false
null hypothesis (1 - β).
Higher power means lower chances of Type II errors
21 | P a g e