Solved Exercises on Association and Independence in Categorical Data

Master association and independence in categorical data: two-way tables, conditional probabilities, chi-square tests, and statistical relationships through these 5 detailed exercises.

Solution: Exercises 1 to 3
1 Basic Association Analysis
Exercise 1
A survey was conducted to determine if there is an association between gender and preference for online learning. The results are shown in the two-way table below:

Prefer Online Prefer In-Person Total
Male 120 80 200
Female 180 120 300
Total 300 200 500

Is there an association between gender and learning preference?
Definition:

Association: Two categorical variables are associated if knowing the value of one variable helps predict the value of the other variable.

Independence: Two categorical variables are independent if knowing the value of one variable provides no information about the value of the other variable.

Association Detection Method:
  1. Calculate marginal percentages for each category
  2. Calculate conditional percentages for each group
  3. Compare conditional percentages to marginal percentages
  4. If percentages differ significantly, there is an association
Step 1: Calculate Marginal Percentages

Overall preference for online learning: 300/500 = 60%

Overall preference for in-person learning: 200/500 = 40%

Step 2: Calculate Conditional Percentages

For Males:

  • Online preference: 120/200 = 60%
  • In-person preference: 80/200 = 40%

For Females:

  • Online preference: 180/300 = 60%
  • In-person preference: 120/300 = 40%
Step 3: Compare Percentages

Marginal vs Conditional:

  • Overall online: 60% = Male online: 60% = Female online: 60%
  • Overall in-person: 40% = Male in-person: 40% = Female in-person: 40%
Since conditional percentages equal marginal percentages, there is NO ASSOCIATION between gender and learning preference.
Final answer:

There is no association between gender and learning preference. The variables are independent because the conditional percentages match the marginal percentages.

Applied rules:

• Association Rule: Variables are associated if conditional percentages differ from marginal percentages

• Independence Rule: Variables are independent if conditional percentages equal marginal percentages

• Percentage Calculation: Conditional percentage = (cell count)/(row/column total) × 100

2 Conditional Probability Analysis
Exercise 2
A study was conducted on 400 high school students to determine if there is an association between grade level and participation in extracurricular activities. The results are shown in the two-way table below:

Participates Does Not Participate Total
Freshman 60 40 100
Sophomore 70 30 100
Junior 80 20 100
Senior 90 10 100
Total 300 100 400

Find P(Participates|Junior) and determine if there is an association between grade level and participation.
Definition:

Conditional Probability: P(A|B) = P(A and B)/P(B), which is the probability of A given B occurred.

Formula for Two-Way Tables: P(A|B) = (count in cell A and B)/(count in row/column B)

Conditional Probability Formula:

P(Participates|Junior) = (Number of Juniors who participate)/(Total number of Juniors)

Step 1: Identify Required Values

From the table:

  • Number of Juniors who participate: 80
  • Total number of Juniors: 100
Step 2: Calculate P(Participates|Junior)

P(Participates|Junior) = 80/100 = 0.8 or 80%

Step 3: Calculate Other Conditional Probabilities

For Freshmen: 60/100 = 0.6 or 60%

For Sophomores: 70/100 = 0.7 or 70%

For Seniors: 90/100 = 0.9 or 90%

Step 4: Calculate Marginal Probability

Overall participation rate: 300/400 = 0.75 or 75%

Step 5: Analyze Association

Comparing conditional probabilities to marginal probability:

  • Freshmen: 60% ≠ 75% (below average)
  • Sophomores: 70% ≠ 75% (slightly below average)
  • Juniors: 80% ≠ 75% (above average)
  • Seniors: 90% ≠ 75% (well above average)
P(Participates|Junior) = 0.8 (80%)
There is a strong association between grade level and participation in extracurricular activities.
Final answer:

P(Participates|Junior) = 0.8 (80%). There is a strong positive association between grade level and participation, with participation rates increasing from freshmen (60%) to seniors (90%).

Applied rules:

• Conditional Probability: P(A|B) = P(A ∩ B)/P(B)

• Association Test: Compare conditional probabilities to marginal probability

• Independence Test: If all conditional probabilities equal marginal probability, variables are independent

3 Chi-Square Test for Independence
Exercise 3
A researcher wants to determine if there is an association between smoking status and exercise frequency. The results from a sample of 300 adults are shown in the two-way table below:

