PROJECTENGRAM

INFERENCE FOR CATEGORICAL DATA

Tags: #◇CSMODEL #◇Inference for Categorical Data #◇Computer Science #◇Data Science #◇Statistical Modeling #◇Python #◇Machine Learning


Module 09: Inference for Categorical Data

◇Key Concepts

1. Introduction to Categorical Data Inference

In statistical modeling and data science, categorical data consists of variables representing qualitative categories rather than numerical measurements (e.g., survey agreement, political affiliation, health status, race, or success/failure outcomes).

While numerical data is analyzed using inference on means (μ\mu) and standard deviations (σ\sigma), categorical data requires inference based on proportions (pp) and frequencies/counts (OiO_i).

Categorical inference is categorized based on the number of variables and categories involved:

  1. One Proportion: Testing or estimating the population proportion pp for a single binary variable (H0:p=p0H_0: p = p_0).
  2. Two Proportions: Comparing population proportions across two independent groups (H0:p1=p2H_0: p_1 = p_2).
  3. Goodness-of-Fit (Single Variable, k>2k > 2 Categories): Comparing observed sample frequencies across kk categories to a theoretical or historical population distribution.
  4. Test of Independence (Two Variables, r×cr \times c Contingency Table): Evaluating whether two categorical variables are independent or statistically associated.

2. Inference for a Single Proportion (One-Proportion z-Test)

Concept & Hypotheses

The One-Proportion z-Test assesses whether a population proportion pp equals a hypothesized baseline proportion p0p_0.
Null Hypothesis (H0H_0): p=p0p = p_0 (The true population proportion is equal to the hypothesized value p0p_0). Alternative Hypothesis (HAH_A):
Two-tailed: p≠p0p \neq p_0
One-tailed: p>p0p > p_0 or p<p0p < p_0

Sample Proportion & Standard Error

Given a sample of size nn with xx observed successes:
p^=xn\hat{p} = \frac{x}{n}

Under H0H_0, the sampling distribution of p^\hat{p} is centered at p0p_0 with standard error:
SE0=p0(1−p0)nSE_0 = \sqrt{\frac{p_0(1 - p_0)}{n}}

Test Statistic

z=p^−p0SE0=p^−p0p0(1−p0)nz = \frac{\hat{p} - p_0}{SE_0} = \frac{\hat{p} - p_0}{\sqrt{\frac{p_0(1 - p_0)}{n}}}

Confidence Interval for a Proportion

To construct a (1−α)×100%(1-\alpha) \times 100\% confidence interval for pp, we use the sample proportion p^\hat{p} for standard error estimation:
CI=p^±z∗⋅SEp^=p^±z∗⋅p^(1−p^)nCI = \hat{p} \pm z^* \cdot SE_{\hat{p}} = \hat{p} \pm z^* \cdot \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}
where z∗z^* is the critical value from the standard normal distribution (e.g., z∗=1.96z^* = 1.96 for 95%95\% confidence).

Relationship Between pp and Margin of Error (ME)

The Margin of Error ME=z∗p(1−p)nME = z^* \sqrt{\frac{p(1-p)}{n}} varies depending on pp: Maximum ME: Achieved when p=0.5p = 0.5. (Worst-case scenario; used when planning sample size without prior knowledge of pp). Minimum ME: Achieved when pp approaches 00 or 11.

Conditions for One-Proportion z-Test & CI

  1. Independence: The sample observations must be independent.
    Random sampling / random assignment.
    10%10\% Condition: If sampling without replacement, sample size n≤10%n \le 10\% of the total population.
  2. Success-Failure Condition:
    For Hypothesis Testing: Expected successes np0≥10n p_0 \ge 10 AND expected failures n(1−p0)≥10n (1 - p_0) \ge 10.
    For Confidence Intervals: Observed successes np^≥10n \hat{p} \ge 10 AND observed failures n(1−p^)≥10n (1 - \hat{p}) \ge 10.