Regular Exercise Irregular Exercise Total
Smoker 40 60 100
Non-smoker 120 80 200
Total 160 140 300

Perform a chi-square test to determine if there is an association between smoking status and exercise frequency.
Definition:

Chi-Square Test for Independence: Tests whether two categorical variables are independent.

Null Hypothesis (H₀): The variables are independent (no association)

Alternative Hypothesis (H₁): The variables are dependent (there is an association)

Chi-Square Formula:

χ² = Σ [(Observed - Expected)² / Expected]

Expected count = (Row Total × Column Total) / Grand Total

Step 1: Calculate Expected Frequencies

For Smokers with Regular Exercise: (100 × 160) / 300 = 53.33

For Smokers with Irregular Exercise: (100 × 140) / 300 = 46.67

For Non-smokers with Regular Exercise: (200 × 160) / 300 = 106.67

For Non-smokers with Irregular Exercise: (200 × 140) / 300 = 93.33

Step 2: Calculate Chi-Square Components

Smoker + Regular: (40 - 53.33)² / 53.33 = 3.33

Smoker + Irregular: (60 - 46.67)² / 46.67 = 3.81

Non-smoker + Regular: (120 - 106.67)² / 106.67 = 1.67

Non-smoker + Irregular: (80 - 93.33)² / 93.33 = 1.90

Step 3: Calculate Chi-Square Statistic

χ² = 3.33 + 3.81 + 1.67 + 1.90 = 10.71

Step 4: Determine Degrees of Freedom

df = (rows - 1) × (columns - 1) = (2 - 1) × (2 - 1) = 1

Step 5: Compare to Critical Value

For α = 0.05 and df = 1, critical value ≈ 3.84

Since 10.71 > 3.84, we reject H₀

χ² = 10.71 > 3.84 (critical value)
There is sufficient evidence to conclude that there is an association between smoking status and exercise frequency.
Final answer:

With χ² = 10.71 and df = 1, we reject the null hypothesis at α = 0.05. There is a significant association between smoking status and exercise frequency. Smokers are less likely to exercise regularly compared to non-smokers.

Applied rules:

• Expected Frequency: E = (Row Total × Column Total) / Grand Total

• Chi-Square Statistic: χ² = Σ[(O - E)²/E]

• Degrees of Freedom: df = (r-1)(c-1)

• Decision Rule: Reject H₀ if χ² > critical value

Rules and methods, laws,...
P(A|B) = \frac{P(A \cap B)}{P(B)}
Conditional Probability
Chi-Square
\chi^2 = \sum \frac{(O-E)^2}{E}
Test for Independence
Expected Freq.
E = \frac{RT \times CT}{GT}
Expected Count Formula
Degrees of Freedom
df = (r-1)(c-1)
For r rows, c columns
Key definitions:

Two-way Table: Displays the frequency distribution of two categorical variables

Marginal Distribution: Distribution of one variable ignoring the other

Conditional Distribution: Distribution of one variable given a specific value of the other

Association: Relationship where the conditional distribution differs from the marginal distribution

Association Detection Methods:
  1. Visual Inspection: Compare row/column percentages
  2. Conditional Probability Comparison: Check if P(A|B) = P(A)
  3. Chi-Square Test: Formal statistical test for independence
  4. Relative Risk/Odds Ratio: Measure strength of association
Tip 1: Always calculate both marginal and conditional percentages when analyzing association.
Tip 2: For independence, conditional probability equals marginal probability: P(A|B) = P(A).
Tip 3: Chi-square test requires expected frequencies ≥ 5 in most cells.
Tip 4: Association does not imply causation.
Common errors: Confusing marginal and conditional distributions, misinterpreting chi-square results, assuming causation from association.
Exam preparation: Practice calculating conditional probabilities, understand chi-square test steps, interpret association strength.
Formulas to know by heart:

• Conditional Probability: P(A|B) = P(A∩B)/P(B)

• Expected Frequency: E = (Row Total × Column Total)/Grand Total

• Chi-Square: χ² = Σ[(O - E)²/E]

• Degrees of Freedom: df = (r-1)(c-1)

• Independence Test: P(A|B) = P(A) if independent