3. Inference for Two Proportions (Two-Proportion z-Test)

Concept & Hypotheses

The Two-Proportion z-Test compares the proportions of two independent populations (p1p_1 and p2p_2).
Null Hypothesis (H0H_0): p1−p2=0  ⟺  p1=p2p_1 - p_2 = 0 \iff p_1 = p_2 (There is no difference between the two population proportions). Alternative Hypothesis (HAH_A): p1−p2≠0p_1 - p_2 \neq 0 (or p1>p2p_1 > p_2, p1<p2p_1 < p_2).

Pooled Proportion (p^pool\hat{p}_{\text{pool}})

Under H0H_0, we assume p1=p2=pp_1 = p_2 = p. The best estimate of this common proportion pp is obtained by pooling the successes and sample sizes from both groups:
p^pool=x1+x2n1+n2=n1p^1+n2p^2n1+n2\hat{p}_{\text{pool}} = \frac{x_1 + x_2}{n_1 + n_2} = \frac{n_1 \hat{p}_1 + n_2 \hat{p}_2}{n_1 + n_2}

Standard Error & Test Statistic

The pooled standard error for the difference (p^1−p^2)(\hat{p}_1 - \hat{p}_2) under H0H_0 is:
SEpool=p^pool(1−p^pool)(1n1+1n2)SE_{\text{pool}} = \sqrt{\hat{p}_{\text{pool}}(1 - \hat{p}_{\text{pool}}) \left( \frac{1}{n_1} + \frac{1}{n_2} \right)}

The z-test statistic is:
z=p^1−p^2p^pool(1−p^pool)(1n1+1n2)z = \frac{\hat{p}_1 - \hat{p}_2}{\sqrt{\hat{p}_{\text{pool}}(1 - \hat{p}_{\text{pool}}) \left( \frac{1}{n_1} + \frac{1}{n_2} \right)}}

Conditions for Two-Proportion z-Test

  1. Independence: Within each group and between the two groups (independent random samples).
  2. Success-Failure Condition: Expected successes and failures in BOTH groups under p^pool\hat{p}_{\text{pool}} must be at least 10:
    n1p^pool≥10,n1(1−p^pool)≥10,n2p^pool≥10,n2(1−p^pool)≥10n_1 \hat{p}_{\text{pool}} \ge 10, \quad n_1 (1 - \hat{p}_{\text{pool}}) \ge 10, \quad n_2 \hat{p}_{\text{pool}} \ge 10, \quad n_2 (1 - \hat{p}_{\text{pool}}) \ge 10

4. Chi-Square (χ2\chi^2) Goodness-of-Fit Test

Concept & Hypotheses

The Chi-Square Goodness-of-Fit Test determines whether an observed categorical frequency distribution across kk categories (k≥2k \ge 2) matches an expected theoretical or baseline population distribution.
Null Hypothesis (H0H_0): The sample distribution follows the specified population distribution (there is no difference between observed and expected proportions). Alternative Hypothesis (HAH_A): The sample distribution does NOT follow the specified population distribution (at least one category proportion differs).

Expected Frequencies (EiE_i)

Given total sample size nn and hypothesized category probabilities p1,p2,…,pkp_1, p_2, \dots, p_k:
Ei=n⋅pifor i=1,2,…,kE_i = n \cdot p_i \quad \text{for } i = 1, 2, \dots, k
Note that ∑i=1kOi=∑i=1kEi=n\sum_{i=1}^k O_i = \sum_{i=1}^k E_i = n.

Test Statistic

The Chi-Square statistic measures the aggregate normalized squared deviation of observed frequencies (OiO_i) from expected frequencies (EiE_i):
χ2=∑i=1k(Oi−Ei)2Ei\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}
χ2≥0\chi^2 \ge 0 always. If Oi=EiO_i = E_i for all ii, χ2=0\chi^2 = 0 (perfect fit). Larger values of χ2\chi^2 indicate greater discrepancy between sample data and H0H_0.

Degrees of Freedom (dfdf)

df=k−1df = k - 1
where kk is the number of categories/bins.

Conditions for Goodness-of-Fit Test

  1. Independence: Each observation in the sample must be independent of all other observations.
  2. Expected Cell Counts Condition: EVERY expected cell count must be at least 5 (Ei≥5E_i \ge 5 for all ii).

    Crucial Note: This condition applies to expected counts (EiE_i), NOT observed counts (OiO_i).


5. Chi-Square (χ2\chi^2) Test of Independence

Concept & Hypotheses

The Chi-Square Test of Independence evaluates whether two categorical variables measured on the same sample are independent of each other or statistically associated.
Null Hypothesis (H0H_0): Variable A and Variable B are independent (the outcome of one variable does not depend on the outcome of the other). Alternative Hypothesis (HAH_A): Variable A and Variable B are dependent / associated (the distribution of one variable differs across levels of the other).

Contingency Table (r×cr \times c)

Observations are summarized in a two-way contingency table with rr rows (categories of Variable A) and cc columns (categories of Variable B).

Expected Frequencies (Ei,jE_{i,j})

Under the null hypothesis of independence, P(Ai∩Bj)=P(Ai)×P(Bj)P(A_i \cap B_j) = P(A_i) \times P(B_j). The expected frequency for cell (i,j)(i, j) is:
Ei,j=(Row i Total)×(Column j Total)Grand Total (N)E_{i,j} = \frac{(\text{Row } i \text{ Total}) \times (\text{Column } j \text{ Total})}{\text{Grand Total } (N)}

Test Statistic & Degrees of Freedom

χ2=∑i=1r∑j=1c(Oi,j−Ei,j)2Ei,j\chi^2 = \sum_{i=1}^{r} \sum_{j=1}^{c} \frac{(O_{i,j} - E_{i,j})^2}{E_{i,j}}
df=(r−1)×(c−1)df = (r - 1) \times (c - 1)

Conditions for Test of Independence

  1. Independence: Sample observations are randomly selected and independent of one another.
  2. Expected Cell Counts Condition: EVERY expected cell count Ei,j≥5E_{i,j} \ge 5.

6. Interpreting Chi-Square Test Results

Right-Tailed Nature: Because discrepancies are squared, all non-zero terms are positive. Chi-Square tests are inherently one-sided (right-tailed). p-value: P(χdf2≥calculated χ2)P(\chi^2_{df} \ge \text{calculated } \chi^2). Decision Rule:
If p-value≤αp\text{-value} \le \alpha (e.g., 0.050.05): Reject H0H_0. Conclude there is statistically significant evidence of a difference or relationship.
If p-value>αp\text{-value} > \alpha: Fail to reject H0H_0 (or accept H0H_0). The sample data does not provide sufficient evidence to rule out chance variation.


◇Python Snippets

1. Contingency Tables with pd.crosstab()

Creates a frequency cross-tabulation of two categorical series from a pandas DataFrame.

『』
PYTHON
import pandas as pd

# Load dataset
cdc_df = pd.read_csv('cdcpartial.csv')

# Create a contingency table of exercise history vs general health status
counts = pd.crosstab(cdc_df['exerany'], cdc_df['genhlth'])

# Format into a clean DataFrame with custom row labels
table = pd.DataFrame([counts.loc[0], counts.loc[1]], index=['no exercise', 'exercise'])
print(table)

2. Chi-Square Test of Independence with scipy.stats.chi2_contingency()

Calculates the χ2\chi^2 statistic, p-value, degrees of freedom, and expected frequencies for a contingency table.

『』
PYTHON
from scipy.stats import chi2_contingency

# Perform Chi-Square Test of Independence
# Note: set correction=False to get standard Pearson chi-square without Yates' continuity correction
chi2_stat, p_val, dof, expected = chi2_contingency(table, correction=False)