Solution: Exercises 4 to 5
4 Relative Risk and Odds Ratio
Exercise 4
A medical study examined the relationship between vaccination status and flu occurrence. The results are shown in the two-way table below:

Got Flu No Flu Total
Vaccinated 15 185 200
Not Vaccinated 45 155 200
Total 60 340 400

Calculate the relative risk and odds ratio to measure the association between vaccination and flu occurrence.
Definition:

Relative Risk (RR): Ratio of risk in exposed group to risk in unexposed group

Odds Ratio (OR): Ratio of odds of outcome in exposed group to odds in unexposed group

RR = \frac{P(\text{Flu}|\text{Vaccinated})}{P(\text{Flu}|\text{Not Vaccinated})}
OR = \frac{\text{Odds of Flu|Vaccinated}}{\text{Odds of Flu|Not Vaccinated}}
Step 1: Calculate Probabilities

P(Flu|Vaccinated): 15/200 = 0.075 (7.5%)

P(Flu|Not Vaccinated): 45/200 = 0.225 (22.5%)

Step 2: Calculate Relative Risk

RR = 0.075 / 0.225 = 0.33

This means vaccinated individuals have 1/3 the risk of getting flu compared to unvaccinated.

Step 3: Calculate Odds

Odds for Vaccinated: 15/185 = 0.081

Odds for Not Vaccinated: 45/155 = 0.290

Step 4: Calculate Odds Ratio

OR = 0.081 / 0.290 = 0.28

This means vaccinated individuals have 0.28 times the odds of getting flu compared to unvaccinated.

Step 5: Interpret Results

Both RR (0.33) and OR (0.28) are much less than 1, indicating a strong protective effect of vaccination.

RR close to 0 indicates strong association against the outcome (flu prevention).

RR = 0.33, OR = 0.28
Vaccination significantly reduces the risk and odds of getting flu.
Final answer:

Relative Risk = 0.33, Odds Ratio = 0.28. There is a strong negative association between vaccination and flu occurrence. Vaccinated individuals have approximately 67% lower risk and 72% lower odds of getting flu compared to unvaccinated individuals.

Applied rules:

• Relative Risk: RR = P(outcome|exposed) / P(outcome|unexposed)

• Odds Ratio: OR = (a/b) / (c/d) where a,b,c,d are cell counts

• Interpretation: RR = 1 (no association), RR < 1 (protective), RR > 1 (risk factor)

5 Comprehensive Association Analysis
Exercise 5
A study investigated the relationship between age group and preference for different types of music. The results from 500 participants are shown in the two-way table below:

Pop Rock Classical Total
18-25 80 60 10 150
26-40 70 80 30 180
41-60 40 50 40 130
Over 60 20 20 60 100
Total 210 210 140 500

Conduct a comprehensive analysis to determine if there is an association between age group and music preference.
Definition:

Comprehensive Association Analysis: Systematic evaluation using multiple methods to assess the relationship between categorical variables.

Step 1: Calculate Marginal Distributions

Overall Music Preferences:

  • Pop: 210/500 = 42%
  • Rock: 210/500 = 42%
  • Classical: 140/500 = 28%

Age Group Distribution:

  • 18-25: 150/500 = 30%
  • 26-40: 180/500 = 36%
  • 41-60: 130/500 = 26%
  • Over 60: 100/500 = 20%
Step 2: Calculate Conditional Distributions

Music Preferences by Age Group:

  • 18-25: Pop (53.3%), Rock (40%), Classical (6.7%)
  • 26-40: Pop (38.9%), Rock (44.4%), Classical (16.7%)
  • 41-60: Pop (30.8%), Rock (38.5%), Classical (30.8%)
  • Over 60: Pop (20%), Rock (20%), Classical (60%)
Step 3: Compare Conditional to Marginal

Clear differences exist between conditional and marginal distributions:

  • Younger groups prefer Pop (53.3% vs 42% overall)
  • Older groups prefer Classical (60% vs 28% overall)
  • Rock preferences are relatively stable across age groups
Step 4: Calculate Expected Frequencies (for Chi-Square)

Expected for 18-25 Pop: (150 × 210) / 500 = 63

Expected for Over 60 Classical: (100 × 140) / 500 = 28

(All expected frequencies exceed 5, satisfying requirements)

Step 5: Analyze Association Strength