print(f"Chi-Square Statistic : {chi2_stat:.4f}")
print(f"p-value              : {p_val:.4e}")
print(f"Degrees of Freedom   : {dof}")
print("Expected Frequencies :\n", expected)

# Statistical Decision
alpha = 0.05
if p_val < alpha:
    print("Reject H0: The two categorical variables are dependent.")
else:
    print("Fail to reject H0: The two categorical variables are independent.")

3. Chi-Square Goodness-of-Fit Test with scipy.stats.chisquare()

Tests whether observed category counts differ significantly from expected theoretical frequencies.

『』
PYTHON
from scipy.stats import chisquare

# Example: Juror race distribution vs expected counts based on voter registration
observed = [205, 26, 25, 19]          # Observed counts: White, Black, Hispanic, Other
expected = [198.0, 19.25, 33.0, 24.75] # Expected counts: Total (275) * voter %

# Perform Goodness-of-Fit test
gof_result = chisquare(f_obs=observed, f_exp=expected)

print(f"Goodness-of-Fit Chi2 Stat : {gof_result.statistic:.4f}")
print(f"p-value                   : {gof_result.pvalue:.4f}")

4. Proportion z-Tests with statsmodels.stats.proportion.proportions_ztest()

Handles both 1-proportion z-tests and 2-proportion z-tests.

『』
PYTHON
from statsmodels.stats.proportion import proportions_ztest

# --- ONE-PROPORTION z-TEST ---
# H0: p = 0.10 vs H1: p != 0.10
# Observed: 140 atheists in sample of 1000 respondents
count_1 = 140
nobs_1 = 1000
value_0 = 0.10

z_stat_1, p_val_1 = proportions_ztest(count=count_1, nobs=nobs_1, value=value_0, alternative='two-sided')
print(f"1-Prop z-statistic: {z_stat_1:.4f}, p-value: {p_val_1:.4f}")

# --- TWO-PROPORTION z-TEST ---
# Group 1 (Smokers): 150 had condition out of 500
# Group 2 (Non-Smokers): 180 had condition out of 700
counts_2 = [150, 180]
nobs_2 = [500, 700]

z_stat_2, p_val_2 = proportions_ztest(count=counts_2, nobs=nobs_2, alternative='two-sided')
print(f"2-Prop z-statistic: {z_stat_2:.4f}, p-value: {p_val_2:.4f}")

5. Computing Sample Proportion Confidence Intervals & Margin of Error

Calculates the point estimate, standard error, margin of error, and confidence interval bounds in Python.

『』
PYTHON
import numpy as np
from scipy.stats import norm

# Sample statistics from Atheism survey (US 2012 sample)
n = 1002
atheist_count = 50
atheist_prop = atheist_count / n

# 95% Confidence Interval Calculation
confidence_level = 0.95
z_crit = norm.ppf(1 - (1 - confidence_level) / 2) # approx 1.96

# Standard Error and Margin of Error
se = np.sqrt(atheist_prop * (1 - atheist_prop) / n)
margin_of_error = z_crit * se

minimum_value = atheist_prop - margin_of_error
maximum_value = atheist_prop + margin_of_error

print(f"Sample Proportion : {atheist_prop * 100:.4f}%")
print(f"Margin of Error   : {margin_of_error * 100:.4f}%")
print(f"95% CI            : ({minimum_value * 100:.4f}%, {maximum_value * 100:.4f}%)")

◇Formulas & Key Equations

Formula / MetricMathematical ExpressionKey Context / Notes
Sample Proportionp^=xn\hat{p} = \frac{x}{n}Ratio of observed successes xx to sample size nn.
1-Prop Hypothesis Test SESE0=p0(1−p0)nSE_0 = \sqrt{\frac{p_0(1-p_0)}{n}}Uses hypothesized value p0p_0 under H0H_0.
1-Prop Confidence Interval SESEp^=p^(1−p^)nSE_{\hat{p}} = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}Uses sample proportion p^\hat{p}.
1-Prop z-Test Statisticz=p^−p0p0(1−p0)nz = \frac{\hat{p} - p_0}{\sqrt{\frac{p_0(1-p_0)}{n}}}Tests H0:p=p0H_0: p = p_0.
Proportion Margin of ErrorME=z∗p^(1−p^)nME = z^* \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}Maximized when p^=0.5\hat{p} = 0.5.
Pooled Proportion (2-Prop)p^pool=x1+x2n1+n2\hat{p}_{\text{pool}} = \frac{x_1 + x_2}{n_1 + n_2}Combines successes under H0:p1=p2H_0: p_1 = p_2.
2-Prop z-Test Statisticz=p^1−p^2p^pool(1−p^pool)(1n1+1n2)z = \frac{\hat{p}_1 - \hat{p}_2}{\sqrt{\hat{p}_{\text{pool}}(1-\hat{p}_{\text{pool}})\left(\frac{1}{n_1} + \frac{1}{n_2}\right)}}Compares two independent proportions.
Chi-Square Expected Cell Count (GOF)Ei=n⋅piE_i = n \cdot p_inn = sample size, pip_i = theoretical probability.
Chi-Square Expected Cell Count (Independence)Ei,j=(Row i Total)×(Col j Total)NE_{i,j} = \frac{(\text{Row } i \text{ Total}) \times (\text{Col } j \text{ Total})}{N}Calculated for each cell in an r×cr \times c table.
Chi-Square Statistic (χ2\chi^2)χ2=∑(O−E)2E\chi^2 = \sum \frac{(O - E)^2}{E}Aggregate normalized squared deviation.
Degrees of Freedom (GOF)df=k−1df = k - 1kk = number of categories.
Degrees of Freedom (Independence)df=(r−1)(c−1)df = (r - 1)(c - 1)rr = number of rows, cc = number of columns.

◇Common Exam Traps

  1. Checking E≥5E \ge 5 on Observed Counts instead of Expected Counts:
    Wrong: Rejecting a Chi-Square test because an observed cell count is Oij=2O_{ij} = 2.
    Correct: The condition requires EXPECTED counts (Eij≥5E_{ij} \ge 5). It is completely fine if observed counts OijO_{ij} are small or even 00, as long as all Eij≥5E_{ij} \ge 5.

  2. Standard Error Formula: p0p_0 vs p^\hat{p} Confusion:
    Wrong: Using p^\hat{p} in the SE denominator when calculating the 1-proportion z-test statistic.
    Correct:
    For Hypothesis Testing (zz-test), use p0p_0: SE=p0(1−p0)nSE = \sqrt{\frac{p_0(1-p_0)}{n}}.
    For Confidence Intervals (CICI), use p^\hat{p}: SE=p^(1−p^)nSE = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}.

  3. Degrees of Freedom Miscalculation in Contingency Tables:
    Wrong: Setting df=(r×c)−1df = (r \times c) - 1 for a Test of Independence.
    Correct: For a Test of Independence, df=(r−1)(c−1)df = (r - 1)(c - 1). For Goodness-of-Fit, df=k−1df = k - 1.

  4. Yates' Continuity Correction in Python (chi2_contingency):
    Wrong: Expecting scipy.stats.chi2_contingency(table) to equal hand calculations when analyzing a 2×22 \times 2 table without checking parameters.
    Correct: By default, SciPy applies Yates' continuity correction (correction=True) for 2×22 \times 2 tables, which shrinks χ2\chi^2. Set correction=False to reproduce exact Pearson hand calculations on exams.

  5. Assuming Chi-Square Tests are Two-Tailed:
    Wrong: Splitting α\alpha into two tails (α/2\alpha/2) for a Chi-Square p-value.
    Correct: Chi-Square tests are always right-tailed because squared terms (O−E)2(O-E)^2 enforce χ2≥0\chi^2 \ge 0. Any deviation from H0H_0 pushes χ2\chi^2 further into the upper tail.

  6. Maximum Margin of Error Misinterpretation:
    Wrong: Thinking Margin of Error is highest when sample proportion is close to 00 or 11.
    Correct: Margin of Error ME=z∗p(1−p)nME = z^* \sqrt{\frac{p(1-p)}{n}} is maximized at p=0.5p = 0.5 and shrinks as p→0p \to 0 or p→1p \to 1.