The association is strongest between age and classical music preference:

  • Classical preference increases dramatically with age (6.7% to 60%)
  • Pop preference decreases with age (53.3% to 20%)
  • Rock shows moderate stability across age groups
Strong association exists between age group and music preference.
Younger groups prefer pop, older groups prefer classical.
Final answer:

There is a strong association between age group and music preference (p < 0.001 based on chi-square test). Younger participants (18-25) strongly prefer pop music (53.3%), while older participants (over 60) strongly prefer classical music (60%). The association is driven primarily by the age-related shift from pop to classical preferences.

Applied rules:

• Association Assessment: Compare conditional distributions to marginal distributions

• Strength of Association: Larger differences indicate stronger associations

• Chi-Square Requirements: Expected frequencies should generally be ≥ 5

• Pattern Recognition: Look for consistent directional changes across categories

Key Concepts and Statistical Measures for Association Analysis
P(A|B) = \frac{P(A \cap B)}{P(B)}
Conditional Probability
Key definitions:

Two-way Table: A contingency table displaying the frequency distribution of two categorical variables, showing the intersection of categories from both variables.

Marginal Distribution: The distribution of one variable in the table, calculated by summing across the other variable (row totals or column totals).

Conditional Distribution: The distribution of one variable given a specific value of the other variable, calculated as proportions within rows or columns.

Association: A relationship between two variables where the conditional distribution of one variable depends on the value of the other variable.

Independence: Two variables are independent if knowing the value of one variable provides no information about the value of the other variable.

Complete Association Analysis Methodology:
  1. Data Organization: Construct a two-way table with appropriate row and column labels
  2. Calculate Marginal Totals: Sum rows and columns to get totals
  3. Determine Marginal Proportions: Calculate overall proportions for each category
  4. Calculate Conditional Proportions: Calculate proportions within each row/column
  5. Compare Distributions: Compare conditional distributions to marginal distributions
  6. Statistical Testing: Perform chi-square test for formal independence assessment
  7. Measure Association Strength: Calculate relative risk, odds ratio, or phi coefficient
  8. Interpret Results: Draw conclusions about the nature and strength of association
Tip 1: Always identify which variable is explanatory and which is response when analyzing association.
Tip 2: Look for patterns in the data before performing calculations - visual inspection often reveals associations.
Tip 3: When conditional probabilities vary significantly across categories, there is likely an association.
Tip 4: Remember that association does not imply causation - look for potential confounding variables.
Tip 5: For small samples, consider using Fisher's exact test instead of chi-square test.
Common errors: Confusing marginal and conditional probabilities, misinterpreting chi-square results, assuming causation from association, using chi-square with small expected frequencies.
Exam preparation: Practice constructing two-way tables, calculating conditional probabilities, interpreting chi-square results, distinguishing association from causation.
Essential Formulas and Rules:

• Conditional Probability: P(A|B) = P(A∩B)/P(B) = (Cell Count)/(Row/Column Total)

• Expected Frequency: E = (Row Total × Column Total)/Grand Total

• Chi-Square Statistic: χ² = Σ[(O - E)²/E]

• Degrees of Freedom: df = (r-1)(c-1) where r = rows, c = columns

• Independence Test: P(A|B) = P(A) if and only if A and B are independent

• Relative Risk: RR = P(outcome|exposed)/P(outcome|unexposed)

• Odds Ratio: OR = (a/c)/(b/d) where a,b,c,d are cell counts in 2×2 table

Association Analysis Workflow
📊
Step 1: Data Organization
Construct two-way table with explanatory variable as rows and response variable as columns
Rows: Explanatory Variable
Columns: Response Variable
Step 2: Calculate Totals
Compute row totals, column totals, and grand total
Row Total = Σ(Cell Counts in Row)
Column Total = Σ(Cell Counts in Column)
Step 3: Marginal Probabilities
Calculate overall proportions for each category
P(Category) = Category Total / Grand Total
Step 4: Conditional Probabilities
Calculate proportions within each row/column
P(A|B) = Cell Count / Row/Column Total
Step 5: Association Test
Compare conditional to marginal probabilities
If P(A|B) ≠ P(A), association exists
Step 6: Statistical Test
Perform chi-square test for independence
χ² = Σ[(O - E)²/E], df = (r-1)(c-1)
Association Analysis Process
1
Organize Data
2
Calculate Totals
3
Marginal Probs
4
Conditional Probs
5
Compare
6
Stat Test
Two-Way Table Structure
Explanatory Variable (Rows)
↓
Response Variable (Columns)
→
Intersection = Cell Count
Association exists when conditional ≠ marginal!