◇Practice Questions

Q1. A Computer Science department wants to test if students are equally distributed across 4 elective tracks: Data Science (DS), Software Technology (ST), Network & Security (NS), and Interactive Media (IM). In a random sample of N=200N = 200 students, the observed counts are: DS: 6565 ST: 5555 NS: 4545 IM: 3535

Calculate the Chi-Square statistic χ2\chi^2 and state the degrees of freedom dfdf. At a significance level of α=0.05\alpha = 0.05 (critical value χ0.05,32=7.815\chi^2_{0.05, 3} = 7.815), what is the statistical conclusion? A) χ2=5.00,df=3\chi^2 = 5.00, df = 3; Fail to reject H0H_0 (distribution is equal). B) χ2=10.00,df=3\chi^2 = 10.00, df = 3; Reject H0H_0 (distribution is not equal). C) χ2=10.00,df=4\chi^2 = 10.00, df = 4; Reject H0H_0 (distribution is not equal). D) χ2=12.50,df=3\chi^2 = 12.50, df = 3; Reject H0H_0 (distribution is not equal).


Q2. A researcher surveys 200 university students to test whether major choice (Major A vs Major B) is independent of obtaining an internship (Interned vs Did Not Intern). The observed contingency table is:

MajorInternedDid Not InternTotal
Major A40406060100
Major B60604040100
Total100100200

What is the expected count EE for Major A students who Interned under H0H_0, and what is the Pearson Chi-Square test statistic χ2\chi^2? A) E=40.0,χ2=4.00E = 40.0, \chi^2 = 4.00 B) E=50.0,χ2=8.00E = 50.0, \chi^2 = 8.00 C) E=50.0,χ2=4.00E = 50.0, \chi^2 = 4.00 D) E=60.0,χ2=16.00E = 60.0, \chi^2 = 16.00


Q3. An e-commerce platform tests two website layouts (Layout 1 and Layout 2) to determine if there is a difference in conversion proportions. Layout 1: x1=120x_1 = 120 conversions out of n1=400n_1 = 400 visitors (p^1=0.30\hat{p}_1 = 0.30). Layout 2: x2=180x_2 = 180 conversions out of n2=600n_2 = 600 visitors (p^2=0.30\hat{p}_2 = 0.30).

What is the pooled sample proportion p^pool\hat{p}_{\text{pool}} and the calculated z-test statistic? A) p^pool=0.30,z=0.00\hat{p}_{\text{pool}} = 0.30, z = 0.00 B) p^pool=0.30,z=1.96\hat{p}_{\text{pool}} = 0.30, z = 1.96 C) p^pool=0.25,z=0.50\hat{p}_{\text{pool}} = 0.25, z = 0.50 D) p^pool=0.35,z=0.00\hat{p}_{\text{pool}} = 0.35, z = 0.00


Q4. Inspect the following Python code snippet:

『』
PYTHON
import pandas as pd
from scipy.stats import chi2_contingency

df_table = pd.DataFrame({
    'Pass': [85, 65],
    'Fail': [15, 35]
}, index=['Course_X', 'Course_Y'])

chi2, p_val, dof, expected = chi2_contingency(df_table, correction=False)
print(f"dof={dof}, exp_CourseX_Fail={expected[0,1]:.1f}")