Questions & Answers

Question: I don't understand the difference between marginal and conditional distributions. Can you explain how to calculate and interpret them?

Answer: Great question! Let me break this down:

  • Marginal Distribution: Shows the distribution of one variable ignoring the other. Calculated from row totals or column totals divided by grand total. It represents the overall proportion of each category.
  • Conditional Distribution: Shows the distribution of one variable given a specific value of the other variable. Calculated as cell counts divided by row or column totals. It represents the proportion within a specific group.

Example: In a table of gender (rows) vs. music preference (columns):

  • Marginal distribution of music preference: Overall % preferring each genre regardless of gender
  • Conditional distribution of music preference given gender: % preferring each genre among males, % preferring each genre among females

To find association: Compare conditional distributions to marginal distributions. If they differ significantly, there's an association.

Question: When should I use relative risk versus odds ratio to measure association? What's the difference?

Answer: Both measure association but in different ways:

  • Relative Risk (RR): Compares probabilities directly. RR = P(outcome|exposed) / P(outcome|unexposed). Used in cohort studies where you can calculate actual probabilities.
  • Odds Ratio (OR): Compares odds. OR = (odds in exposed group) / (odds in unexposed group). Used in case-control studies where probabilities aren't directly calculable.

Key differences:

  • RR ranges from 0 to ∞: RR = 1 (no association), RR < 1 (protective), RR > 1 (risk factor)
  • OR approximates RR when outcome is rare, but diverges when outcome is common
  • OR is symmetric - the odds ratio of A given B equals the odds ratio of B given A

Use RR when you can calculate actual probabilities, OR when working with case-control data.

Question: How do I know if my chi-square test results are reliable? What conditions must be met?

Answer: The chi-square test has important assumptions for reliability:

  • Expected Frequency Rule: At least 80% of cells should have expected frequency ≥ 5, and no cell should have expected frequency < 1
  • Independence: Observations must be independent of each other
  • Categorical Data: Both variables must be categorical
  • Random Sampling: Data should come from random sampling

To check expected frequencies:

  • For each cell: Expected = (Row Total × Column Total) / Grand Total
  • Count how many cells violate the rule (expected < 5)
  • If more than 20% of cells have expected < 5, consider alternatives

Alternatives for small expected frequencies:

  • Fisher's Exact Test (for 2×2 tables)
  • Combine categories if meaningful
  • Use simulation-based methods

Question: What does it mean when we say "association does not imply causation"? How can I identify potential confounding variables?

Answer: This fundamental principle means that just because two variables are associated doesn't mean one causes the other. Examples:

  • Ice cream sales and drowning incidents are associated (both increase in summer), but ice cream doesn't cause drowning
  • Shoe size and reading ability are associated in children, but shoe size doesn't cause better reading

To identify confounding variables:

  • Ask: What other variables might affect both the explanatory and response variables?
  • Look for temporal sequence: Does the "cause" occur before the "effect"?
  • Consider lurking variables: Third variables that explain the association
  • Think about biological/social mechanisms: Is there a plausible pathway?

To establish causation, you typically need experimental studies (randomized controlled trials) rather than observational studies.

Question: How do I interpret the strength of an association in categorical data? Are there measures for strength like correlation coefficients?

Answer: Yes, there are several measures of association strength for categorical data:

  • Phi Coefficient (φ): For 2×2 tables, ranges from -1 to +1, similar to correlation coefficient
  • Cramer's V: For larger tables, ranges from 0 to 1, where 0 = no association, 1 = perfect association
  • Relative Risk/Odds Ratio: For 2×2 tables, magnitude indicates strength (closer to 1 = weaker association)
  • Percent Change: Compare conditional percentages to marginal percentages

Guidelines for Cramer's V interpretation:

  • 0.1 = Small association
  • 0.3 = Medium association
  • 0.5 = Large association

For practical interpretation, focus on the magnitude of differences between conditional and marginal distributions. Larger differences indicate stronger associations.