What is the exact output printed by this script? A) dof=1, exp_CourseX_Fail=25.0 B) dof=2, exp_CourseX_Fail=25.0 C) dof=1, exp_CourseX_Fail=15.0 D) dof=4, exp_CourseX_Fail=50.0


Q5. A data analyst runs the following Python code to test if a coin is biased towards heads (H0:p=0.50H_0: p = 0.50 vs HA:p>0.50H_A: p > 0.50):

『』
PYTHON
from statsmodels.stats.proportion import proportions_ztest

# Observed 60 heads in 100 tosses
count = 60
nobs = 100
value = 0.50

z_stat, p_val = proportions_ztest(count=count, nobs=nobs, value=value, alternative='larger')
print(f"z={z_stat:.2f}")

Given that under H0H_0, SE0=0.5×0.5100=0.05SE_0 = \sqrt{\frac{0.5 \times 0.5}{100}} = 0.05, what exact value is printed for z? A) z=1.00 B) z=1.96 C) z=2.00 D) z=4.00


Q6. A statistical consultant is conducting a Chi-Square Test of Independence on a 3×43 \times 4 contingency table. Which of the following statements regarding test assumptions and degrees of freedom is TRUE? A) The degrees of freedom for this test is df=(3×4)−1=11df = (3 \times 4) - 1 = 11. B) Every observed cell count OijO_{ij} must be greater than or equal to 5. C) Every expected cell count EijE_{ij} must be greater than or equal to 5, and df=(3−1)(4−1)=6df = (3 - 1)(4 - 1) = 6. D) The Chi-Square test statistic can be negative if observed counts are less than expected counts.


Answer Key

Q1: B — χ2=10.00,df=3\chi^2 = 10.00, df = 3; Reject H0H_0
Step-by-step Solution:
Total sample N=200N = 200. Under equal distribution (H0H_0), expected probability for each of the k=4k = 4 tracks is pi=0.25p_i = 0.25.
Expected frequency for each track: Ei=200×0.25=50E_i = 200 \times 0.25 = 50.
Degrees of freedom: df=k−1=4−1=3df = k - 1 = 4 - 1 = 3.
Chi-Square components:
(65−50)250=22550=4.50\frac{(65-50)^2}{50} = \frac{225}{50} = 4.50
(55−50)250=2550=0.50\frac{(55-50)^2}{50} = \frac{25}{50} = 0.50
(45−50)250=2550=0.50\frac{(45-50)^2}{50} = \frac{25}{50} = 0.50
(35−50)250=22550=4.50\frac{(35-50)^2}{50} = \frac{225}{50} = 4.50
χ2=4.50+0.50+0.50+4.50=10.00\chi^2 = 4.50 + 0.50 + 0.50 + 4.50 = 10.00.
Since calculated χ2=10.00>critical value 7.815\chi^2 = 10.00 > \text{critical value } 7.815, we reject H0H_0.
Q2: B — E=50.0,χ2=8.00E = 50.0, \chi^2 = 8.00
Step-by-step Solution:
Row total for Major A = 100100. Column total for Interned = 100100. Grand Total N=200N = 200.
Expected count for cell (Major A, Interned):
EMajorA, Interned=100×100200=50.0E_{\text{MajorA, Interned}} = \frac{100 \times 100}{200} = 50.0
Similarly, all four expected counts equal 50.050.0.
Chi-Square Statistic:
χ2=(40−50)250+(60−50)250+(60−50)250+(40−50)250=10050×4=2.0×4=8.00\chi^2 = \frac{(40-50)^2}{50} + \frac{(60-50)^2}{50} + \frac{(60-50)^2}{50} + \frac{(40-50)^2}{50} = \frac{100}{50} \times 4 = 2.0 \times 4 = 8.00
Q3: A — p^pool=0.30,z=0.00\hat{p}_{\text{pool}} = 0.30, z = 0.00
Step-by-step Solution:
Pooled proportion:
p^pool=x1+x2n1+n2=120+180400+600=3001000=0.30\hat{p}_{\text{pool}} = \frac{x_1 + x_2}{n_1 + n_2} = \frac{120 + 180}{400 + 600} = \frac{300}{1000} = 0.30
Sample proportions: p^1=120400=0.30\hat{p}_1 = \frac{120}{400} = 0.30, p^2=180600=0.30\hat{p}_2 = \frac{180}{600} = 0.30.
Difference in sample proportions: p^1−p^2=0.30−0.30=0\hat{p}_1 - \hat{p}_2 = 0.30 - 0.30 = 0.
z=0SEpool=0.00z = \frac{0}{SE_{\text{pool}}} = 0.00.
Q4: A — dof=1, exp_CourseX_Fail=25.0
Step-by-step Solution:
df_table dimensions: 2 rows (Course_X, Course_Y), 2 columns (Pass, Fail).
Degrees of freedom: df=(2−1)(2−1)=1df = (2-1)(2-1) = 1.
Row Total for Course_X = 85+15=10085 + 15 = 100. Column Total for Fail = 15+35=5015 + 35 = 50. Grand Total N=200N = 200.
Expected count for Course_X Fail (index [0,1]):
E0,1=100×50200=25.0E_{0,1} = \frac{100 \times 50}{200} = 25.0
Python prints: dof=1, exp_CourseX_Fail=25.0.
Q5: C — z=2.00
Step-by-step Solution:
Sample proportion: p^=60100=0.60\hat{p} = \frac{60}{100} = 0.60.
Hypothesized proportion under H0H_0: p0=0.50p_0 = 0.50.
Standard Error under H0H_0: SE0=0.50×0.50100=0.0025=0.05SE_0 = \sqrt{\frac{0.50 \times 0.50}{100}} = \sqrt{0.0025} = 0.05.
z=p^−p0SE0=0.60−0.500.05=0.100.05=2.00z = \frac{\hat{p} - p_0}{SE_0} = \frac{0.60 - 0.50}{0.05} = \frac{0.10}{0.05} = 2.00.
Q6: C — Every expected cell count Eij≥5E_{ij} \ge 5, and df=(3−1)(4−1)=6df = (3 - 1)(4 - 1) = 6.
Step-by-step Solution:
For a Test of Independence on an r×cr \times c table, degrees of freedom df=(r−1)(c−1)=(3−1)(4−1)=2×3=6df = (r-1)(c-1) = (3-1)(4-1) = 2 \times 3 = 6.
The sample size condition requires expected cell counts Eij≥5E_{ij} \ge 5, not observed cell counts OijO_{ij}.
Chi-Square statistics cannot be negative because all terms (O−E)2E≥0\frac{(O-E)^2}{E} \ge 0.

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

Which of the following is true about categorical data compared to numerical data in statistical inference?

Q2

In a One-Proportion z-Test, what is the correct formula for the standard error under the null hypothesis?

Q3

When planning sample sizes for a confidence interval, under which condition is the Margin of Error maximized?

Q4

Which condition must be met to use the normal approximation in a One-Proportion z-Test?

Q5

What is the purpose of calculating a pooled proportion (p^pool\hat{p}_{\text{pool}}) in a Two-Proportion z-Test?

Q6

In a Chi-Square Goodness-of-Fit Test, what does the null hypothesis (H0H_0) generally state?

Q7

How are the degrees of freedom calculated for a Chi-Square Test of Independence on an r×cr \times c contingency table?

Q8

What is the "Expected Cell Counts Condition" for a valid Chi-Square test?

Q9

Why are Chi-Square tests inherently one-sided (right-tailed)?

Q10

When using Python's scipy.stats.chi2_contingency function on a 2×22 \times 2 table, why might the results differ from manual Pearson calculations?

Inference for Categorical Data | PROJECT ENGRAM