knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
# List of packages
packages <- c("tidyverse", "broom", "modelsummary", "sjPlot", "car", "knitr", "gt", "fst", "Lock5Data", "patchwork", "kableExtra", "broom", "sjmisc", "sjlabelled", "gt", "tinytable", "webshot2", "officer", "effects", "interactions", "see", "equatiomatic", "stevedata", "cowplot", "ggeffects")
# Install packages if they aren't installed already
new_packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages)
# Load the packages
lapply(packages, library, character.only = TRUE)

Thursday, March 13th Session

Practice exercises state the following:

For this week’s practice exercise, you will build an alternative set of regression models to explore different factors that might influence community satisfaction in Atlantic Canada. Instead of using the predictors we examined in class, you will work with three different variables:

  1. Income: PHHTTINC (Household total income)

  2. Education: PHGEDUC (Highest level of education completed)

  3. Visible Minority Status: PVISMIN (Visible minority in household)

I will provide the full survey documentation as a PDF on Moodle.

Assignment Instructions:

  1. Build Three Progressive Models:

    • Model 1: Community satisfaction predicted by household income (PHHTTINC)

    • Model 2: Add education level (PHGEDUC)

    • Model 3: Add visible minority household member (PVISMIN)

chs_data <- read.csv("CHS2021ECL_PUMF.csv")

Now suppose we do the following:

atlantic <- chs_data %>%
  select(
    satisfaction = PCOS_05,
    income = PHHTTINC,
    education = PHGEDUC,
    visible_minority = PVISMIN
  )
model1 <- lm(satisfaction ~ income, data = atlantic)
model2 <- lm(satisfaction ~ income + education, data = atlantic)
model3 <- lm(satisfaction ~ income + education + visible_minority, data = atlantic)
tab_model(
  model1, model2, model3,
  dv.labels = c("Model 1: Income", "Model 2: + Education", "Model 3: + Minority Status"),
  title = "Modeling Without Data Checking"
)
Modeling Without Data Checking
  Model 1: Income Model 2: + Education Model 3: + Minority Status
Predictors Estimates CI p Estimates CI p Estimates CI p
(Intercept) 7.27 7.16 – 7.38 <0.001 7.19 7.08 – 7.31 <0.001 7.10 6.92 – 7.28 <0.001
income -0.00 -0.00 – -0.00 0.009 -0.00 -0.00 – -0.00 <0.001 -0.00 -0.00 – -0.00 <0.001
education 0.01 0.00 – 0.01 <0.001 0.01 0.00 – 0.01 <0.001
visible minority 0.02 -0.01 – 0.05 0.184
Observations 40988 40988 40988
R2 / R2 adjusted 0.000 / 0.000 0.001 / 0.001 0.001 / 0.001

What do you note? Is this correct? Where did we go wrong?

Lesson 1: Always Check, and Double Check

print(table(chs_data$PGEOGR))
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
## 2446 1714 1088 1977 2037 2001 1218 1165 1395 2195  946 1021 1009 1091 1033 2233 
##   17   18   19   20   21   22   23   24   25   26   27   28 
## 1037 1924  997  940 1742 1078  968 2748 1110 1123 1964  788
print(table(chs_data$PVISMIN))
## 
##     1     2     9 
##  2609 17765 20614
print(table(chs_data$PHGEDUC))
## 
##    1    2    3    4    5    6    7   99 
## 3691 8035 3539 7656 1688 6671 4230 5478
print(table(chs_data$PCOS_05))
## 
##    1    2    3    4    5    6    7    8    9   99 
## 1829 1122 1246 6034 3513 6297 8578 4396 7515  458

What do you note here? What about below?

atlantic_chs <- chs_data %>%
  filter(PGEOGR %in% 1:6) %>%
  select(
    outcome = PCOS_05,              # Community satisfaction (0-10)
    household_income = PHHTTINC,    # Household income
    education = PHGEDUC,            # Highest education completed
    visible_minority = PVISMIN      # Visible minority status
  )

table(atlantic_chs$visible_minority)
## 
##     9 
## 11263

Let’s do a more systematic check:

vis_min_by_region <- chs_data %>%
  group_by(PGEOGR) %>%
  summarize(
    total_observations = n(),
    visible_minority_1 = sum(PVISMIN == 1),
    visible_minority_2 = sum(PVISMIN == 2),
    visible_minority_9 = sum(PVISMIN == 9),
    percent_missing = round(sum(PVISMIN == 9) / n() * 100, 1)
  )
print(vis_min_by_region)
## # A tibble: 28 × 6
##    PGEOGR total_observations visible_minority_1 visible_minority_2
##     <int>              <int>              <int>              <int>
##  1      1               2446                  0                  0
##  2      2               1714                  0                  0
##  3      3               1088                  0                  0
##  4      4               1977                  0                  0
##  5      5               2037                  0                  0
##  6      6               2001                  0                  0
##  7      7               1218                 23               1076
##  8      8               1165                288                870
##  9      9               1395                 11               1236
## 10     10               2195                  4               2109
## # ℹ 18 more rows
## # ℹ 2 more variables: visible_minority_9 <int>, percent_missing <dbl>

We could run the models on the full data like so:

chs_for_analysis <- chs_data %>%
  select(
    outcome = PCOS_05,              # Community satisfaction (0-10)
    household_income = PHHTTINC,    # Household income
    education = PHGEDUC,            # Highest education completed
    visible_minority = PVISMIN,     # Visible minority status
    region = PGEOGR                 # Region code
  ) %>%
  mutate(
    # Clean outcome variable (community satisfaction 0-10)
    outcome = case_when(
      outcome < 0 ~ NA_real_,
      outcome > 10 ~ NA_real_,
      TRUE ~ as.numeric(outcome)
    ),
    
    # Clean household income by excluding extreme values
    household_income = case_when(
      household_income >= 99999999999 ~ NA_real_,  # Exclude extremely large values
      household_income < 0 ~ NA_real_,             # Exclude negative values
      TRUE ~ household_income
    ),
    
    # Create log income variable with clean data
    log_income = log10(household_income + 1),
    
    # Recode region with all provided names
    region_name = case_when(
      region == 1 ~ "Newfoundland and Labrador",
      region == 2 ~ "Prince Edward Island",
      region == 3 ~ "Halifax",
      region == 4 ~ "Outside Halifax - NS",
      region == 5 ~ "Saint John and Moncton",
      region == 6 ~ "Outside Saint John and Moncton - NB",
      region == 7 ~ "Québec",
      region == 8 ~ "Montréal",
      region == 9 ~ "Other CMAs - Québec",
      region == 10 ~ "Outside CMAs - QC",
      region == 11 ~ "Ottawa",
      region == 12 ~ "Toronto",
      region == 13 ~ "Hamilton",
      region == 14 ~ "Kitchener-Cambridge-Waterloo",
      region == 15 ~ "Other CMAs - Ontario",
      region == 16 ~ "Outside CMAs - ON",
      region == 17 ~ "Winnipeg",
      region == 18 ~ "Outside Winnipeg - MB",
      region == 19 ~ "Regina",
      region == 20 ~ "Saskatoon",
      region == 21 ~ "Outside Regina and Saskatoon - SK",
      region == 22 ~ "Calgary",
      region == 23 ~ "Edmonton",
      region == 24 ~ "Outside Calgary and Edmonton - AB",
      region == 25 ~ "Vancouver",
      region == 26 ~ "Other CMAs - British Columbia",
      region == 27 ~ "Outside CMAs - BC",
      region == 28 ~ "Territories",
      TRUE ~ NA_character_
    ),
    
    # Convert to factor with explicit ordering
    region_name = factor(region_name),
    
    # Recode education as a factor with meaningful labels
    education = case_when(
      education == 1 ~ "Less than high school",
      education == 2 ~ "High school diploma",
      education == 3 ~ "Trade certificate",
      education == 4 ~ "College/CEGEP diploma",
      education == 5 ~ "University below bachelor",
      education == 6 ~ "Bachelor's degree",
      education == 7 ~ "Above bachelor's degree",
      TRUE ~ NA_character_
    ),
    
    # Convert to factor with explicit ordering
    education = factor(education, 
                     levels = c("Less than high school", 
                               "High school diploma", 
                               "Trade certificate", 
                               "College/CEGEP diploma", 
                               "University below bachelor", 
                               "Bachelor's degree", 
                               "Above bachelor's degree")),
    
    # Recode visible minority status as a factor
    # Based on the table: 1=visible minority, 2=no visible minority, 9=not stated
    visible_minority = case_when(
      visible_minority == 1 ~ "Visible minority member",
      visible_minority == 2 ~ "No visible minority",
      TRUE ~ NA_character_
    ),
    
    # Convert to factor with explicit ordering
    visible_minority = factor(visible_minority,
                            levels = c("Visible minority member", 
                                      "No visible minority"))
  )

Building Progressive Regression Models (using full dataset for demonstration)

# Model 1: Household Income Only
model1 <- lm(outcome ~ log_income, data = chs_for_analysis)
summary(model1)
## 
## Call:
## lm(formula = outcome ~ log_income, data = chs_for_analysis)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.3936 -1.3103  0.6809  1.7434  3.0253 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.55803    0.16168  34.377  < 2e-16 ***
## log_income   0.14417    0.03352   4.302  1.7e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.172 on 33140 degrees of freedom
##   (7846 observations deleted due to missingness)
## Multiple R-squared:  0.000558,   Adjusted R-squared:  0.0005279 
## F-statistic:  18.5 on 1 and 33140 DF,  p-value: 1.701e-05
# Model 2: Add Education Level
model2 <- lm(outcome ~ log_income + education, data = chs_for_analysis)
summary(model2)
## 
## Call:
## lm(formula = outcome ~ log_income + education, data = chs_for_analysis)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.1680 -1.4335  0.4245  1.7528  3.9079 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                         4.56769    0.18474  24.725   <2e-16 ***
## log_income                          0.49260    0.04046  12.175   <2e-16 ***
## educationHigh school diploma       -0.47556    0.04642 -10.246   <2e-16 ***
## educationTrade certificate         -0.58201    0.05512 -10.560   <2e-16 ***
## educationCollege/CEGEP diploma     -0.83930    0.04815 -17.432   <2e-16 ***
## educationUniversity below bachelor -0.61749    0.06969  -8.861   <2e-16 ***
## educationBachelor's degree         -0.92026    0.05165 -17.816   <2e-16 ***
## educationAbove bachelor's degree   -0.90825    0.05711 -15.904   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.151 on 30378 degrees of freedom
##   (10602 observations deleted due to missingness)
## Multiple R-squared:  0.01401,    Adjusted R-squared:  0.01378 
## F-statistic: 61.67 on 7 and 30378 DF,  p-value: < 2.2e-16
# Model 3: Add Visible Minority Status
model3 <- lm(outcome ~ log_income + education + visible_minority, data = chs_for_analysis)
summary(model3)
## 
## Call:
## lm(formula = outcome ~ log_income + education + visible_minority, 
##     data = chs_for_analysis)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.8930 -1.6130  0.2976  1.7448  4.2639 
## 
## Coefficients:
##                                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                          3.97730    0.24539  16.208  < 2e-16 ***
## log_income                           0.53884    0.05207  10.349  < 2e-16 ***
## educationHigh school diploma        -0.45692    0.06318  -7.232 4.97e-13 ***
## educationTrade certificate          -0.64664    0.07562  -8.551  < 2e-16 ***
## educationCollege/CEGEP diploma      -0.76111    0.06491 -11.725  < 2e-16 ***
## educationUniversity below bachelor  -0.57024    0.09065  -6.290 3.24e-10 ***
## educationBachelor's degree          -0.84646    0.06960 -12.163  < 2e-16 ***
## educationAbove bachelor's degree    -0.80487    0.07645 -10.528  < 2e-16 ***
## visible_minorityNo visible minority  0.21569    0.05070   4.254 2.11e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.17 on 17349 degrees of freedom
##   (23630 observations deleted due to missingness)
## Multiple R-squared:  0.01395,    Adjusted R-squared:  0.0135 
## F-statistic: 30.69 on 8 and 17349 DF,  p-value: < 2.2e-16
# Create regression tables using tab_model
tab_model(
  model1, model2, model3,
  dv.labels = c("Model 1:\nIncome Only", "Model 2:\n+ Education", "Model 3:\n+ Visible Minority"),
  string.pred = "Predictors",
  string.est = "β",
  string.ci = "95% CI",
  p.style = "stars",
  show.aic = TRUE,
  show.r2 = TRUE,
  title = "Table 1. Factors Affecting Community Satisfaction in Canada"
)
Table 1. Factors Affecting Community Satisfaction in Canada
  Model 1: Income Only Model 2: + Education Model 3: + Visible Minority
Predictors β 95% CI β 95% CI β 95% CI
(Intercept) 5.56 *** 5.24 – 5.87 4.57 *** 4.21 – 4.93 3.98 *** 3.50 – 4.46
log income 0.14 *** 0.08 – 0.21 0.49 *** 0.41 – 0.57 0.54 *** 0.44 – 0.64
education [High school
diploma]
-0.48 *** -0.57 – -0.38 -0.46 *** -0.58 – -0.33
education [Trade
certificate]
-0.58 *** -0.69 – -0.47 -0.65 *** -0.79 – -0.50
education [College/CEGEP
diploma]
-0.84 *** -0.93 – -0.74 -0.76 *** -0.89 – -0.63
education [University
below bachelor]
-0.62 *** -0.75 – -0.48 -0.57 *** -0.75 – -0.39
education [Bachelor’s
degree]
-0.92 *** -1.02 – -0.82 -0.85 *** -0.98 – -0.71
education [Above
bachelor’s degree]
-0.91 *** -1.02 – -0.80 -0.80 *** -0.95 – -0.66
visible minority [No
visible minority]
0.22 *** 0.12 – 0.32
Observations 33142 30386 17358
R2 / R2 adjusted 0.001 / 0.001 0.014 / 0.014 0.014 / 0.013
AIC 145475.142 132800.950 76163.893
  • p<0.05   ** p<0.01   *** p<0.001

We are, however, not being systematic still in understanding how to handle all our variables:

Lesson 2: Explore variable distributions before AND after

atlantic_clean <- chs_data %>%
  filter(PGEOGR %in% 1:6) %>%
  select(
    satisfaction = PCOS_05,
    income = PHHTTINC,
    education = PHGEDUC,
    immigration = PRSPIMST,
    region = PGEOGR
  )

# Check income distribution before transformation
print(table(atlantic_clean$income))
## 
##         775         800         850         875        1300        1900 
##           2           1           1           1           3           1 
##        1950        2000        2400        2500        4200        4800 
##           1           1           1           3           1           1 
##        5250        5500        6000        6250        6500        7000 
##           1           1           1           2           1           2 
##        7250        7500        7750        8000        8250        8500 
##           5           4          14          15          15           9 
##        8750        9000        9250        9500        9750       10000 
##           6           5           5           4           7          19 
##       10500       11000       11500       12000       12500       13000 
##          20          22          34          28          14          17 
##       13500       14000       14500       15000       15500       16000 
##          19          25          19          19          20          14 
##       16500       17000       17500       18000       18500       19000 
##          10          17          20          11          20          38 
##       19500       20000       20500       21000       22000       23000 
##          24          97           2         166         230         214 
##       24000       25000       26000       27000       28000       29000 
##         160         143          86          91          81          75 
##       30000       31000       32000       33000       34000       35000 
##          80          67          69          73          89          93 
##       36000       37000       38000       39000       40000       41000 
##         100          92          95         101          95          79 
##       42000       43000       44000       45000       46000       47000 
##          78          89          70          70          78          74 
##       47500       48000       49000       50000       51000       52500 
##          27          77          56         133          11         126 
##       55000       57500       60000       62500       65000       67500 
##         174         174         150         164         185         157 
##       70000       72500       75000       77500       80000       82500 
##         157         146         136         132         142         133 
##       85000       87500       90000       92500       95000       97500 
##         146         117         122          99         137         102 
##       1e+05      102500      105000      110000      115000      120000 
##         142          16         153         143         129         122 
##      125000      130000      135000      140000      145000      150000 
##         154         111          92          93          93         102 
##      155000      160000      165000      170000      175000      180000 
##          86          70          72          50          57          58 
##      185000      190000      195000       2e+05      205000      210000 
##          46          61          39          54           3          64 
##      220000      230000      240000      250000      260000      270000 
##          51          46          33          32          23          21 
##      280000      290000       3e+05      310000      320000      330000 
##          16          14           6           5           1           6 
##      340000      350000      360000      370000      380000      390000 
##           7           8           5           7           8           4 
##       4e+05      410000      420000      450000      460000      470000 
##           4           4           1           2           5           7 
##      480000       5e+05      525000      550000      575000 99999999999 
##           7           6          10          12           3        2535
# Check satisfaction values
print(table(atlantic_clean$satisfaction))
## 
##    1    2    3    4    5    6    7    8    9   99 
##  437  242  300 1509  830 1581 2305 1314 2621  124
# Clean the variables one by one
atlantic_clean <- atlantic_clean %>%
  mutate(
    satisfaction_clean = case_when(
      satisfaction >= 0 & satisfaction <= 10 ~ satisfaction,
      TRUE ~ NA_real_
    )
  )

# Compare before AND after
print(table(atlantic_clean$satisfaction))
## 
##    1    2    3    4    5    6    7    8    9   99 
##  437  242  300 1509  830 1581 2305 1314 2621  124
print(table(atlantic_clean$satisfaction_clean))
## 
##    1    2    3    4    5    6    7    8    9 
##  437  242  300 1509  830 1581 2305 1314 2621
atlantic_clean <- atlantic_clean %>%
  mutate(
    income_clean = case_when(
      income >= 99999999999 ~ NA_real_,
      income < 0 ~ NA_real_,
      TRUE ~ income
    )
  )

## Compare before AND after
print(table(atlantic_clean$income))
## 
##         775         800         850         875        1300        1900 
##           2           1           1           1           3           1 
##        1950        2000        2400        2500        4200        4800 
##           1           1           1           3           1           1 
##        5250        5500        6000        6250        6500        7000 
##           1           1           1           2           1           2 
##        7250        7500        7750        8000        8250        8500 
##           5           4          14          15          15           9 
##        8750        9000        9250        9500        9750       10000 
##           6           5           5           4           7          19 
##       10500       11000       11500       12000       12500       13000 
##          20          22          34          28          14          17 
##       13500       14000       14500       15000       15500       16000 
##          19          25          19          19          20          14 
##       16500       17000       17500       18000       18500       19000 
##          10          17          20          11          20          38 
##       19500       20000       20500       21000       22000       23000 
##          24          97           2         166         230         214 
##       24000       25000       26000       27000       28000       29000 
##         160         143          86          91          81          75 
##       30000       31000       32000       33000       34000       35000 
##          80          67          69          73          89          93 
##       36000       37000       38000       39000       40000       41000 
##         100          92          95         101          95          79 
##       42000       43000       44000       45000       46000       47000 
##          78          89          70          70          78          74 
##       47500       48000       49000       50000       51000       52500 
##          27          77          56         133          11         126 
##       55000       57500       60000       62500       65000       67500 
##         174         174         150         164         185         157 
##       70000       72500       75000       77500       80000       82500 
##         157         146         136         132         142         133 
##       85000       87500       90000       92500       95000       97500 
##         146         117         122          99         137         102 
##       1e+05      102500      105000      110000      115000      120000 
##         142          16         153         143         129         122 
##      125000      130000      135000      140000      145000      150000 
##         154         111          92          93          93         102 
##      155000      160000      165000      170000      175000      180000 
##          86          70          72          50          57          58 
##      185000      190000      195000       2e+05      205000      210000 
##          46          61          39          54           3          64 
##      220000      230000      240000      250000      260000      270000 
##          51          46          33          32          23          21 
##      280000      290000       3e+05      310000      320000      330000 
##          16          14           6           5           1           6 
##      340000      350000      360000      370000      380000      390000 
##           7           8           5           7           8           4 
##       4e+05      410000      420000      450000      460000      470000 
##           4           4           1           2           5           7 
##      480000       5e+05      525000      550000      575000 99999999999 
##           7           6          10          12           3        2535
print(table(atlantic_clean$income_clean))
## 
##    775    800    850    875   1300   1900   1950   2000   2400   2500   4200 
##      2      1      1      1      3      1      1      1      1      3      1 
##   4800   5250   5500   6000   6250   6500   7000   7250   7500   7750   8000 
##      1      1      1      1      2      1      2      5      4     14     15 
##   8250   8500   8750   9000   9250   9500   9750  10000  10500  11000  11500 
##     15      9      6      5      5      4      7     19     20     22     34 
##  12000  12500  13000  13500  14000  14500  15000  15500  16000  16500  17000 
##     28     14     17     19     25     19     19     20     14     10     17 
##  17500  18000  18500  19000  19500  20000  20500  21000  22000  23000  24000 
##     20     11     20     38     24     97      2    166    230    214    160 
##  25000  26000  27000  28000  29000  30000  31000  32000  33000  34000  35000 
##    143     86     91     81     75     80     67     69     73     89     93 
##  36000  37000  38000  39000  40000  41000  42000  43000  44000  45000  46000 
##    100     92     95    101     95     79     78     89     70     70     78 
##  47000  47500  48000  49000  50000  51000  52500  55000  57500  60000  62500 
##     74     27     77     56    133     11    126    174    174    150    164 
##  65000  67500  70000  72500  75000  77500  80000  82500  85000  87500  90000 
##    185    157    157    146    136    132    142    133    146    117    122 
##  92500  95000  97500  1e+05 102500 105000 110000 115000 120000 125000 130000 
##     99    137    102    142     16    153    143    129    122    154    111 
## 135000 140000 145000 150000 155000 160000 165000 170000 175000 180000 185000 
##     92     93     93    102     86     70     72     50     57     58     46 
## 190000 195000  2e+05 205000 210000 220000 230000 240000 250000 260000 270000 
##     61     39     54      3     64     51     46     33     32     23     21 
## 280000 290000  3e+05 310000 320000 330000 340000 350000 360000 370000 380000 
##     16     14      6      5      1      6      7      8      5      7      8 
## 390000  4e+05 410000 420000 450000 460000 470000 480000  5e+05 525000 550000 
##      4      4      4      1      2      5      7      7      6     10     12 
## 575000 
##      3
atlantic_clean <- atlantic_clean %>%
  mutate(
    log_income = log10(income_clean)
  )

print(table(atlantic_clean$log_income))
## 
## 2.88930170250631 2.90308998699194 2.92941892571429 2.94200805302231 
##                2                1                1                1 
## 3.11394335230684 3.27875360095283 3.29003461136252 3.30102999566398 
##                3                1                1                1 
## 3.38021124171161 3.39794000867204  3.6232492903979 3.68124123737559 
##                1                3                1                1 
## 3.72015930340596 3.74036268949424 3.77815125038364 3.79588001734408 
##                1                1                1                2 
## 3.81291335664286 3.84509804001426 3.86033800657099  3.8750612633917 
##                1                2                5                4 
## 3.88930170250631 3.90308998699194 3.91645394854993 3.92941892571429 
##               14               15               15                9 
## 3.94200805302231 3.95424250943932 3.96614173273903 3.97772360528885 
##                6                5                5                4 
## 3.98900461569854                4 4.02118929906994 4.04139268515823 
##                7               19               20               22 
## 4.06069784035361 4.07918124604763 4.09691001300806 4.11394335230684 
##               34               28               14               17 
## 4.13033376849501 4.14612803567824 4.16136800223498 4.17609125905568 
##               19               25               19               19 
## 4.19033169817029 4.20411998265593 4.21748394421391 4.23044892137827 
##               20               14               10               17 
## 4.24303804868629 4.25527250510331 4.26717172840301 4.27875360095283 
##               20               11               20               38 
## 4.29003461136252 4.30102999566398 4.31175386105575 4.32221929473392 
##               24               97                2              166 
## 4.34242268082221 4.36172783601759 4.38021124171161 4.39794000867204 
##              230              214              160              143 
## 4.41497334797082 4.43136376415899 4.44715803134222 4.46239799789896 
##               86               91               81               75 
## 4.47712125471966 4.49136169383427 4.50514997831991 4.51851393987789 
##               80               67               69               73 
## 4.53147891704226 4.54406804435028 4.55630250076729   4.568201724067 
##               89               93              100               92 
## 4.57978359661681  4.5910646070265 4.60205999132796 4.61278385671974 
##               95              101               95               79 
##  4.6232492903979 4.63346845557959 4.64345267648619 4.65321251377534 
##               78               89               70               70 
## 4.66275783168157 4.67209785793572 4.67669360962487 4.68124123737559 
##               78               74               27               77 
## 4.69019608002851 4.69897000433602 4.70757017609794 4.72015930340596 
##               56              133               11              126 
## 4.74036268949424 4.75966784468963 4.77815125038364 4.79588001734407 
##              174              174              150              164 
## 4.81291335664286 4.82930377283103 4.84509804001426 4.86033800657099 
##              185              157              157              146 
##  4.8750612633917 4.88930170250631 4.90308998699194 4.91645394854993 
##              136              132              142              133 
## 4.92941892571429 4.94200805302231 4.95424250943933 4.96614173273903 
##              146              117              122               99 
## 4.97772360528885 4.98900461569854                5 5.01072386539177 
##              137              102              142               16 
## 5.02118929906994 5.04139268515823 5.06069784035361 5.07918124604763 
##              153              143              129              122 
## 5.09691001300806 5.11394335230684 5.13033376849501 5.14612803567824 
##              154              111               92               93 
## 5.16136800223498 5.17609125905568 5.19033169817029 5.20411998265593 
##               93              102               86               70 
## 5.21748394421391 5.23044892137827 5.24303804868629 5.25527250510331 
##               72               50               57               58 
## 5.26717172840301 5.27875360095283 5.29003461136252 5.30102999566398 
##               46               61               39               54 
## 5.31175386105575 5.32221929473392 5.34242268082221 5.36172783601759 
##                3               64               51               46 
## 5.38021124171161 5.39794000867204 5.41497334797082 5.43136376415899 
##               33               32               23               21 
## 5.44715803134222 5.46239799789896 5.47712125471966 5.49136169383427 
##               16               14                6                5 
## 5.50514997831991 5.51851393987789 5.53147891704226 5.54406804435028 
##                1                6                7                8 
## 5.55630250076729   5.568201724067 5.57978359661681  5.5910646070265 
##                5                7                8                4 
## 5.60205999132796 5.61278385671974  5.6232492903979 5.65321251377534 
##                4                4                1                2 
## 5.66275783168157 5.67209785793572 5.68124123737559 5.69897000433602 
##                5                7                7                6 
## 5.72015930340596 5.74036268949424 5.75966784468963 
##               10               12                3
## Before
print(table(atlantic_clean$education))
## 
##    1    2    3    4    5    6    7   99 
## 1075 2208 1084 2131  326 1547 1051 1841
atlantic_clean <- atlantic_clean %>%
  mutate(
    education_clean = case_when(
      education == 1 ~ "Less than high school",
      education == 2 ~ "High school diploma",
      education == 3 ~ "Trade certificate",
      education == 4 ~ "College/CEGEP diploma",
      education == 5 ~ "University below bachelor",
      education == 6 ~ "Bachelor's degree",
      education == 7 ~ "Above bachelor's degree",
      TRUE ~ NA_character_
    ),
    education_clean = factor(education_clean)
  )

## After
print(table(atlantic_clean$education_clean))
## 
##   Above bachelor's degree         Bachelor's degree     College/CEGEP diploma 
##                      1051                      1547                      2131 
##       High school diploma     Less than high school         Trade certificate 
##                      2208                      1075                      1084 
## University below bachelor 
##                       326

Now note that these are ordered alphabetically. Rank ordered categorical variables should be ordered for interpretability, setting the “lowest” rank/category as the reference category in modeling:

atlantic_clean <- atlantic_clean %>%
  mutate(
    education_grouped = case_when(
      education_clean %in% c("Less than high school", "High school diploma") ~ "High school or less",
      education_clean %in% c("Trade certificate", "College/CEGEP diploma") ~ "Post-secondary (non-university)",
      education_clean %in% c("University below bachelor", "Bachelor's degree", "Above bachelor's degree") ~ "University education",
      TRUE ~ NA_character_
    ),
    education_grouped = factor(education_grouped, levels = c("High school or less", 
                                                         "Post-secondary (non-university)", 
                                                         "University education"))
  )

## Check, always
print(table(atlantic_clean$education_grouped))
## 
##             High school or less Post-secondary (non-university) 
##                            3283                            3215 
##            University education 
##                            2924

Let’s continue:

## Before
print(table(atlantic_clean$immigration))
## 
##     9 
## 11263
atlantic_clean <- atlantic_clean %>%
  mutate(
    immigration_clean = case_when(
      immigration == 1 ~ "Canadian-born",
      immigration == 2 ~ "Immigrant/Non-permanent",
      TRUE ~ NA_character_
    ),
    immigration_clean = factor(immigration_clean)
  )

## After
print(table(atlantic_clean$immigration_clean))
## < table of extent 0 >

Again, not provided for Atlantic Canada!

atlantic_analysis <- atlantic_clean %>%
  filter(
    !is.na(satisfaction_clean),
    !is.na(log_income),
    !is.na(education_clean)
  )

print(nrow(atlantic_clean))
## [1] 11263
print(nrow(atlantic_analysis))
## [1] 7791
print(nrow(atlantic_clean) - nrow(atlantic_analysis))
## [1] 3472

Let us build models now:

model1 <- lm(satisfaction_clean ~ log_income, data = atlantic_analysis)
model2 <- lm(satisfaction_clean ~ log_income + education_grouped, data = atlantic_analysis)

tab_model(
  model1, model2, 
  dv.labels = c("Model 1: Income", "Model 2: + Education"),
  title = "Proper Models With Clean Data"
)
Proper Models With Clean Data
  Model 1: Income Model 2: + Education
Predictors Estimates CI p Estimates CI p
(Intercept) 6.25 5.60 – 6.91 <0.001 4.68 3.94 – 5.42 <0.001
log income 0.08 -0.06 – 0.21 0.272 0.48 0.32 – 0.64 <0.001
education grouped
[Post-secondary
(non-university)]
-0.48 -0.60 – -0.36 <0.001
education grouped
[University education]
-0.63 -0.77 – -0.50 <0.001
Observations 7791 7791
R2 / R2 adjusted 0.000 / 0.000 0.012 / 0.012

Here is a reminder how to clean up your table, which you can do directly in the tab_model function:

tab_model(
  model1, model2,
  dv.labels = c("Model 1: Income Only", "Model 2: Income + Education"),
  title = "Life Satisfaction in Atlantic Canada",
  pred.labels = c(
    "(Intercept)" = "Intercept",
    "log_income" = "Log Income (log10)",
    "education_groupedPost-secondary (non-university)" = "Education: Post-secondary",
    "education_groupedUniversity education" = "Education: University"
  ),
  show.reflvl = TRUE,
  p.style = "numeric"
)
Life Satisfaction in Atlantic Canada
  Model 1: Income Only Model 2: Income + Education
Predictors Estimates CI p Estimates CI p
Intercept 6.25 5.60 – 6.91 <0.001 4.68 3.94 – 5.42 <0.001
Log Income (log10) 0.08 -0.06 – 0.21 0.272 0.48 0.32 – 0.64 <0.001
Education: Post-secondary -0.48 -0.60 – -0.36 <0.001
Education: University -0.63 -0.77 – -0.50 <0.001
Observations 7791 7791
R2 / R2 adjusted 0.000 / 0.000 0.012 / 0.012

Lesson 3: Understanding interactions

First, let me simulate an example to explain:

set.seed(123)

n <- 500  
party_size <- sample(5:100, n, replace = TRUE)  
personality <- sample(c("Introvert", "Extrovert"), n, replace = TRUE) 
party_data <- data.frame(
  party_size = party_size,
  personality = personality
)

party_data$personality_num <- ifelse(party_data$personality == "Introvert", -1, 1)

base_enjoyment <- 50

introvert_slope <- -0.5  
extrovert_slope <- 0.3   
noise_sd <- 10          

party_data$enjoyment <- base_enjoyment + 
  (party_data$personality_num == -1) * introvert_slope * party_data$party_size +
  (party_data$personality_num == 1) * extrovert_slope * party_data$party_size +
  rnorm(n, mean = 0, sd = noise_sd)

party_data$enjoyment <- pmax(0, pmin(100, party_data$enjoyment))

model <- lm(enjoyment ~ party_size * personality, data = party_data)

ggplot(party_data, aes(x = party_size, y = enjoyment, color = personality)) +
  geom_point(alpha = 0.5) +
  geom_smooth(method = "lm", se = TRUE) +
  labs(
    title = "Party Enjoyment by Party Size and Personality Type",
    x = "Number of People at Party",
    y = "Enjoyment (0-100 scale)",
    color = "Personality Type"
  ) +
  theme_minimal() +
  scale_color_manual(values = c("Introvert" = "blue", "Extrovert" = "red"))

new_data <- expand.grid(
  party_size = seq(5, 100, by = 5),
  personality = c("Introvert", "Extrovert")
)
predictions <- predict(model, newdata = new_data, se.fit = TRUE)
new_data$predicted_enjoyment <- predictions$fit

ggplot(new_data, aes(x = party_size, y = predicted_enjoyment, color = personality, group = personality)) +
  geom_line(size = 1.5) +
  labs(
    title = "Predicted Party Enjoyment by Party Size and Personality Type",
    subtitle = "Illustration of Non-Parallel Lines (Interaction Effect)",
    x = "Number of People at Party",
    y = "Predicted Enjoyment (0-100 scale)",
    color = "Personality Type"
  ) +
  theme_minimal() +
  scale_color_manual(values = c("Introvert" = "blue", "Extrovert" = "red")) +
  annotate("text", x = 80, y = 30, label = "Introverts enjoy\nsmaller parties", color = "blue") +
  annotate("text", x = 80, y = 70, label = "Extroverts enjoy\nlarger parties", color = "red")

Let’s do another simulated example, leveraging a simulated example we did during Tutorial 6 (for MLR):

set.seed(123)
n <- 500
experience <- runif(n, 0, 30)  # Years of experience from 0-30

education <- sample(c("HS or Less", "College", "Graduate"), 
                    size = n, replace = TRUE, 
                    prob = c(0.4, 0.4, 0.2))  # Realistic distribution

income_mlr <- case_when(
  education == "HS or Less" ~ 25000 + 1200 * experience,
  education == "College" ~ 40000 + 1200 * experience,
  education == "Graduate" ~ 60000 + 1200 * experience
) + rnorm(n, 0, 10000)  # Add some random noise

income_interaction <- case_when(
  education == "HS or Less" ~ 25000 + 800 * experience,
  education == "College" ~ 40000 + 1200 * experience,
  education == "Graduate" ~ 60000 + 2000 * experience
) + rnorm(n, 0, 10000)  # Add some random noise

sim_data_mlr <- data.frame(
  Income = income_mlr,
  Experience = experience,
  Education = factor(education, levels = c("HS or Less", "College", "Graduate")),
  Model = "Multiple Linear Regression\n(Parallel Slopes)"
)

sim_data_interaction <- data.frame(
  Income = income_interaction,
  Experience = experience,
  Education = factor(education, levels = c("HS or Less", "College", "Graduate")),
  Model = "Interaction Model\n(Different Slopes)"
)

p1 <- ggplot(sim_data_mlr, aes(x = Experience, y = Income, color = Education)) +
  geom_point(alpha = 0.5) +
  geom_smooth(method = "lm", se = FALSE, linewidth = 1.2) +
  scale_y_continuous(labels = scales::dollar_format()) +
  scale_color_brewer(palette = "Set1") +
  theme_minimal(base_size = 12) +
  labs(
    title = "Multiple Linear Regression",
    subtitle = "Effect of experience is HELD CONSTANT across education levels\n(Experience slope doesn't depend on education)",
    x = "Years of Work Experience",
    y = "Annual Income",
    color = "Education Level"
  ) +
  theme(
    legend.position = "bottom",
    plot.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  ) +
  annotate("text", x = 25, y = 30000, label = "Reference Category", 
          color = "#E41A1C", fontface = "bold") +
  annotate("text", x = 25, y = 55000, 
          label = "β₂, College effect = +$15,000", color = "#377EB8") +
  annotate("text", x = 25, y = 80000, 
          label = "β₃, Graduate effect = +$35,000", color = "#4DAF4A") +
  annotate("text", x = 5, y = 90000, 
          label = "β₁ = +$1,200 per year\n(same for all groups)", 
          color = "black", fontface = "italic")

p2 <- ggplot(sim_data_interaction, aes(x = Experience, y = Income, color = Education)) +
  geom_point(alpha = 0.5) +
  geom_smooth(method = "lm", se = FALSE, linewidth = 1.2) +
  scale_y_continuous(labels = scales::dollar_format()) +
  scale_color_brewer(palette = "Set1") +
  theme_minimal(base_size = 12) +
  labs(
    title = "Interaction Model",
    subtitle = "Effect of experience is ALLOWED TO VARY by education level\n(Experience slope depends on education)",
    x = "Years of Work Experience",
    y = "Annual Income",
    color = "Education Level"
  ) +
  theme(
    legend.position = "bottom",
    plot.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  ) +
  annotate("text", x = 25, y = 30000, 
          label = "HS slope = +$800/year", 
          color = "#E41A1C", fontface = "bold") +
  annotate("text", x = 25, y = 60000, 
          label = "College slope = +$1,200/year", color = "#377EB8") +
  annotate("text", x = 25, y = 100000, 
          label = "Graduate slope = +$2,000/year", color = "#4DAF4A")

combined_plot <- p1 + p2 +
  plot_layout(guides = "collect") +
  plot_annotation(
    title = "Comparing Multiple Linear Regression vs. Interaction Effects",
    theme = theme(
      plot.title = element_text(face = "bold", size = 16),
      legend.position = "bottom"
    )
  )

combined_plot

Let’s use our real-world example from earlier to see a possible interaction modeled and then visualized:

model3 <- lm(satisfaction_clean ~ log_income + education_grouped + log_income * education_grouped, data = atlantic_analysis)

tab_model(
  model1, model2, model3,
  dv.labels = c("Model 1: Income Only", "Model 2: Main Effects", "Model 3: Interaction"),
  title = "Life Satisfaction in Atlantic Canada",
  pred.labels = c(
    "(Intercept)" = "Intercept",
    "log_income" = "Log Income (log10)",
    "education_groupedPost-secondary (non-university)" = "Education: Post-secondary",
    "education_groupedUniversity education" = "Education: University",
    "log_income:education_groupedPost-secondary (non-university)" = "Log Income × Post-secondary",
    "log_income:education_groupedUniversity education" = "Log Income × University"
  ),
  p.style = "numeric",
  digits = 2
)
Life Satisfaction in Atlantic Canada
  Model 1: Income Only Model 2: Main Effects Model 3: Interaction
Predictors Estimates CI p Estimates CI p Estimates CI p
Intercept 6.25 5.60 – 6.91 <0.001 4.68 3.94 – 5.42 <0.001 4.96 3.65 – 6.26 <0.001
Log Income (log10) 0.08 -0.06 – 0.21 0.272 0.48 0.32 – 0.64 <0.001 0.42 0.13 – 0.71 0.004
Education: Post-secondary -0.48 -0.60 – -0.36 <0.001 -0.97 -2.78 – 0.85 0.296
Education: University -0.63 -0.77 – -0.50 <0.001 -0.96 -2.92 – 0.99 0.334
Log Income ×
Post-secondary
0.10 -0.28 – 0.49 0.598
Log Income × University 0.07 -0.34 – 0.48 0.731
Observations 7791 7791 7791
R2 / R2 adjusted 0.000 / 0.000 0.012 / 0.012 0.012 / 0.012

Now let’s visualize:

plot_model(model3, type = "int", 
           axis.title = c("Log Income", "Life Satisfaction"),
           legend.title = "Education Level",
           title = "Interaction Between Income and Education on Life Satisfaction") +
  theme_minimal()

Let’s revisit our full Canada specification above:

model3 <- lm(outcome ~ log_income + education + visible_minority, data = chs_for_analysis)
summary(model3)
## 
## Call:
## lm(formula = outcome ~ log_income + education + visible_minority, 
##     data = chs_for_analysis)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.8930 -1.6130  0.2976  1.7448  4.2639 
## 
## Coefficients:
##                                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                          3.97730    0.24539  16.208  < 2e-16 ***
## log_income                           0.53884    0.05207  10.349  < 2e-16 ***
## educationHigh school diploma        -0.45692    0.06318  -7.232 4.97e-13 ***
## educationTrade certificate          -0.64664    0.07562  -8.551  < 2e-16 ***
## educationCollege/CEGEP diploma      -0.76111    0.06491 -11.725  < 2e-16 ***
## educationUniversity below bachelor  -0.57024    0.09065  -6.290 3.24e-10 ***
## educationBachelor's degree          -0.84646    0.06960 -12.163  < 2e-16 ***
## educationAbove bachelor's degree    -0.80487    0.07645 -10.528  < 2e-16 ***
## visible_minorityNo visible minority  0.21569    0.05070   4.254 2.11e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.17 on 17349 degrees of freedom
##   (23630 observations deleted due to missingness)
## Multiple R-squared:  0.01395,    Adjusted R-squared:  0.0135 
## F-statistic: 30.69 on 8 and 17349 DF,  p-value: < 2.2e-16
model4 <- lm(outcome ~ log_income + education + visible_minority + education*visible_minority, data = chs_for_analysis)
summary(model4)
## 
## Call:
## lm(formula = outcome ~ log_income + education + visible_minority + 
##     education * visible_minority, data = chs_for_analysis)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.9161 -1.5948  0.2954  1.7457  4.2920 
## 
## Coefficients:
##                                                                        Estimate
## (Intercept)                                                             3.37521
## log_income                                                              0.54296
## educationHigh school diploma                                            0.26447
## educationTrade certificate                                             -0.59678
## educationCollege/CEGEP diploma                                         -0.26389
## educationUniversity below bachelor                                      0.07138
## educationBachelor's degree                                             -0.28055
## educationAbove bachelor's degree                                       -0.10208
## visible_minorityNo visible minority                                     0.82030
## educationHigh school diploma:visible_minorityNo visible minority       -0.75196
## educationTrade certificate:visible_minorityNo visible minority         -0.04679
## educationCollege/CEGEP diploma:visible_minorityNo visible minority     -0.51026
## educationUniversity below bachelor:visible_minorityNo visible minority -0.67477
## educationBachelor's degree:visible_minorityNo visible minority         -0.58442
## educationAbove bachelor's degree:visible_minorityNo visible minority   -0.77655
##                                                                        Std. Error
## (Intercept)                                                               0.36397
## log_income                                                                0.05208
## educationHigh school diploma                                              0.31156
## educationTrade certificate                                                0.37376
## educationCollege/CEGEP diploma                                            0.29797
## educationUniversity below bachelor                                        0.33225
## educationBachelor's degree                                                0.28769
## educationAbove bachelor's degree                                          0.28943
## visible_minorityNo visible minority                                       0.28045
## educationHigh school diploma:visible_minorityNo visible minority          0.31794
## educationTrade certificate:visible_minorityNo visible minority            0.38110
## educationCollege/CEGEP diploma:visible_minorityNo visible minority        0.30444
## educationUniversity below bachelor:visible_minorityNo visible minority    0.34454
## educationBachelor's degree:visible_minorityNo visible minority            0.29459
## educationAbove bachelor's degree:visible_minorityNo visible minority      0.29805
##                                                                        t value
## (Intercept)                                                              9.273
## log_income                                                              10.425
## educationHigh school diploma                                             0.849
## educationTrade certificate                                              -1.597
## educationCollege/CEGEP diploma                                          -0.886
## educationUniversity below bachelor                                       0.215
## educationBachelor's degree                                              -0.975
## educationAbove bachelor's degree                                        -0.353
## visible_minorityNo visible minority                                      2.925
## educationHigh school diploma:visible_minorityNo visible minority        -2.365
## educationTrade certificate:visible_minorityNo visible minority          -0.123
## educationCollege/CEGEP diploma:visible_minorityNo visible minority      -1.676
## educationUniversity below bachelor:visible_minorityNo visible minority  -1.958
## educationBachelor's degree:visible_minorityNo visible minority          -1.984
## educationAbove bachelor's degree:visible_minorityNo visible minority    -2.605
##                                                                        Pr(>|t|)
## (Intercept)                                                             < 2e-16
## log_income                                                              < 2e-16
## educationHigh school diploma                                            0.39598
## educationTrade certificate                                              0.11036
## educationCollege/CEGEP diploma                                          0.37584
## educationUniversity below bachelor                                      0.82991
## educationBachelor's degree                                              0.32948
## educationAbove bachelor's degree                                        0.72433
## visible_minorityNo visible minority                                     0.00345
## educationHigh school diploma:visible_minorityNo visible minority        0.01804
## educationTrade certificate:visible_minorityNo visible minority          0.90228
## educationCollege/CEGEP diploma:visible_minorityNo visible minority      0.09374
## educationUniversity below bachelor:visible_minorityNo visible minority  0.05019
## educationBachelor's degree:visible_minorityNo visible minority          0.04729
## educationAbove bachelor's degree:visible_minorityNo visible minority    0.00918
##                                                                           
## (Intercept)                                                            ***
## log_income                                                             ***
## educationHigh school diploma                                              
## educationTrade certificate                                                
## educationCollege/CEGEP diploma                                            
## educationUniversity below bachelor                                        
## educationBachelor's degree                                                
## educationAbove bachelor's degree                                          
## visible_minorityNo visible minority                                    ** 
## educationHigh school diploma:visible_minorityNo visible minority       *  
## educationTrade certificate:visible_minorityNo visible minority            
## educationCollege/CEGEP diploma:visible_minorityNo visible minority     .  
## educationUniversity below bachelor:visible_minorityNo visible minority .  
## educationBachelor's degree:visible_minorityNo visible minority         *  
## educationAbove bachelor's degree:visible_minorityNo visible minority   ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.169 on 17343 degrees of freedom
##   (23630 observations deleted due to missingness)
## Multiple R-squared:  0.01475,    Adjusted R-squared:  0.01395 
## F-statistic: 18.54 on 14 and 17343 DF,  p-value: < 2.2e-16
plot_model(model4, type = "int", 
           axis.title = c("Minority", "Life Satisfaction"),
           legend.title = "Education Level",
           title = "Interaction Between Visible Minoirty and Education on Life Satisfaction") +
  theme_minimal()

Ok, let’s turn now to breaking down what it all means with our example:

Main Effects Interpretation:

  1. Log income (0.54296): For each unit increase in log income, life satisfaction increases by about 0.54 points on the 0-10 scale, holding all other variables constant. This is a strong, highly significant effect that persists regardless of education or visible minority status.

  2. Education main effects: These coefficients represent the relationship between education and life satisfaction specifically for visible minorities (the reference group). Interestingly, none of these education effects are statistically significant, suggesting that among visible minorities, different education levels don’t significantly predict different life satisfaction levels when controlling for income.

  3. Visible minority main effect (0.82030): This coefficient shows that non-visible minorities report life satisfaction 0.82 points higher than visible minorities, but only for those with less than high school education (the reference education category). This is a substantial difference on a 0-10 scale.

Understanding the Interaction:

The interaction terms represent how the effect of visible minority status changes across different education levels (or equivalently, how the effect of education differs between visible minority groups).

  1. Each interaction coefficient should be interpreted as a modification to the main effect of visible minority status:

    • For example, the interaction “High school diploma:visible minorityNo visible minority” (-0.75196) means that the visible minority gap of 0.82 is reduced by 0.75 for those with high school diplomas, resulting in a much smaller gap of about 0.07.
  2. For people with bachelor’s degrees, the visible minority effect is 0.82030 - 0.58442 = 0.24, and for those with above bachelor’s degrees, it’s 0.82030 - 0.77655 = 0.04.

  3. Pattern of diminishing returns: The higher the education level, the smaller the life satisfaction gap between visible minorities and non-visible minorities, with the gap nearly disappearing at the highest education level.

What This Means More “Sociologically”:

Conditional relationships: The effect of being a visible minority on life satisfaction is conditional on education level, and vice versa. We cannot accurately describe either effect without considering the other.

Income vs. education effects: Income has a direct positive relationship with life satisfaction regardless of other factors, while education’s relationship is more contingent on visible minority status. This suggests different pathways through which socioeconomic factors influence well-being.

But let’s actually explore another (i.e., don’t do that – the last lesson for today)

Lesson 4: Careful with your categories!!

model5 <- lm(outcome ~ log_income + region_name + education + education*region_name, data = chs_for_analysis)
summary(model5)
## 
## Call:
## lm(formula = outcome ~ log_income + region_name + education + 
##     education * region_name, data = chs_for_analysis)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.4669 -1.4844  0.2935  1.6887  4.8817 
## 
## Coefficients:
##                                                                                    Estimate
## (Intercept)                                                                        3.360677
## log_income                                                                         0.582711
## region_nameEdmonton                                                               -0.716353
## region_nameHalifax                                                                -0.030169
## region_nameHamilton                                                                0.527784
## region_nameKitchener-Cambridge-Waterloo                                            0.808561
## region_nameMontréal                                                                0.422703
## region_nameNewfoundland and Labrador                                               1.236706
## region_nameOther CMAs - British Columbia                                          -0.024259
## region_nameOther CMAs - Ontario                                                   -0.011729
## region_nameOther CMAs - Québec                                                     1.013762
## region_nameOttawa                                                                  0.043418
## region_nameOutside Calgary and Edmonton - AB                                       0.474175
## region_nameOutside CMAs - BC                                                       0.312253
## region_nameOutside CMAs - ON                                                       0.844245
## region_nameOutside CMAs - QC                                                       1.039526
## region_nameOutside Halifax - NS                                                    1.128664
## region_nameOutside Regina and Saskatoon - SK                                       1.065979
## region_nameOutside Saint John and Moncton - NB                                     1.286832
## region_nameOutside Winnipeg - MB                                                   0.726124
## region_namePrince Edward Island                                                    1.297902
## region_nameQuébec                                                                  0.749581
## region_nameRegina                                                                  1.057327
## region_nameSaint John and Moncton                                                  1.161891
## region_nameSaskatoon                                                               1.315830
## region_nameToronto                                                                -0.015222
## region_nameVancouver                                                              -0.178207
## region_nameWinnipeg                                                               -0.080440
## educationHigh school diploma                                                      -0.378238
## educationTrade certificate                                                        -1.385703
## educationCollege/CEGEP diploma                                                    -0.405437
## educationUniversity below bachelor                                                -0.396915
## educationBachelor's degree                                                        -0.690267
## educationAbove bachelor's degree                                                  -0.454181
## region_nameEdmonton:educationHigh school diploma                                   0.578440
## region_nameHalifax:educationHigh school diploma                                    0.201931
## region_nameHamilton:educationHigh school diploma                                  -0.081710
## region_nameKitchener-Cambridge-Waterloo:educationHigh school diploma              -0.727729
## region_nameMontréal:educationHigh school diploma                                   0.342605
## region_nameNewfoundland and Labrador:educationHigh school diploma                  0.126660
## region_nameOther CMAs - British Columbia:educationHigh school diploma              0.405638
## region_nameOther CMAs - Ontario:educationHigh school diploma                       0.244034
## region_nameOther CMAs - Québec:educationHigh school diploma                        0.018507
## region_nameOttawa:educationHigh school diploma                                     0.157064
## region_nameOutside Calgary and Edmonton - AB:educationHigh school diploma         -0.338303
## region_nameOutside CMAs - BC:educationHigh school diploma                          0.201596
## region_nameOutside CMAs - ON:educationHigh school diploma                         -0.098375
## region_nameOutside CMAs - QC:educationHigh school diploma                          0.055250
## region_nameOutside Halifax - NS:educationHigh school diploma                       0.111967
## region_nameOutside Regina and Saskatoon - SK:educationHigh school diploma         -0.261347
## region_nameOutside Saint John and Moncton - NB:educationHigh school diploma       -0.130886
## region_nameOutside Winnipeg - MB:educationHigh school diploma                      0.194296
## region_namePrince Edward Island:educationHigh school diploma                      -0.070403
## region_nameQuébec:educationHigh school diploma                                     0.355531
## region_nameRegina:educationHigh school diploma                                    -0.850508
## region_nameSaint John and Moncton:educationHigh school diploma                    -0.432494
## region_nameSaskatoon:educationHigh school diploma                                 -0.576276
## region_nameToronto:educationHigh school diploma                                    0.277673
## region_nameVancouver:educationHigh school diploma                                  0.425888
## region_nameWinnipeg:educationHigh school diploma                                   0.398698
## region_nameEdmonton:educationTrade certificate                                     1.752819
## region_nameHalifax:educationTrade certificate                                      1.511489
## region_nameHamilton:educationTrade certificate                                     1.015832
## region_nameKitchener-Cambridge-Waterloo:educationTrade certificate                 0.407855
## region_nameMontréal:educationTrade certificate                                     0.607620
## region_nameNewfoundland and Labrador:educationTrade certificate                    0.779852
## region_nameOther CMAs - British Columbia:educationTrade certificate                1.108463
## region_nameOther CMAs - Ontario:educationTrade certificate                         0.806722
## region_nameOther CMAs - Québec:educationTrade certificate                          0.583512
## region_nameOttawa:educationTrade certificate                                       2.074894
## region_nameOutside Calgary and Edmonton - AB:educationTrade certificate            0.554606
## region_nameOutside CMAs - BC:educationTrade certificate                            1.195058
## region_nameOutside CMAs - ON:educationTrade certificate                            0.907094
## region_nameOutside CMAs - QC:educationTrade certificate                            0.890380
## region_nameOutside Halifax - NS:educationTrade certificate                         1.175012
## region_nameOutside Regina and Saskatoon - SK:educationTrade certificate            0.489329
## region_nameOutside Saint John and Moncton - NB:educationTrade certificate          0.752128
## region_nameOutside Winnipeg - MB:educationTrade certificate                        1.063651
## region_namePrince Edward Island:educationTrade certificate                         1.389829
## region_nameQuébec:educationTrade certificate                                       1.050157
## region_nameRegina:educationTrade certificate                                       0.233095
## region_nameSaint John and Moncton:educationTrade certificate                       0.509539
## region_nameSaskatoon:educationTrade certificate                                   -0.265538
## region_nameToronto:educationTrade certificate                                      0.851421
## region_nameVancouver:educationTrade certificate                                    0.792243
## region_nameWinnipeg:educationTrade certificate                                     1.318158
## region_nameEdmonton:educationCollege/CEGEP diploma                                 0.903285
## region_nameHalifax:educationCollege/CEGEP diploma                                 -0.162963
## region_nameHamilton:educationCollege/CEGEP diploma                                -0.428640
## region_nameKitchener-Cambridge-Waterloo:educationCollege/CEGEP diploma            -0.973006
## region_nameMontréal:educationCollege/CEGEP diploma                                 0.025604
## region_nameNewfoundland and Labrador:educationCollege/CEGEP diploma               -0.440656
## region_nameOther CMAs - British Columbia:educationCollege/CEGEP diploma            0.126645
## region_nameOther CMAs - Ontario:educationCollege/CEGEP diploma                    -0.018516
## region_nameOther CMAs - Québec:educationCollege/CEGEP diploma                     -0.452663
## region_nameOttawa:educationCollege/CEGEP diploma                                   0.143241
## region_nameOutside Calgary and Edmonton - AB:educationCollege/CEGEP diploma       -0.326346
## region_nameOutside CMAs - BC:educationCollege/CEGEP diploma                        0.001937
## region_nameOutside CMAs - ON:educationCollege/CEGEP diploma                       -0.360215
## region_nameOutside CMAs - QC:educationCollege/CEGEP diploma                       -0.458483
## region_nameOutside Halifax - NS:educationCollege/CEGEP diploma                    -0.463662
## region_nameOutside Regina and Saskatoon - SK:educationCollege/CEGEP diploma       -0.494783
## region_nameOutside Saint John and Moncton - NB:educationCollege/CEGEP diploma     -0.474196
## region_nameOutside Winnipeg - MB:educationCollege/CEGEP diploma                   -0.209600
## region_namePrince Edward Island:educationCollege/CEGEP diploma                    -0.472814
## region_nameQuébec:educationCollege/CEGEP diploma                                  -0.635295
## region_nameRegina:educationCollege/CEGEP diploma                                  -1.220464
## region_nameSaint John and Moncton:educationCollege/CEGEP diploma                  -0.895082
## region_nameSaskatoon:educationCollege/CEGEP diploma                               -1.305483
## region_nameToronto:educationCollege/CEGEP diploma                                 -0.265296
## region_nameVancouver:educationCollege/CEGEP diploma                                0.214531
## region_nameWinnipeg:educationCollege/CEGEP diploma                                 0.052874
## region_nameEdmonton:educationUniversity below bachelor                             0.722366
## region_nameHalifax:educationUniversity below bachelor                              0.464645
## region_nameHamilton:educationUniversity below bachelor                            -0.578580
## region_nameKitchener-Cambridge-Waterloo:educationUniversity below bachelor        -0.793299
## region_nameMontréal:educationUniversity below bachelor                            -0.218663
## region_nameNewfoundland and Labrador:educationUniversity below bachelor           -0.255653
## region_nameOther CMAs - British Columbia:educationUniversity below bachelor       -0.087632
## region_nameOther CMAs - Ontario:educationUniversity below bachelor                 0.827796
## region_nameOther CMAs - Québec:educationUniversity below bachelor                  0.011558
## region_nameOttawa:educationUniversity below bachelor                              -0.079111
## region_nameOutside Calgary and Edmonton - AB:educationUniversity below bachelor   -0.129292
## region_nameOutside CMAs - BC:educationUniversity below bachelor                   -0.003305
## region_nameOutside CMAs - ON:educationUniversity below bachelor                   -0.224466
## region_nameOutside CMAs - QC:educationUniversity below bachelor                   -0.127225
## region_nameOutside Halifax - NS:educationUniversity below bachelor                -0.462931
## region_nameOutside Regina and Saskatoon - SK:educationUniversity below bachelor   -0.280321
## region_nameOutside Saint John and Moncton - NB:educationUniversity below bachelor  0.370064
## region_nameOutside Winnipeg - MB:educationUniversity below bachelor                0.346282
## region_namePrince Edward Island:educationUniversity below bachelor                -0.165135
## region_nameQuébec:educationUniversity below bachelor                               0.383713
## region_nameRegina:educationUniversity below bachelor                              -0.099681
## region_nameSaint John and Moncton:educationUniversity below bachelor              -0.562720
## region_nameSaskatoon:educationUniversity below bachelor                           -2.058714
## region_nameToronto:educationUniversity below bachelor                              0.454621
## region_nameVancouver:educationUniversity below bachelor                            0.397534
## region_nameWinnipeg:educationUniversity below bachelor                             0.302437
## region_nameEdmonton:educationBachelor's degree                                     0.943996
## region_nameHalifax:educationBachelor's degree                                      0.604541
## region_nameHamilton:educationBachelor's degree                                    -0.002948
## region_nameKitchener-Cambridge-Waterloo:educationBachelor's degree                -0.603139
## region_nameMontréal:educationBachelor's degree                                     0.057819
## region_nameNewfoundland and Labrador:educationBachelor's degree                   -0.375255
## region_nameOther CMAs - British Columbia:educationBachelor's degree                0.115807
## region_nameOther CMAs - Ontario:educationBachelor's degree                         0.175273
## region_nameOther CMAs - Québec:educationBachelor's degree                         -0.426374
## region_nameOttawa:educationBachelor's degree                                       0.216617
## region_nameOutside Calgary and Edmonton - AB:educationBachelor's degree            0.047115
## region_nameOutside CMAs - BC:educationBachelor's degree                            0.483035
## region_nameOutside CMAs - ON:educationBachelor's degree                           -0.098619
## region_nameOutside CMAs - QC:educationBachelor's degree                           -0.191437
## region_nameOutside Halifax - NS:educationBachelor's degree                        -0.102320
## region_nameOutside Regina and Saskatoon - SK:educationBachelor's degree           -0.019438
## region_nameOutside Saint John and Moncton - NB:educationBachelor's degree         -0.378750
## region_nameOutside Winnipeg - MB:educationBachelor's degree                       -0.215500
## region_namePrince Edward Island:educationBachelor's degree                        -0.304154
## region_nameQuébec:educationBachelor's degree                                       0.085685
## region_nameRegina:educationBachelor's degree                                      -0.505601
## region_nameSaint John and Moncton:educationBachelor's degree                      -0.463741
## region_nameSaskatoon:educationBachelor's degree                                   -1.345224
## region_nameToronto:educationBachelor's degree                                      0.117618
## region_nameVancouver:educationBachelor's degree                                    0.216078
## region_nameWinnipeg:educationBachelor's degree                                     0.606155
## region_nameEdmonton:educationAbove bachelor's degree                               0.636559
## region_nameHalifax:educationAbove bachelor's degree                               -0.007806
## region_nameHamilton:educationAbove bachelor's degree                              -0.288214
## region_nameKitchener-Cambridge-Waterloo:educationAbove bachelor's degree          -0.859503
## region_nameMontréal:educationAbove bachelor's degree                              -0.323177
## region_nameNewfoundland and Labrador:educationAbove bachelor's degree             -0.783154
## region_nameOther CMAs - British Columbia:educationAbove bachelor's degree          0.201062
## region_nameOther CMAs - Ontario:educationAbove bachelor's degree                   0.475285
## region_nameOther CMAs - Québec:educationAbove bachelor's degree                   -0.858816
## region_nameOttawa:educationAbove bachelor's degree                                 0.041993
## region_nameOutside Calgary and Edmonton - AB:educationAbove bachelor's degree     -0.248466
## region_nameOutside CMAs - BC:educationAbove bachelor's degree                      0.311210
## region_nameOutside CMAs - ON:educationAbove bachelor's degree                      0.038800
## region_nameOutside CMAs - QC:educationAbove bachelor's degree                     -0.592508
## region_nameOutside Halifax - NS:educationAbove bachelor's degree                  -0.176844
## region_nameOutside Regina and Saskatoon - SK:educationAbove bachelor's degree     -0.499975
## region_nameOutside Saint John and Moncton - NB:educationAbove bachelor's degree   -0.563087
## region_nameOutside Winnipeg - MB:educationAbove bachelor's degree                 -0.329436
## region_namePrince Edward Island:educationAbove bachelor's degree                  -0.186067
## region_nameQuébec:educationAbove bachelor's degree                                -0.389339
## region_nameRegina:educationAbove bachelor's degree                                -0.876154
## region_nameSaint John and Moncton:educationAbove bachelor's degree                -0.697831
## region_nameSaskatoon:educationAbove bachelor's degree                             -1.176836
## region_nameToronto:educationAbove bachelor's degree                               -0.101546
## region_nameVancouver:educationAbove bachelor's degree                              0.098249
## region_nameWinnipeg:educationAbove bachelor's degree                               0.397011
##                                                                                   Std. Error
## (Intercept)                                                                         0.421952
## log_income                                                                          0.040403
## region_nameEdmonton                                                                 0.516904
## region_nameHalifax                                                                  0.543697
## region_nameHamilton                                                                 0.485290
## region_nameKitchener-Cambridge-Waterloo                                             0.469551
## region_nameMontréal                                                                 0.431667
## region_nameNewfoundland and Labrador                                                0.405948
## region_nameOther CMAs - British Columbia                                            0.534974
## region_nameOther CMAs - Ontario                                                     0.463356
## region_nameOther CMAs - Québec                                                      0.423089
## region_nameOttawa                                                                   0.500175
## region_nameOutside Calgary and Edmonton - AB                                        0.409493
## region_nameOutside CMAs - BC                                                        0.417889
## region_nameOutside CMAs - ON                                                        0.403038
## region_nameOutside CMAs - QC                                                        0.394656
## region_nameOutside Halifax - NS                                                     0.408323
## region_nameOutside Regina and Saskatoon - SK                                        0.410755
## region_nameOutside Saint John and Moncton - NB                                      0.410325
## region_nameOutside Winnipeg - MB                                                    0.409220
## region_namePrince Edward Island                                                     0.425270
## region_nameQuébec                                                                   0.430405
## region_nameRegina                                                                   0.510801
## region_nameSaint John and Moncton                                                   0.418832
## region_nameSaskatoon                                                                0.629067
## region_nameToronto                                                                  0.476775
## region_nameVancouver                                                                0.479997
## region_nameWinnipeg                                                                 0.466967
## educationHigh school diploma                                                        0.423769
## educationTrade certificate                                                          0.478510
## educationCollege/CEGEP diploma                                                      0.420309
## educationUniversity below bachelor                                                  0.482074
## educationBachelor's degree                                                          0.406197
## educationAbove bachelor's degree                                                    0.417510
## region_nameEdmonton:educationHigh school diploma                                    0.572693
## region_nameHalifax:educationHigh school diploma                                     0.602805
## region_nameHamilton:educationHigh school diploma                                    0.550951
## region_nameKitchener-Cambridge-Waterloo:educationHigh school diploma                0.535976
## region_nameMontréal:educationHigh school diploma                                    0.490977
## region_nameNewfoundland and Labrador:educationHigh school diploma                   0.459957
## region_nameOther CMAs - British Columbia:educationHigh school diploma               0.590644
## region_nameOther CMAs - Ontario:educationHigh school diploma                        0.517940
## region_nameOther CMAs - Québec:educationHigh school diploma                         0.483840
## region_nameOttawa:educationHigh school diploma                                      0.571699
## region_nameOutside Calgary and Edmonton - AB:educationHigh school diploma           0.458971
## region_nameOutside CMAs - BC:educationHigh school diploma                           0.469614
## region_nameOutside CMAs - ON:educationHigh school diploma                           0.452794
## region_nameOutside CMAs - QC:educationHigh school diploma                           0.446589
## region_nameOutside Halifax - NS:educationHigh school diploma                        0.462778
## region_nameOutside Regina and Saskatoon - SK:educationHigh school diploma           0.465723
## region_nameOutside Saint John and Moncton - NB:educationHigh school diploma         0.463057
## region_nameOutside Winnipeg - MB:educationHigh school diploma                       0.462616
## region_namePrince Edward Island:educationHigh school diploma                        0.486368
## region_nameQuébec:educationHigh school diploma                                      0.497911
## region_nameRegina:educationHigh school diploma                                      0.577285
## region_nameSaint John and Moncton:educationHigh school diploma                      0.471900
## region_nameSaskatoon:educationHigh school diploma                                   0.701751
## region_nameToronto:educationHigh school diploma                                     0.540670
## region_nameVancouver:educationHigh school diploma                                   0.542388
## region_nameWinnipeg:educationHigh school diploma                                    0.525157
## region_nameEdmonton:educationTrade certificate                                      0.631722
## region_nameHalifax:educationTrade certificate                                       0.669642
## region_nameHamilton:educationTrade certificate                                      0.671955
## region_nameKitchener-Cambridge-Waterloo:educationTrade certificate                  0.620011
## region_nameMontréal:educationTrade certificate                                      0.575053
## region_nameNewfoundland and Labrador:educationTrade certificate                     0.513048
## region_nameOther CMAs - British Columbia:educationTrade certificate                 0.662553
## region_nameOther CMAs - Ontario:educationTrade certificate                          0.626129
## region_nameOther CMAs - Québec:educationTrade certificate                           0.545835
## region_nameOttawa:educationTrade certificate                                        0.796295
## region_nameOutside Calgary and Edmonton - AB:educationTrade certificate             0.515475
## region_nameOutside CMAs - BC:educationTrade certificate                             0.528622
## region_nameOutside CMAs - ON:educationTrade certificate                             0.519866
## region_nameOutside CMAs - QC:educationTrade certificate                             0.506435
## region_nameOutside Halifax - NS:educationTrade certificate                          0.518097
## region_nameOutside Regina and Saskatoon - SK:educationTrade certificate             0.525371
## region_nameOutside Saint John and Moncton - NB:educationTrade certificate           0.534038
## region_nameOutside Winnipeg - MB:educationTrade certificate                         0.538612
## region_namePrince Edward Island:educationTrade certificate                          0.587177
## region_nameQuébec:educationTrade certificate                                        0.581404
## region_nameRegina:educationTrade certificate                                        0.640848
## region_nameSaint John and Moncton:educationTrade certificate                        0.541298
## region_nameSaskatoon:educationTrade certificate                                     0.753372
## region_nameToronto:educationTrade certificate                                       0.682753
## region_nameVancouver:educationTrade certificate                                     0.618165
## region_nameWinnipeg:educationTrade certificate                                      0.624402
## region_nameEdmonton:educationCollege/CEGEP diploma                                  0.575460
## region_nameHalifax:educationCollege/CEGEP diploma                                   0.598865
## region_nameHamilton:educationCollege/CEGEP diploma                                  0.542437
## region_nameKitchener-Cambridge-Waterloo:educationCollege/CEGEP diploma              0.528396
## region_nameMontréal:educationCollege/CEGEP diploma                                  0.490681
## region_nameNewfoundland and Labrador:educationCollege/CEGEP diploma                 0.455574
## region_nameOther CMAs - British Columbia:educationCollege/CEGEP diploma             0.585813
## region_nameOther CMAs - Ontario:educationCollege/CEGEP diploma                      0.511458
## region_nameOther CMAs - Québec:educationCollege/CEGEP diploma                       0.479608
## region_nameOttawa:educationCollege/CEGEP diploma                                    0.562791
## region_nameOutside Calgary and Edmonton - AB:educationCollege/CEGEP diploma         0.455722
## region_nameOutside CMAs - BC:educationCollege/CEGEP diploma                         0.469510
## region_nameOutside CMAs - ON:educationCollege/CEGEP diploma                         0.448731
## region_nameOutside CMAs - QC:educationCollege/CEGEP diploma                         0.446524
## region_nameOutside Halifax - NS:educationCollege/CEGEP diploma                      0.462316
## region_nameOutside Regina and Saskatoon - SK:educationCollege/CEGEP diploma         0.466638
## region_nameOutside Saint John and Moncton - NB:educationCollege/CEGEP diploma       0.462425
## region_nameOutside Winnipeg - MB:educationCollege/CEGEP diploma                     0.462459
## region_namePrince Edward Island:educationCollege/CEGEP diploma                      0.479393
## region_nameQuébec:educationCollege/CEGEP diploma                                    0.488392
## region_nameRegina:educationCollege/CEGEP diploma                                    0.593394
## region_nameSaint John and Moncton:educationCollege/CEGEP diploma                    0.467989
## region_nameSaskatoon:educationCollege/CEGEP diploma                                 0.692708
## region_nameToronto:educationCollege/CEGEP diploma                                   0.531876
## region_nameVancouver:educationCollege/CEGEP diploma                                 0.535529
## region_nameWinnipeg:educationCollege/CEGEP diploma                                  0.528759
## region_nameEdmonton:educationUniversity below bachelor                              0.669129
## region_nameHalifax:educationUniversity below bachelor                               0.733242
## region_nameHamilton:educationUniversity below bachelor                              0.747890
## region_nameKitchener-Cambridge-Waterloo:educationUniversity below bachelor          0.729699
## region_nameMontréal:educationUniversity below bachelor                              0.576471
## region_nameNewfoundland and Labrador:educationUniversity below bachelor             0.560402
## region_nameOther CMAs - British Columbia:educationUniversity below bachelor         0.696815
## region_nameOther CMAs - Ontario:educationUniversity below bachelor                  0.650547
## region_nameOther CMAs - Québec:educationUniversity below bachelor                   0.585968
## region_nameOttawa:educationUniversity below bachelor                                0.670449
## region_nameOutside Calgary and Edmonton - AB:educationUniversity below bachelor     0.543422
## region_nameOutside CMAs - BC:educationUniversity below bachelor                     0.550133
## region_nameOutside CMAs - ON:educationUniversity below bachelor                     0.552671
## region_nameOutside CMAs - QC:educationUniversity below bachelor                     0.541871
## region_nameOutside Halifax - NS:educationUniversity below bachelor                  0.568091
## region_nameOutside Regina and Saskatoon - SK:educationUniversity below bachelor     0.563132
## region_nameOutside Saint John and Moncton - NB:educationUniversity below bachelor   0.616605
## region_nameOutside Winnipeg - MB:educationUniversity below bachelor                 0.562010
## region_namePrince Edward Island:educationUniversity below bachelor                  0.604551
## region_nameQuébec:educationUniversity below bachelor                                0.615828
## region_nameRegina:educationUniversity below bachelor                                0.687577
## region_nameSaint John and Moncton:educationUniversity below bachelor                0.698169
## region_nameSaskatoon:educationUniversity below bachelor                             0.805787
## region_nameToronto:educationUniversity below bachelor                               0.620000
## region_nameVancouver:educationUniversity below bachelor                             0.611638
## region_nameWinnipeg:educationUniversity below bachelor                              0.670945
## region_nameEdmonton:educationBachelor's degree                                      0.560298
## region_nameHalifax:educationBachelor's degree                                       0.582164
## region_nameHamilton:educationBachelor's degree                                      0.539938
## region_nameKitchener-Cambridge-Waterloo:educationBachelor's degree                  0.528302
## region_nameMontréal:educationBachelor's degree                                      0.472902
## region_nameNewfoundland and Labrador:educationBachelor's degree                     0.449190
## region_nameOther CMAs - British Columbia:educationBachelor's degree                 0.577314
## region_nameOther CMAs - Ontario:educationBachelor's degree                          0.510365
## region_nameOther CMAs - Québec:educationBachelor's degree                           0.473284
## region_nameOttawa:educationBachelor's degree                                        0.540082
## region_nameOutside Calgary and Edmonton - AB:educationBachelor's degree             0.445775
## region_nameOutside CMAs - BC:educationBachelor's degree                             0.461704
## region_nameOutside CMAs - ON:educationBachelor's degree                             0.446186
## region_nameOutside CMAs - QC:educationBachelor's degree                             0.438939
## region_nameOutside Halifax - NS:educationBachelor's degree                          0.461871
## region_nameOutside Regina and Saskatoon - SK:educationBachelor's degree             0.461367
## region_nameOutside Saint John and Moncton - NB:educationBachelor's degree           0.455312
## region_nameOutside Winnipeg - MB:educationBachelor's degree                         0.453065
## region_namePrince Edward Island:educationBachelor's degree                          0.474034
## region_nameQuébec:educationBachelor's degree                                        0.477695
## region_nameRegina:educationBachelor's degree                                        0.557956
## region_nameSaint John and Moncton:educationBachelor's degree                        0.460629
## region_nameSaskatoon:educationBachelor's degree                                     0.668417
## region_nameToronto:educationBachelor's degree                                       0.512090
## region_nameVancouver:educationBachelor's degree                                     0.514708
## region_nameWinnipeg:educationBachelor's degree                                      0.508453
## region_nameEdmonton:educationAbove bachelor's degree                                0.579760
## region_nameHalifax:educationAbove bachelor's degree                                 0.594788
## region_nameHamilton:educationAbove bachelor's degree                                0.564624
## region_nameKitchener-Cambridge-Waterloo:educationAbove bachelor's degree            0.536348
## region_nameMontréal:educationAbove bachelor's degree                                0.486270
## region_nameNewfoundland and Labrador:educationAbove bachelor's degree               0.465817
## region_nameOther CMAs - British Columbia:educationAbove bachelor's degree           0.591629
## region_nameOther CMAs - Ontario:educationAbove bachelor's degree                    0.526239
## region_nameOther CMAs - Québec:educationAbove bachelor's degree                     0.498313
## region_nameOttawa:educationAbove bachelor's degree                                  0.549869
## region_nameOutside Calgary and Edmonton - AB:educationAbove bachelor's degree       0.474248
## region_nameOutside CMAs - BC:educationAbove bachelor's degree                       0.477076
## region_nameOutside CMAs - ON:educationAbove bachelor's degree                       0.473457
## region_nameOutside CMAs - QC:educationAbove bachelor's degree                       0.483908
## region_nameOutside Halifax - NS:educationAbove bachelor's degree                    0.482969
## region_nameOutside Regina and Saskatoon - SK:educationAbove bachelor's degree       0.512223
## region_nameOutside Saint John and Moncton - NB:educationAbove bachelor's degree     0.483691
## region_nameOutside Winnipeg - MB:educationAbove bachelor's degree                   0.512900
## region_namePrince Edward Island:educationAbove bachelor's degree                    0.494658
## region_nameQuébec:educationAbove bachelor's degree                                  0.499074
## region_nameRegina:educationAbove bachelor's degree                                  0.586700
## region_nameSaint John and Moncton:educationAbove bachelor's degree                  0.479240
## region_nameSaskatoon:educationAbove bachelor's degree                               0.689831
## region_nameToronto:educationAbove bachelor's degree                                 0.524663
## region_nameVancouver:educationAbove bachelor's degree                               0.529145
## region_nameWinnipeg:educationAbove bachelor's degree                                0.535072
##                                                                                   t value
## (Intercept)                                                                         7.965
## log_income                                                                         14.423
## region_nameEdmonton                                                                -1.386
## region_nameHalifax                                                                 -0.055
## region_nameHamilton                                                                 1.088
## region_nameKitchener-Cambridge-Waterloo                                             1.722
## region_nameMontréal                                                                 0.979
## region_nameNewfoundland and Labrador                                                3.046
## region_nameOther CMAs - British Columbia                                           -0.045
## region_nameOther CMAs - Ontario                                                    -0.025
## region_nameOther CMAs - Québec                                                      2.396
## region_nameOttawa                                                                   0.087
## region_nameOutside Calgary and Edmonton - AB                                        1.158
## region_nameOutside CMAs - BC                                                        0.747
## region_nameOutside CMAs - ON                                                        2.095
## region_nameOutside CMAs - QC                                                        2.634
## region_nameOutside Halifax - NS                                                     2.764
## region_nameOutside Regina and Saskatoon - SK                                        2.595
## region_nameOutside Saint John and Moncton - NB                                      3.136
## region_nameOutside Winnipeg - MB                                                    1.774
## region_namePrince Edward Island                                                     3.052
## region_nameQuébec                                                                   1.742
## region_nameRegina                                                                   2.070
## region_nameSaint John and Moncton                                                   2.774
## region_nameSaskatoon                                                                2.092
## region_nameToronto                                                                 -0.032
## region_nameVancouver                                                               -0.371
## region_nameWinnipeg                                                                -0.172
## educationHigh school diploma                                                       -0.893
## educationTrade certificate                                                         -2.896
## educationCollege/CEGEP diploma                                                     -0.965
## educationUniversity below bachelor                                                 -0.823
## educationBachelor's degree                                                         -1.699
## educationAbove bachelor's degree                                                   -1.088
## region_nameEdmonton:educationHigh school diploma                                    1.010
## region_nameHalifax:educationHigh school diploma                                     0.335
## region_nameHamilton:educationHigh school diploma                                   -0.148
## region_nameKitchener-Cambridge-Waterloo:educationHigh school diploma               -1.358
## region_nameMontréal:educationHigh school diploma                                    0.698
## region_nameNewfoundland and Labrador:educationHigh school diploma                   0.275
## region_nameOther CMAs - British Columbia:educationHigh school diploma               0.687
## region_nameOther CMAs - Ontario:educationHigh school diploma                        0.471
## region_nameOther CMAs - Québec:educationHigh school diploma                         0.038
## region_nameOttawa:educationHigh school diploma                                      0.275
## region_nameOutside Calgary and Edmonton - AB:educationHigh school diploma          -0.737
## region_nameOutside CMAs - BC:educationHigh school diploma                           0.429
## region_nameOutside CMAs - ON:educationHigh school diploma                          -0.217
## region_nameOutside CMAs - QC:educationHigh school diploma                           0.124
## region_nameOutside Halifax - NS:educationHigh school diploma                        0.242
## region_nameOutside Regina and Saskatoon - SK:educationHigh school diploma          -0.561
## region_nameOutside Saint John and Moncton - NB:educationHigh school diploma        -0.283
## region_nameOutside Winnipeg - MB:educationHigh school diploma                       0.420
## region_namePrince Edward Island:educationHigh school diploma                       -0.145
## region_nameQuébec:educationHigh school diploma                                      0.714
## region_nameRegina:educationHigh school diploma                                     -1.473
## region_nameSaint John and Moncton:educationHigh school diploma                     -0.916
## region_nameSaskatoon:educationHigh school diploma                                  -0.821
## region_nameToronto:educationHigh school diploma                                     0.514
## region_nameVancouver:educationHigh school diploma                                   0.785
## region_nameWinnipeg:educationHigh school diploma                                    0.759
## region_nameEdmonton:educationTrade certificate                                      2.775
## region_nameHalifax:educationTrade certificate                                       2.257
## region_nameHamilton:educationTrade certificate                                      1.512
## region_nameKitchener-Cambridge-Waterloo:educationTrade certificate                  0.658
## region_nameMontréal:educationTrade certificate                                      1.057
## region_nameNewfoundland and Labrador:educationTrade certificate                     1.520
## region_nameOther CMAs - British Columbia:educationTrade certificate                 1.673
## region_nameOther CMAs - Ontario:educationTrade certificate                          1.288
## region_nameOther CMAs - Québec:educationTrade certificate                           1.069
## region_nameOttawa:educationTrade certificate                                        2.606
## region_nameOutside Calgary and Edmonton - AB:educationTrade certificate             1.076
## region_nameOutside CMAs - BC:educationTrade certificate                             2.261
## region_nameOutside CMAs - ON:educationTrade certificate                             1.745
## region_nameOutside CMAs - QC:educationTrade certificate                             1.758
## region_nameOutside Halifax - NS:educationTrade certificate                          2.268
## region_nameOutside Regina and Saskatoon - SK:educationTrade certificate             0.931
## region_nameOutside Saint John and Moncton - NB:educationTrade certificate           1.408
## region_nameOutside Winnipeg - MB:educationTrade certificate                         1.975
## region_namePrince Edward Island:educationTrade certificate                          2.367
## region_nameQuébec:educationTrade certificate                                        1.806
## region_nameRegina:educationTrade certificate                                        0.364
## region_nameSaint John and Moncton:educationTrade certificate                        0.941
## region_nameSaskatoon:educationTrade certificate                                    -0.352
## region_nameToronto:educationTrade certificate                                       1.247
## region_nameVancouver:educationTrade certificate                                     1.282
## region_nameWinnipeg:educationTrade certificate                                      2.111
## region_nameEdmonton:educationCollege/CEGEP diploma                                  1.570
## region_nameHalifax:educationCollege/CEGEP diploma                                  -0.272
## region_nameHamilton:educationCollege/CEGEP diploma                                 -0.790
## region_nameKitchener-Cambridge-Waterloo:educationCollege/CEGEP diploma             -1.841
## region_nameMontréal:educationCollege/CEGEP diploma                                  0.052
## region_nameNewfoundland and Labrador:educationCollege/CEGEP diploma                -0.967
## region_nameOther CMAs - British Columbia:educationCollege/CEGEP diploma             0.216
## region_nameOther CMAs - Ontario:educationCollege/CEGEP diploma                     -0.036
## region_nameOther CMAs - Québec:educationCollege/CEGEP diploma                      -0.944
## region_nameOttawa:educationCollege/CEGEP diploma                                    0.255
## region_nameOutside Calgary and Edmonton - AB:educationCollege/CEGEP diploma        -0.716
## region_nameOutside CMAs - BC:educationCollege/CEGEP diploma                         0.004
## region_nameOutside CMAs - ON:educationCollege/CEGEP diploma                        -0.803
## region_nameOutside CMAs - QC:educationCollege/CEGEP diploma                        -1.027
## region_nameOutside Halifax - NS:educationCollege/CEGEP diploma                     -1.003
## region_nameOutside Regina and Saskatoon - SK:educationCollege/CEGEP diploma        -1.060
## region_nameOutside Saint John and Moncton - NB:educationCollege/CEGEP diploma      -1.025
## region_nameOutside Winnipeg - MB:educationCollege/CEGEP diploma                    -0.453
## region_namePrince Edward Island:educationCollege/CEGEP diploma                     -0.986
## region_nameQuébec:educationCollege/CEGEP diploma                                   -1.301
## region_nameRegina:educationCollege/CEGEP diploma                                   -2.057
## region_nameSaint John and Moncton:educationCollege/CEGEP diploma                   -1.913
## region_nameSaskatoon:educationCollege/CEGEP diploma                                -1.885
## region_nameToronto:educationCollege/CEGEP diploma                                  -0.499
## region_nameVancouver:educationCollege/CEGEP diploma                                 0.401
## region_nameWinnipeg:educationCollege/CEGEP diploma                                  0.100
## region_nameEdmonton:educationUniversity below bachelor                              1.080
## region_nameHalifax:educationUniversity below bachelor                               0.634
## region_nameHamilton:educationUniversity below bachelor                             -0.774
## region_nameKitchener-Cambridge-Waterloo:educationUniversity below bachelor         -1.087
## region_nameMontréal:educationUniversity below bachelor                             -0.379
## region_nameNewfoundland and Labrador:educationUniversity below bachelor            -0.456
## region_nameOther CMAs - British Columbia:educationUniversity below bachelor        -0.126
## region_nameOther CMAs - Ontario:educationUniversity below bachelor                  1.272
## region_nameOther CMAs - Québec:educationUniversity below bachelor                   0.020
## region_nameOttawa:educationUniversity below bachelor                               -0.118
## region_nameOutside Calgary and Edmonton - AB:educationUniversity below bachelor    -0.238
## region_nameOutside CMAs - BC:educationUniversity below bachelor                    -0.006
## region_nameOutside CMAs - ON:educationUniversity below bachelor                    -0.406
## region_nameOutside CMAs - QC:educationUniversity below bachelor                    -0.235
## region_nameOutside Halifax - NS:educationUniversity below bachelor                 -0.815
## region_nameOutside Regina and Saskatoon - SK:educationUniversity below bachelor    -0.498
## region_nameOutside Saint John and Moncton - NB:educationUniversity below bachelor   0.600
## region_nameOutside Winnipeg - MB:educationUniversity below bachelor                 0.616
## region_namePrince Edward Island:educationUniversity below bachelor                 -0.273
## region_nameQuébec:educationUniversity below bachelor                                0.623
## region_nameRegina:educationUniversity below bachelor                               -0.145
## region_nameSaint John and Moncton:educationUniversity below bachelor               -0.806
## region_nameSaskatoon:educationUniversity below bachelor                            -2.555
## region_nameToronto:educationUniversity below bachelor                               0.733
## region_nameVancouver:educationUniversity below bachelor                             0.650
## region_nameWinnipeg:educationUniversity below bachelor                              0.451
## region_nameEdmonton:educationBachelor's degree                                      1.685
## region_nameHalifax:educationBachelor's degree                                       1.038
## region_nameHamilton:educationBachelor's degree                                     -0.005
## region_nameKitchener-Cambridge-Waterloo:educationBachelor's degree                 -1.142
## region_nameMontréal:educationBachelor's degree                                      0.122
## region_nameNewfoundland and Labrador:educationBachelor's degree                    -0.835
## region_nameOther CMAs - British Columbia:educationBachelor's degree                 0.201
## region_nameOther CMAs - Ontario:educationBachelor's degree                          0.343
## region_nameOther CMAs - Québec:educationBachelor's degree                          -0.901
## region_nameOttawa:educationBachelor's degree                                        0.401
## region_nameOutside Calgary and Edmonton - AB:educationBachelor's degree             0.106
## region_nameOutside CMAs - BC:educationBachelor's degree                             1.046
## region_nameOutside CMAs - ON:educationBachelor's degree                            -0.221
## region_nameOutside CMAs - QC:educationBachelor's degree                            -0.436
## region_nameOutside Halifax - NS:educationBachelor's degree                         -0.222
## region_nameOutside Regina and Saskatoon - SK:educationBachelor's degree            -0.042
## region_nameOutside Saint John and Moncton - NB:educationBachelor's degree          -0.832
## region_nameOutside Winnipeg - MB:educationBachelor's degree                        -0.476
## region_namePrince Edward Island:educationBachelor's degree                         -0.642
## region_nameQuébec:educationBachelor's degree                                        0.179
## region_nameRegina:educationBachelor's degree                                       -0.906
## region_nameSaint John and Moncton:educationBachelor's degree                       -1.007
## region_nameSaskatoon:educationBachelor's degree                                    -2.013
## region_nameToronto:educationBachelor's degree                                       0.230
## region_nameVancouver:educationBachelor's degree                                     0.420
## region_nameWinnipeg:educationBachelor's degree                                      1.192
## region_nameEdmonton:educationAbove bachelor's degree                                1.098
## region_nameHalifax:educationAbove bachelor's degree                                -0.013
## region_nameHamilton:educationAbove bachelor's degree                               -0.510
## region_nameKitchener-Cambridge-Waterloo:educationAbove bachelor's degree           -1.603
## region_nameMontréal:educationAbove bachelor's degree                               -0.665
## region_nameNewfoundland and Labrador:educationAbove bachelor's degree              -1.681
## region_nameOther CMAs - British Columbia:educationAbove bachelor's degree           0.340
## region_nameOther CMAs - Ontario:educationAbove bachelor's degree                    0.903
## region_nameOther CMAs - Québec:educationAbove bachelor's degree                    -1.723
## region_nameOttawa:educationAbove bachelor's degree                                  0.076
## region_nameOutside Calgary and Edmonton - AB:educationAbove bachelor's degree      -0.524
## region_nameOutside CMAs - BC:educationAbove bachelor's degree                       0.652
## region_nameOutside CMAs - ON:educationAbove bachelor's degree                       0.082
## region_nameOutside CMAs - QC:educationAbove bachelor's degree                      -1.224
## region_nameOutside Halifax - NS:educationAbove bachelor's degree                   -0.366
## region_nameOutside Regina and Saskatoon - SK:educationAbove bachelor's degree      -0.976
## region_nameOutside Saint John and Moncton - NB:educationAbove bachelor's degree    -1.164
## region_nameOutside Winnipeg - MB:educationAbove bachelor's degree                  -0.642
## region_namePrince Edward Island:educationAbove bachelor's degree                   -0.376
## region_nameQuébec:educationAbove bachelor's degree                                 -0.780
## region_nameRegina:educationAbove bachelor's degree                                 -1.493
## region_nameSaint John and Moncton:educationAbove bachelor's degree                 -1.456
## region_nameSaskatoon:educationAbove bachelor's degree                              -1.706
## region_nameToronto:educationAbove bachelor's degree                                -0.194
## region_nameVancouver:educationAbove bachelor's degree                               0.186
## region_nameWinnipeg:educationAbove bachelor's degree                                0.742
##                                                                                   Pr(>|t|)
## (Intercept)                                                                       1.72e-15
## log_income                                                                         < 2e-16
## region_nameEdmonton                                                                0.16580
## region_nameHalifax                                                                 0.95575
## region_nameHamilton                                                                0.27680
## region_nameKitchener-Cambridge-Waterloo                                            0.08508
## region_nameMontréal                                                                0.32747
## region_nameNewfoundland and Labrador                                               0.00232
## region_nameOther CMAs - British Columbia                                           0.96383
## region_nameOther CMAs - Ontario                                                    0.97981
## region_nameOther CMAs - Québec                                                     0.01658
## region_nameOttawa                                                                  0.93083
## region_nameOutside Calgary and Edmonton - AB                                       0.24689
## region_nameOutside CMAs - BC                                                       0.45494
## region_nameOutside CMAs - ON                                                       0.03621
## region_nameOutside CMAs - QC                                                       0.00844
## region_nameOutside Halifax - NS                                                    0.00571
## region_nameOutside Regina and Saskatoon - SK                                       0.00946
## region_nameOutside Saint John and Moncton - NB                                     0.00171
## region_nameOutside Winnipeg - MB                                                   0.07601
## region_namePrince Edward Island                                                    0.00228
## region_nameQuébec                                                                  0.08159
## region_nameRegina                                                                  0.03847
## region_nameSaint John and Moncton                                                  0.00554
## region_nameSaskatoon                                                               0.03647
## region_nameToronto                                                                 0.97453
## region_nameVancouver                                                               0.71044
## region_nameWinnipeg                                                                0.86323
## educationHigh school diploma                                                       0.37210
## educationTrade certificate                                                         0.00378
## educationCollege/CEGEP diploma                                                     0.33474
## educationUniversity below bachelor                                                 0.41032
## educationBachelor's degree                                                         0.08927
## educationAbove bachelor's degree                                                   0.27668
## region_nameEdmonton:educationHigh school diploma                                   0.31249
## region_nameHalifax:educationHigh school diploma                                    0.73764
## region_nameHamilton:educationHigh school diploma                                   0.88210
## region_nameKitchener-Cambridge-Waterloo:educationHigh school diploma               0.17455
## region_nameMontréal:educationHigh school diploma                                   0.48531
## region_nameNewfoundland and Labrador:educationHigh school diploma                  0.78303
## region_nameOther CMAs - British Columbia:educationHigh school diploma              0.49223
## region_nameOther CMAs - Ontario:educationHigh school diploma                       0.63753
## region_nameOther CMAs - Québec:educationHigh school diploma                        0.96949
## region_nameOttawa:educationHigh school diploma                                     0.78352
## region_nameOutside Calgary and Edmonton - AB:educationHigh school diploma          0.46107
## region_nameOutside CMAs - BC:educationHigh school diploma                          0.66772
## region_nameOutside CMAs - ON:educationHigh school diploma                          0.82801
## region_nameOutside CMAs - QC:educationHigh school diploma                          0.90154
## region_nameOutside Halifax - NS:educationHigh school diploma                       0.80882
## region_nameOutside Regina and Saskatoon - SK:educationHigh school diploma          0.57469
## region_nameOutside Saint John and Moncton - NB:educationHigh school diploma        0.77744
## region_nameOutside Winnipeg - MB:educationHigh school diploma                      0.67449
## region_namePrince Edward Island:educationHigh school diploma                       0.88491
## region_nameQuébec:educationHigh school diploma                                     0.47521
## region_nameRegina:educationHigh school diploma                                     0.14068
## region_nameSaint John and Moncton:educationHigh school diploma                     0.35941
## region_nameSaskatoon:educationHigh school diploma                                  0.41154
## region_nameToronto:educationHigh school diploma                                    0.60756
## region_nameVancouver:educationHigh school diploma                                  0.43234
## region_nameWinnipeg:educationHigh school diploma                                   0.44774
## region_nameEdmonton:educationTrade certificate                                     0.00553
## region_nameHalifax:educationTrade certificate                                      0.02401
## region_nameHamilton:educationTrade certificate                                     0.13061
## region_nameKitchener-Cambridge-Waterloo:educationTrade certificate                 0.51066
## region_nameMontréal:educationTrade certificate                                     0.29069
## region_nameNewfoundland and Labrador:educationTrade certificate                    0.12851
## region_nameOther CMAs - British Columbia:educationTrade certificate                0.09433
## region_nameOther CMAs - Ontario:educationTrade certificate                         0.19761
## region_nameOther CMAs - Québec:educationTrade certificate                          0.28507
## region_nameOttawa:educationTrade certificate                                       0.00917
## region_nameOutside Calgary and Edmonton - AB:educationTrade certificate            0.28198
## region_nameOutside CMAs - BC:educationTrade certificate                            0.02378
## region_nameOutside CMAs - ON:educationTrade certificate                            0.08102
## region_nameOutside CMAs - QC:educationTrade certificate                            0.07874
## region_nameOutside Halifax - NS:educationTrade certificate                         0.02334
## region_nameOutside Regina and Saskatoon - SK:educationTrade certificate            0.35166
## region_nameOutside Saint John and Moncton - NB:educationTrade certificate          0.15903
## region_nameOutside Winnipeg - MB:educationTrade certificate                        0.04830
## region_namePrince Edward Island:educationTrade certificate                         0.01794
## region_nameQuébec:educationTrade certificate                                       0.07089
## region_nameRegina:educationTrade certificate                                       0.71606
## region_nameSaint John and Moncton:educationTrade certificate                       0.34654
## region_nameSaskatoon:educationTrade certificate                                    0.72449
## region_nameToronto:educationTrade certificate                                      0.21239
## region_nameVancouver:educationTrade certificate                                    0.19999
## region_nameWinnipeg:educationTrade certificate                                     0.03477
## region_nameEdmonton:educationCollege/CEGEP diploma                                 0.11650
## region_nameHalifax:educationCollege/CEGEP diploma                                  0.78553
## region_nameHamilton:educationCollege/CEGEP diploma                                 0.42941
## region_nameKitchener-Cambridge-Waterloo:educationCollege/CEGEP diploma             0.06557
## region_nameMontréal:educationCollege/CEGEP diploma                                 0.95838
## region_nameNewfoundland and Labrador:educationCollege/CEGEP diploma                0.33342
## region_nameOther CMAs - British Columbia:educationCollege/CEGEP diploma            0.82884
## region_nameOther CMAs - Ontario:educationCollege/CEGEP diploma                     0.97112
## region_nameOther CMAs - Québec:educationCollege/CEGEP diploma                      0.34527
## region_nameOttawa:educationCollege/CEGEP diploma                                   0.79910
## region_nameOutside Calgary and Edmonton - AB:educationCollege/CEGEP diploma        0.47393
## region_nameOutside CMAs - BC:educationCollege/CEGEP diploma                        0.99671
## region_nameOutside CMAs - ON:educationCollege/CEGEP diploma                        0.42213
## region_nameOutside CMAs - QC:educationCollege/CEGEP diploma                        0.30453
## region_nameOutside Halifax - NS:educationCollege/CEGEP diploma                     0.31591
## region_nameOutside Regina and Saskatoon - SK:educationCollege/CEGEP diploma        0.28901
## region_nameOutside Saint John and Moncton - NB:educationCollege/CEGEP diploma      0.30516
## region_nameOutside Winnipeg - MB:educationCollege/CEGEP diploma                    0.65039
## region_namePrince Edward Island:educationCollege/CEGEP diploma                     0.32400
## region_nameQuébec:educationCollege/CEGEP diploma                                   0.19334
## region_nameRegina:educationCollege/CEGEP diploma                                   0.03972
## region_nameSaint John and Moncton:educationCollege/CEGEP diploma                   0.05581
## region_nameSaskatoon:educationCollege/CEGEP diploma                                0.05949
## region_nameToronto:educationCollege/CEGEP diploma                                  0.61793
## region_nameVancouver:educationCollege/CEGEP diploma                                0.68872
## region_nameWinnipeg:educationCollege/CEGEP diploma                                 0.92035
## region_nameEdmonton:educationUniversity below bachelor                             0.28035
## region_nameHalifax:educationUniversity below bachelor                              0.52629
## region_nameHamilton:educationUniversity below bachelor                             0.43916
## region_nameKitchener-Cambridge-Waterloo:educationUniversity below bachelor         0.27697
## region_nameMontréal:educationUniversity below bachelor                             0.70446
## region_nameNewfoundland and Labrador:educationUniversity below bachelor            0.64825
## region_nameOther CMAs - British Columbia:educationUniversity below bachelor        0.89992
## region_nameOther CMAs - Ontario:educationUniversity below bachelor                 0.20322
## region_nameOther CMAs - Québec:educationUniversity below bachelor                  0.98426
## region_nameOttawa:educationUniversity below bachelor                               0.90607
## region_nameOutside Calgary and Edmonton - AB:educationUniversity below bachelor    0.81194
## region_nameOutside CMAs - BC:educationUniversity below bachelor                    0.99521
## region_nameOutside CMAs - ON:educationUniversity below bachelor                    0.68464
## region_nameOutside CMAs - QC:educationUniversity below bachelor                    0.81437
## region_nameOutside Halifax - NS:educationUniversity below bachelor                 0.41514
## region_nameOutside Regina and Saskatoon - SK:educationUniversity below bachelor    0.61864
## region_nameOutside Saint John and Moncton - NB:educationUniversity below bachelor  0.54840
## region_nameOutside Winnipeg - MB:educationUniversity below bachelor                0.53780
## region_namePrince Edward Island:educationUniversity below bachelor                 0.78474
## region_nameQuébec:educationUniversity below bachelor                               0.53323
## region_nameRegina:educationUniversity below bachelor                               0.88473
## region_nameSaint John and Moncton:educationUniversity below bachelor               0.42025
## region_nameSaskatoon:educationUniversity below bachelor                            0.01063
## region_nameToronto:educationUniversity below bachelor                              0.46341
## region_nameVancouver:educationUniversity below bachelor                            0.51573
## region_nameWinnipeg:educationUniversity below bachelor                             0.65216
## region_nameEdmonton:educationBachelor's degree                                     0.09204
## region_nameHalifax:educationBachelor's degree                                      0.29907
## region_nameHamilton:educationBachelor's degree                                     0.99564
## region_nameKitchener-Cambridge-Waterloo:educationBachelor's degree                 0.25361
## region_nameMontréal:educationBachelor's degree                                     0.90269
## region_nameNewfoundland and Labrador:educationBachelor's degree                    0.40350
## region_nameOther CMAs - British Columbia:educationBachelor's degree                0.84102
## region_nameOther CMAs - Ontario:educationBachelor's degree                         0.73128
## region_nameOther CMAs - Québec:educationBachelor's degree                          0.36766
## region_nameOttawa:educationBachelor's degree                                       0.68836
## region_nameOutside Calgary and Edmonton - AB:educationBachelor's degree            0.91583
## region_nameOutside CMAs - BC:educationBachelor's degree                            0.29548
## region_nameOutside CMAs - ON:educationBachelor's degree                            0.82507
## region_nameOutside CMAs - QC:educationBachelor's degree                            0.66274
## region_nameOutside Halifax - NS:educationBachelor's degree                         0.82468
## region_nameOutside Regina and Saskatoon - SK:educationBachelor's degree            0.96639
## region_nameOutside Saint John and Moncton - NB:educationBachelor's degree          0.40550
## region_nameOutside Winnipeg - MB:educationBachelor's degree                        0.63433
## region_namePrince Edward Island:educationBachelor's degree                         0.52112
## region_nameQuébec:educationBachelor's degree                                       0.85765
## region_nameRegina:educationBachelor's degree                                       0.36485
## region_nameSaint John and Moncton:educationBachelor's degree                       0.31406
## region_nameSaskatoon:educationBachelor's degree                                    0.04417
## region_nameToronto:educationBachelor's degree                                      0.81834
## region_nameVancouver:educationBachelor's degree                                    0.67463
## region_nameWinnipeg:educationBachelor's degree                                     0.23321
## region_nameEdmonton:educationAbove bachelor's degree                               0.27223
## region_nameHalifax:educationAbove bachelor's degree                                0.98953
## region_nameHamilton:educationAbove bachelor's degree                               0.60974
## region_nameKitchener-Cambridge-Waterloo:educationAbove bachelor's degree           0.10905
## region_nameMontréal:educationAbove bachelor's degree                               0.50631
## region_nameNewfoundland and Labrador:educationAbove bachelor's degree              0.09273
## region_nameOther CMAs - British Columbia:educationAbove bachelor's degree          0.73398
## region_nameOther CMAs - Ontario:educationAbove bachelor's degree                   0.36644
## region_nameOther CMAs - Québec:educationAbove bachelor's degree                    0.08482
## region_nameOttawa:educationAbove bachelor's degree                                 0.93913
## region_nameOutside Calgary and Edmonton - AB:educationAbove bachelor's degree      0.60034
## region_nameOutside CMAs - BC:educationAbove bachelor's degree                      0.51420
## region_nameOutside CMAs - ON:educationAbove bachelor's degree                      0.93469
## region_nameOutside CMAs - QC:educationAbove bachelor's degree                      0.22080
## region_nameOutside Halifax - NS:educationAbove bachelor's degree                   0.71425
## region_nameOutside Regina and Saskatoon - SK:educationAbove bachelor's degree      0.32903
## region_nameOutside Saint John and Moncton - NB:educationAbove bachelor's degree    0.24437
## region_nameOutside Winnipeg - MB:educationAbove bachelor's degree                  0.52068
## region_namePrince Edward Island:educationAbove bachelor's degree                   0.70681
## region_nameQuébec:educationAbove bachelor's degree                                 0.43532
## region_nameRegina:educationAbove bachelor's degree                                 0.13535
## region_nameSaint John and Moncton:educationAbove bachelor's degree                 0.14537
## region_nameSaskatoon:educationAbove bachelor's degree                              0.08802
## region_nameToronto:educationAbove bachelor's degree                                0.84653
## region_nameVancouver:educationAbove bachelor's degree                              0.85270
## region_nameWinnipeg:educationAbove bachelor's degree                               0.45811
##                                                                                      
## (Intercept)                                                                       ***
## log_income                                                                        ***
## region_nameEdmonton                                                                  
## region_nameHalifax                                                                   
## region_nameHamilton                                                                  
## region_nameKitchener-Cambridge-Waterloo                                           .  
## region_nameMontréal                                                                  
## region_nameNewfoundland and Labrador                                              ** 
## region_nameOther CMAs - British Columbia                                             
## region_nameOther CMAs - Ontario                                                      
## region_nameOther CMAs - Québec                                                    *  
## region_nameOttawa                                                                    
## region_nameOutside Calgary and Edmonton - AB                                         
## region_nameOutside CMAs - BC                                                         
## region_nameOutside CMAs - ON                                                      *  
## region_nameOutside CMAs - QC                                                      ** 
## region_nameOutside Halifax - NS                                                   ** 
## region_nameOutside Regina and Saskatoon - SK                                      ** 
## region_nameOutside Saint John and Moncton - NB                                    ** 
## region_nameOutside Winnipeg - MB                                                  .  
## region_namePrince Edward Island                                                   ** 
## region_nameQuébec                                                                 .  
## region_nameRegina                                                                 *  
## region_nameSaint John and Moncton                                                 ** 
## region_nameSaskatoon                                                              *  
## region_nameToronto                                                                   
## region_nameVancouver                                                                 
## region_nameWinnipeg                                                                  
## educationHigh school diploma                                                         
## educationTrade certificate                                                        ** 
## educationCollege/CEGEP diploma                                                       
## educationUniversity below bachelor                                                   
## educationBachelor's degree                                                        .  
## educationAbove bachelor's degree                                                     
## region_nameEdmonton:educationHigh school diploma                                     
## region_nameHalifax:educationHigh school diploma                                      
## region_nameHamilton:educationHigh school diploma                                     
## region_nameKitchener-Cambridge-Waterloo:educationHigh school diploma                 
## region_nameMontréal:educationHigh school diploma                                     
## region_nameNewfoundland and Labrador:educationHigh school diploma                    
## region_nameOther CMAs - British Columbia:educationHigh school diploma                
## region_nameOther CMAs - Ontario:educationHigh school diploma                         
## region_nameOther CMAs - Québec:educationHigh school diploma                          
## region_nameOttawa:educationHigh school diploma                                       
## region_nameOutside Calgary and Edmonton - AB:educationHigh school diploma            
## region_nameOutside CMAs - BC:educationHigh school diploma                            
## region_nameOutside CMAs - ON:educationHigh school diploma                            
## region_nameOutside CMAs - QC:educationHigh school diploma                            
## region_nameOutside Halifax - NS:educationHigh school diploma                         
## region_nameOutside Regina and Saskatoon - SK:educationHigh school diploma            
## region_nameOutside Saint John and Moncton - NB:educationHigh school diploma          
## region_nameOutside Winnipeg - MB:educationHigh school diploma                        
## region_namePrince Edward Island:educationHigh school diploma                         
## region_nameQuébec:educationHigh school diploma                                       
## region_nameRegina:educationHigh school diploma                                       
## region_nameSaint John and Moncton:educationHigh school diploma                       
## region_nameSaskatoon:educationHigh school diploma                                    
## region_nameToronto:educationHigh school diploma                                      
## region_nameVancouver:educationHigh school diploma                                    
## region_nameWinnipeg:educationHigh school diploma                                     
## region_nameEdmonton:educationTrade certificate                                    ** 
## region_nameHalifax:educationTrade certificate                                     *  
## region_nameHamilton:educationTrade certificate                                       
## region_nameKitchener-Cambridge-Waterloo:educationTrade certificate                   
## region_nameMontréal:educationTrade certificate                                       
## region_nameNewfoundland and Labrador:educationTrade certificate                      
## region_nameOther CMAs - British Columbia:educationTrade certificate               .  
## region_nameOther CMAs - Ontario:educationTrade certificate                           
## region_nameOther CMAs - Québec:educationTrade certificate                            
## region_nameOttawa:educationTrade certificate                                      ** 
## region_nameOutside Calgary and Edmonton - AB:educationTrade certificate              
## region_nameOutside CMAs - BC:educationTrade certificate                           *  
## region_nameOutside CMAs - ON:educationTrade certificate                           .  
## region_nameOutside CMAs - QC:educationTrade certificate                           .  
## region_nameOutside Halifax - NS:educationTrade certificate                        *  
## region_nameOutside Regina and Saskatoon - SK:educationTrade certificate              
## region_nameOutside Saint John and Moncton - NB:educationTrade certificate            
## region_nameOutside Winnipeg - MB:educationTrade certificate                       *  
## region_namePrince Edward Island:educationTrade certificate                        *  
## region_nameQuébec:educationTrade certificate                                      .  
## region_nameRegina:educationTrade certificate                                         
## region_nameSaint John and Moncton:educationTrade certificate                         
## region_nameSaskatoon:educationTrade certificate                                      
## region_nameToronto:educationTrade certificate                                        
## region_nameVancouver:educationTrade certificate                                      
## region_nameWinnipeg:educationTrade certificate                                    *  
## region_nameEdmonton:educationCollege/CEGEP diploma                                   
## region_nameHalifax:educationCollege/CEGEP diploma                                    
## region_nameHamilton:educationCollege/CEGEP diploma                                   
## region_nameKitchener-Cambridge-Waterloo:educationCollege/CEGEP diploma            .  
## region_nameMontréal:educationCollege/CEGEP diploma                                   
## region_nameNewfoundland and Labrador:educationCollege/CEGEP diploma                  
## region_nameOther CMAs - British Columbia:educationCollege/CEGEP diploma              
## region_nameOther CMAs - Ontario:educationCollege/CEGEP diploma                       
## region_nameOther CMAs - Québec:educationCollege/CEGEP diploma                        
## region_nameOttawa:educationCollege/CEGEP diploma                                     
## region_nameOutside Calgary and Edmonton - AB:educationCollege/CEGEP diploma          
## region_nameOutside CMAs - BC:educationCollege/CEGEP diploma                          
## region_nameOutside CMAs - ON:educationCollege/CEGEP diploma                          
## region_nameOutside CMAs - QC:educationCollege/CEGEP diploma                          
## region_nameOutside Halifax - NS:educationCollege/CEGEP diploma                       
## region_nameOutside Regina and Saskatoon - SK:educationCollege/CEGEP diploma          
## region_nameOutside Saint John and Moncton - NB:educationCollege/CEGEP diploma        
## region_nameOutside Winnipeg - MB:educationCollege/CEGEP diploma                      
## region_namePrince Edward Island:educationCollege/CEGEP diploma                       
## region_nameQuébec:educationCollege/CEGEP diploma                                     
## region_nameRegina:educationCollege/CEGEP diploma                                  *  
## region_nameSaint John and Moncton:educationCollege/CEGEP diploma                  .  
## region_nameSaskatoon:educationCollege/CEGEP diploma                               .  
## region_nameToronto:educationCollege/CEGEP diploma                                    
## region_nameVancouver:educationCollege/CEGEP diploma                                  
## region_nameWinnipeg:educationCollege/CEGEP diploma                                   
## region_nameEdmonton:educationUniversity below bachelor                               
## region_nameHalifax:educationUniversity below bachelor                                
## region_nameHamilton:educationUniversity below bachelor                               
## region_nameKitchener-Cambridge-Waterloo:educationUniversity below bachelor           
## region_nameMontréal:educationUniversity below bachelor                               
## region_nameNewfoundland and Labrador:educationUniversity below bachelor              
## region_nameOther CMAs - British Columbia:educationUniversity below bachelor          
## region_nameOther CMAs - Ontario:educationUniversity below bachelor                   
## region_nameOther CMAs - Québec:educationUniversity below bachelor                    
## region_nameOttawa:educationUniversity below bachelor                                 
## region_nameOutside Calgary and Edmonton - AB:educationUniversity below bachelor      
## region_nameOutside CMAs - BC:educationUniversity below bachelor                      
## region_nameOutside CMAs - ON:educationUniversity below bachelor                      
## region_nameOutside CMAs - QC:educationUniversity below bachelor                      
## region_nameOutside Halifax - NS:educationUniversity below bachelor                   
## region_nameOutside Regina and Saskatoon - SK:educationUniversity below bachelor      
## region_nameOutside Saint John and Moncton - NB:educationUniversity below bachelor    
## region_nameOutside Winnipeg - MB:educationUniversity below bachelor                  
## region_namePrince Edward Island:educationUniversity below bachelor                   
## region_nameQuébec:educationUniversity below bachelor                                 
## region_nameRegina:educationUniversity below bachelor                                 
## region_nameSaint John and Moncton:educationUniversity below bachelor                 
## region_nameSaskatoon:educationUniversity below bachelor                           *  
## region_nameToronto:educationUniversity below bachelor                                
## region_nameVancouver:educationUniversity below bachelor                              
## region_nameWinnipeg:educationUniversity below bachelor                               
## region_nameEdmonton:educationBachelor's degree                                    .  
## region_nameHalifax:educationBachelor's degree                                        
## region_nameHamilton:educationBachelor's degree                                       
## region_nameKitchener-Cambridge-Waterloo:educationBachelor's degree                   
## region_nameMontréal:educationBachelor's degree                                       
## region_nameNewfoundland and Labrador:educationBachelor's degree                      
## region_nameOther CMAs - British Columbia:educationBachelor's degree                  
## region_nameOther CMAs - Ontario:educationBachelor's degree                           
## region_nameOther CMAs - Québec:educationBachelor's degree                            
## region_nameOttawa:educationBachelor's degree                                         
## region_nameOutside Calgary and Edmonton - AB:educationBachelor's degree              
## region_nameOutside CMAs - BC:educationBachelor's degree                              
## region_nameOutside CMAs - ON:educationBachelor's degree                              
## region_nameOutside CMAs - QC:educationBachelor's degree                              
## region_nameOutside Halifax - NS:educationBachelor's degree                           
## region_nameOutside Regina and Saskatoon - SK:educationBachelor's degree              
## region_nameOutside Saint John and Moncton - NB:educationBachelor's degree            
## region_nameOutside Winnipeg - MB:educationBachelor's degree                          
## region_namePrince Edward Island:educationBachelor's degree                           
## region_nameQuébec:educationBachelor's degree                                         
## region_nameRegina:educationBachelor's degree                                         
## region_nameSaint John and Moncton:educationBachelor's degree                         
## region_nameSaskatoon:educationBachelor's degree                                   *  
## region_nameToronto:educationBachelor's degree                                        
## region_nameVancouver:educationBachelor's degree                                      
## region_nameWinnipeg:educationBachelor's degree                                       
## region_nameEdmonton:educationAbove bachelor's degree                                 
## region_nameHalifax:educationAbove bachelor's degree                                  
## region_nameHamilton:educationAbove bachelor's degree                                 
## region_nameKitchener-Cambridge-Waterloo:educationAbove bachelor's degree             
## region_nameMontréal:educationAbove bachelor's degree                                 
## region_nameNewfoundland and Labrador:educationAbove bachelor's degree             .  
## region_nameOther CMAs - British Columbia:educationAbove bachelor's degree            
## region_nameOther CMAs - Ontario:educationAbove bachelor's degree                     
## region_nameOther CMAs - Québec:educationAbove bachelor's degree                   .  
## region_nameOttawa:educationAbove bachelor's degree                                   
## region_nameOutside Calgary and Edmonton - AB:educationAbove bachelor's degree        
## region_nameOutside CMAs - BC:educationAbove bachelor's degree                        
## region_nameOutside CMAs - ON:educationAbove bachelor's degree                        
## region_nameOutside CMAs - QC:educationAbove bachelor's degree                        
## region_nameOutside Halifax - NS:educationAbove bachelor's degree                     
## region_nameOutside Regina and Saskatoon - SK:educationAbove bachelor's degree        
## region_nameOutside Saint John and Moncton - NB:educationAbove bachelor's degree      
## region_nameOutside Winnipeg - MB:educationAbove bachelor's degree                    
## region_namePrince Edward Island:educationAbove bachelor's degree                     
## region_nameQuébec:educationAbove bachelor's degree                                   
## region_nameRegina:educationAbove bachelor's degree                                   
## region_nameSaint John and Moncton:educationAbove bachelor's degree                   
## region_nameSaskatoon:educationAbove bachelor's degree                             .  
## region_nameToronto:educationAbove bachelor's degree                                  
## region_nameVancouver:educationAbove bachelor's degree                                
## region_nameWinnipeg:educationAbove bachelor's degree                                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.123 on 30196 degrees of freedom
##   (10602 observations deleted due to missingness)
## Multiple R-squared:  0.04579,    Adjusted R-squared:  0.03982 
## F-statistic: 7.667 on 189 and 30196 DF,  p-value: < 2.2e-16

Thursday, March 20th Session

Lesson 5: Distinguishing Interpretations of MLR and Interaction Models

When we have two predictors, we can either include them as “main effects” only (multiple linear regression) or allow their effects to interact or “vary” (interaction model). Let’s explore the difference using our party example again.

Mathematical Representation of Both Models

First, let’s see what each model looks like mathematically using the equatiomatic package:

set.seed(123)

n <- 500  
party_size <- sample(5:100, n, replace = TRUE)  
personality <- sample(c("Introvert", "Extrovert"), n, replace = TRUE) 
party_data <- data.frame(
  party_size = party_size,
  personality = personality
)

party_data$personality_num <- ifelse(party_data$personality == "Introvert", -1, 1)

base_enjoyment <- 50

introvert_slope <- -0.5  
extrovert_slope <- 0.3   
noise_sd <- 10          

party_data$enjoyment <- base_enjoyment + 
  (party_data$personality_num == -1) * introvert_slope * party_data$party_size +
  (party_data$personality_num == 1) * extrovert_slope * party_data$party_size +
  rnorm(n, mean = 0, sd = noise_sd)

party_data$enjoyment <- pmax(0, pmin(100, party_data$enjoyment))

mlr_model <- lm(enjoyment ~ party_size + personality, data = party_data)

interaction_model <- lm(enjoyment ~ party_size * personality, data = party_data)

extract_eq(mlr_model, use_coefs = FALSE)

\[ \operatorname{enjoyment} = \alpha + \beta_{1}(\operatorname{party\_size}) + \beta_{2}(\operatorname{personality}_{\operatorname{Introvert}}) + \epsilon \]

extract_eq(interaction_model, use_coefs = FALSE)

\[ \operatorname{enjoyment} = \alpha + \beta_{1}(\operatorname{party\_size}) + \beta_{2}(\operatorname{personality}_{\operatorname{Introvert}}) + \beta_{3}(\operatorname{party\_size} \times \operatorname{personality}_{\operatorname{Introvert}}) + \epsilon \]

The key difference is the inclusion of the interaction term β₃(party_size × personality).

Comparing the Model Outputs

Let’s fit both models to our simulated party data and examine the differences:

# Show regression tables for both models
tab_model(
  mlr_model, 
  interaction_model,
  dv.labels = c("MLR Model", "Interaction Model"),
  title = "Comparing MLR vs. Interaction Model"
)
Comparing MLR vs. Interaction Model
  MLR Model Interaction Model
Predictors Estimates CI p Estimates CI p
(Intercept) 70.89 67.74 – 74.04 <0.001 50.36 47.62 – 53.10 <0.001
party size -0.07 -0.12 – -0.03 0.002 0.30 0.26 – 0.35 <0.001
personality [Introvert] -43.03 -45.63 – -40.44 <0.001 -1.62 -5.47 – 2.23 0.409
party size × personality
[Introvert]
-0.77 -0.84 – -0.71 <0.001
Observations 500 500
R2 / R2 adjusted 0.682 / 0.681 0.852 / 0.851

Interpreting the Models (Gelman-Style)

In their book “Regression and Other Stories,” Gelman, Hill, and Vehtari emphasize key differences in interpreting MLR vs. interaction models:

MLR Interpretation (without interaction):

# Show equation with coefficients
extract_eq(mlr_model, use_coefs = TRUE, coef_digits = 2)

\[ \operatorname{\widehat{enjoyment}} = 70.89 - 0.07(\operatorname{party\_size}) - 43.03(\operatorname{personality}_{\operatorname{Introvert}}) \]

In the MLR model:

  1. The coefficient for party_size represents the expected change in enjoyment for a one-unit increase in party size, holding personality constant. This means the slope is assumed to be the same for both introverts and extroverts.

  2. The coefficient for personality[Introvert] represents the expected difference in enjoyment between extroverts and introverts at any given party size.

  3. The model forces the relationship between party size and enjoyment to be parallel lines for introverts and extroverts.

Interaction Model Interpretation:

# Show equation with coefficients
extract_eq(interaction_model, use_coefs = TRUE, coef_digits = 2)

\[ \operatorname{\widehat{enjoyment}} = 50.36 + 0.3(\operatorname{party\_size}) - 1.62(\operatorname{personality}_{\operatorname{Introvert}}) - 0.77(\operatorname{party\_size} \times \operatorname{personality}_{\operatorname{Introvert}}) \]

In the interaction model:

  1. The coefficient for party_size represents the effect of party size (0.30) on enjoyment specifically for extroverts (the reference category).

  2. The coefficient for personality[Introvert] (-1.62) is the expected difference in enjoyment between extroverts and introverts when party size equals zero (not meaningful in this context).

  3. The coefficient for the interaction term (-0.77) represents how much the slope of party size differs for introverts compared to extroverts.

  4. For introverts, the effect of party size would be: 0.30 + (-0.77) = -0.47, indicating that as party size increases, enjoyment decreases for introverts.

To better understand the interaction model, we can also rewrite it as separate equations for each group:

# Get coefficients
coefs <- coef(interaction_model)

# Calculate equations for each group
extro_eq <- paste0("Enjoyment (Extroverts) = ", round(coefs[1], 2), " + ", 
                  round(coefs[2], 2), " × party_size")
intro_eq <- paste0("Enjoyment (Introverts) = ", 
                  round(coefs[1] + coefs[3], 2), " + ", 
                  round(coefs[2] + coefs[4], 2), " × party_size")

# Display the equations
extro_eq
## [1] "Enjoyment (Extroverts) = 50.36 + 0.3 × party_size"
intro_eq
## [1] "Enjoyment (Introverts) = 48.74 + -0.47 × party_size"

Interpreting Regression Models

Multiple Linear Regression (MLR) Interpretation

In the multiple linear regression model without interactions, the effects of party size and personality type on enjoyment are estimated separately, resulting in the following statistical relationship:

\[\text{enjoyment} = 70.89 - 0.07(\text{party\_size}) - 43.03(\text{personality[Introvert]})\]

This model provides key insights about how each predictor relates to enjoyment:

Effect of party size:

For each additional person at a party, enjoyment is expected to decrease by 0.07 points on our enjoyment scale, regardless of personality type. This effect is statistically significant (p = 0.002), though relatively small in magnitude. The negative coefficient suggests that larger gatherings generally lead to slightly lower enjoyment when adjusting for personality type. When we say “adjusting for personality type,” we mean that we’re estimating the effect of party size while accounting for differences between personality groups. Specifically, since “Extrovert” is our reference category in this example, the coefficient represents how party size affects enjoyment when holding constant whether someone is an extrovert or introvert.

Effect of personality type:

The coefficient for personality type (-43.03) indicates that, at any given party size, introverts report enjoyment levels that are 43.03 points lower than extroverts on average. This substantial difference is highly statistically significant (p < 0.001) and represents the largest effect in the model. Here, “adjusting for party size” means we’re estimating the difference between introverts and extroverts as if they were attending parties of the same size. In other words, this coefficient tells us the expected difference in enjoyment between an introvert and an extrovert who are at parties with the exact same number of attendees.

Intercept interpretation:

The intercept (70.89) represents the predicted enjoyment for extroverts (the reference category) at a hypothetical party with zero attendees. While not practically meaningful in this context, it serves as the baseline from which other predictions are calculated.

Model limitations: An important limitation of this model is its assumption that party size affects both personality types in exactly the same way (parallel slopes). This means that regardless of whether someone is an introvert or extrovert, the model constrains the change in enjoyment for each additional party attendee to be identical (-0.07 points). This constraint fails to capture the possibility that introverts and extroverts might respond differently to increasing social stimulation. The model explains approximately 68.2% of the variance in enjoyment scores (R² = 0.682).

Interaction Model Interpretation

The interaction model allows the effect of party size to differ by personality type:

\[\text{enjoyment} = 50.36 + 0.30(\text{party\_size}) - 1.62(\text{personality[Introvert]}) - 0.77(\text{party\_size} \times \text{personality[Introvert]})\]

This model reveals a more nuanced relationship between our variables:

Effect of party size for extroverts:

The coefficient of party size (0.30) represents the effect specifically for extroverts, indicating that each additional person at a party increases an extrovert’s enjoyment by 0.30 points. This positive relationship is statistically significant (p < 0.001). This main effect coefficient directly represents the effect for extroverts because they are the reference category in our personality variable.

Effect of party size for introverts:

To determine the effect for introverts, we need to combine the main effect of party size with the interaction term: 0.30 + (-0.77) = -0.47. This means that for introverts, each additional person decreases enjoyment by approximately 0.47 points. Following Gelman’s approach to interpreting interactions, this calculation is derived from substituting the values into our interaction model equation. When personality[Introvert] = 1 (for introverts), the party size term becomes:

  • 0.30(party_size) + (-0.77)(party_size × 1) = 0.30(party_size) - 0.77(party_size) = -0.47(party_size)

Deriving the separate equations for each group:

For extroverts (personality[Introvert] = 0):

  • Enjoyment = 50.36 + 0.30(party_size) - 1.62(0) - 0.77(party_size × 0)

  • Enjoyment = 50.36 + 0.30(party_size)

For introverts (personality[Introvert] = 1):

  • Enjoyment = 50.36 + 0.30(party_size) - 1.62(1) - 0.77(party_size × 1)

  • Enjoyment = 50.36 - 1.62 + 0.30(party_size) - 0.77(party_size)

  • Enjoyment = 48.74 - 0.47(party_size)

Where 48.74 is calculated as 50.36 - 1.62, combining the intercept and the personality main effect for introverts.

Personality difference at zero party size: The personality coefficient (-1.62) technically represents the difference between introverts and extroverts at hypothetical parties with zero attendees. This difference is not statistically significant (p = 0.409) and has limited substantive meaning since a “party of size zero” isn’t conceptually meaningful.

Interaction significance: The highly significant interaction term (-0.77, p < 0.001) confirms that the relationship between party size and enjoyment fundamentally differs by personality type. This validates our theoretical expectation that extroverts and introverts respond differently to social stimulation.

Visualizing Interaction Effects

1. Using sjPlot’s plot_model() for Interaction Effects

plot_model(interaction_model, type = "int", ci.lvl = 0.95,
           title = "Interaction between Party Size and Personality",
           axis.title = c("Party Size", "Enjoyment"),
           legend.title = "Personality Type")

2. Using effects Package for Interaction Visualization

plot(effect("party_size:personality", interaction_model), 
     main = "Effect of Party Size and Personality on Enjoyment",
     xlab = "Party Size", ylab = "Predicted Enjoyment")

3. Using interactions Package for Interaction Visualization

interact_plot(interaction_model, pred = "party_size", modx = "personality",
              plot.points = TRUE, point.alpha = 0.3,
              main = "Interaction between Party Size and Personality",
              x.label = "Party Size", y.label = "Predicted Enjoyment")

Real-world data: Analyzing Trump Votes with Regression Models

Steven V. Miller’s package has clean, organized data to explore the Trump 2016 election: https://svmiller.com/stevedata/reference/TV16.html

# Load the data
data(TV16)

# Examine the dataset structure
str(TV16)
## tibble [64,600 × 21] (S3: tbl_df/tbl/data.frame)
##  $ uid        : int [1:64600] 1 2 3 4 5 6 7 8 9 10 ...
##  $ state      : chr [1:64600] "New Hampshire" "Louisiana" "Missouri" "Alabama" ...
##  $ votetrump  : num [1:64600] 1 1 NA NA 0 NA 1 NA 1 1 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ age        : num [1:64600] 47 22 52 28 34 53 54 25 53 59 ...
##  $ female     : num [1:64600] 1 1 1 1 1 1 0 1 0 1 ...
##  $ collegeed  : num [1:64600] 0 0 0 0 1 0 0 0 0 0 ...
##  $ racef      : chr [1:64600] "White" "White" "Black" "Black" ...
##  $ famincr    : num [1:64600] NA 6 4 1 7 1 3 1 4 7 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ ideo       : num [1:64600] 3 3 5 4 2 NA 5 3 4 3 ...
##  $ pid7na     : num [1:64600] 5 4 1 4 2 2 6 4 7 7 ...
##  $ bornagain  : num [1:64600] 0 NA 0 0 0 0 1 0 1 0 ...
##  $ religimp   : num [1:64600] 3 NA 4 3 1 4 4 1 2 3 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ churchatd  : num [1:64600] 1 NA 4 3 1 5 5 2 3 2 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ prayerfreq : num [1:64600] 3 NA 5 5 2 7 7 3 6 4 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ angryracism: num [1:64600] 2 1 NA NA 2 1 2 NA 3 3 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ whiteadv   : num [1:64600] 3 4 NA NA 1 1 5 NA 4 5 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ fearraces  : num [1:64600] 1 1 NA NA 1 1 2 NA 1 1 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ racerare   : num [1:64600] 3 1 NA NA 1 1 2 NA 2 3 ...
##   ..- attr(*, "format.stata")= chr "%8.0g"
##  $ lrelig     : num [1:64600] -0.1917 NA 0.5731 0.0694 -1.1302 ...
##  $ lcograc    : num [1:64600] 0.475 -0.186 NA NA -1.204 ...
##  $ lemprac    : num [1:64600] -0.139 -0.619 NA NA -0.139 ...

Two-Predictor Model with Interaction

First, let’s model Trump voting using two key predictors highlighted in Miller’s blog: partisanship (pid7na) and cognitive racism (lcograc), with an interaction between them.

pid7na:

a numeric vector for the respondent’s partisanship on the familiar 1-7 scale. 1 = Strong Democrat. 7 = Strong Republican. Other party supporters (e.g. libertarians) are coded as NA.

lcograc:

a numeric vector that serves as a latent estimate for cognitive racism. This is derived from the racerare and whiteadv variables, which are:

whiteadv a numeric vector for agreement with statement that white people have advantages over others in the U.S. 1 = strongly agree. 5 = strongly disagree.

racerare a numeric vector for agreement with statement that racism is rare in the U.S. 1 = strongly disagree. 5 = strongly agree.

trump_model_1 <- lm(votetrump ~ pid7na + lcograc + pid7na:lcograc, data = TV16)

extract_eq(trump_model_1, use_coefs = FALSE)

\[ \operatorname{votetrump} = \alpha + \beta_{1}(\operatorname{pid7na}) + \beta_{2}(\operatorname{lcograc}) + \beta_{3}(\operatorname{pid7na} \times \operatorname{lcograc}) + \epsilon \]

tab_model(trump_model_1, 
          title = "Trump Vote Predicted by Partisanship and Cognitive Racism",
          pred.labels = c("Intercept", 
                         "Partisanship (D to R)", 
                         "Cognitive Racism",
                         "Partisanship × Cognitive Racism"))
Trump Vote Predicted by Partisanship and Cognitive Racism
  votetrump
Predictors Estimates CI p
Intercept -0.06 -0.07 – -0.05 <0.001
Partisanship (D to R) 0.13 0.13 – 0.13 <0.001
Cognitive Racism 0.11 0.11 – 0.12 <0.001
Partisanship × Cognitive Racism 0.01 0.01 – 0.02 <0.001
Observations 44319
R2 / R2 adjusted 0.581 / 0.581

Three-Predictor Model with Interaction

For our second model, let’s use three different predictors than the first model: age, education (collegeed), and religiosity (lrelig), with an interaction between age and education.

collegeed: a numeric vector that equals 1 if the respondent says s/he has a college degree

lrelig a numeric vector that serves as a latent estimate for religiosity from the bornagain, religimp, churchatd, and prayerfreq variables. Higher values = more religiosity

TV16$collegeed <- factor(TV16$collegeed, 
                          levels = c(0, 1), 
                          labels = c("No College", "College"))
trump_model_2 <- lm(votetrump ~ age + collegeed + lrelig + age:collegeed, data = TV16)

extract_eq(trump_model_2, use_coefs = FALSE)

\[ \operatorname{votetrump} = \alpha + \beta_{1}(\operatorname{age}) + \beta_{2}(\operatorname{collegeed}_{\operatorname{College}}) + \beta_{3}(\operatorname{lrelig}) + \beta_{4}(\operatorname{age} \times \operatorname{collegeed}_{\operatorname{College}}) + \epsilon \]

tab_model(trump_model_1, trump_model_2,
          dv.labels = c("Model 1: Party & Racism", "Model 2: Age, Education & Religion"),
          title = "Trump Vote Models with Different Predictors",
          pred.labels = c("Intercept", 
                         "Partisanship (D to R)", 
                         "Cognitive Racism",
                         "Partisanship × Cognitive Racism",
                         "Age",
                         "College Education",
                         "Religiosity",
                         "Age × College Education"))
Trump Vote Models with Different Predictors
  Model 1: Party & Racism Model 2: Age, Education & Religion
Predictors Estimates CI p Estimates CI p
Intercept -0.06 -0.07 – -0.05 <0.001 0.24 0.22 – 0.26 <0.001
Partisanship (D to R) 0.13 0.13 – 0.13 <0.001
Cognitive Racism 0.11 0.11 – 0.12 <0.001
Partisanship × Cognitive Racism 0.01 0.01 – 0.02 <0.001
Age 0.00 0.00 – 0.00 <0.001
College Education -0.08 -0.11 – -0.05 <0.001
Religiosity 0.13 0.13 – 0.14 <0.001
Age × College Education -0.00 -0.00 – -0.00 0.030
Observations 44319 44928
R2 / R2 adjusted 0.581 / 0.581 0.114 / 0.114

Comparing Models with Standardized Coefficients

Now, let’s visualize both models together using standardized coefficients to compare the relative importance of different predictors across models, even though they’re on different scales.

plot1 <- plot_model(trump_model_1, show.values = TRUE, value.offset = .3) + 
  ggtitle("Model 1: Unstandardized Coefficients")

plot2 <- plot_model(trump_model_2, show.values = TRUE, value.offset = .3) + 
  ggtitle("Model 2: Unstandardized Coefficients")

plot3 <- plot_model(trump_model_1, type = "std2", show.values = TRUE, value.offset = .3) + 
  ggtitle("Model 1: Standardized (2SD)")

plot4 <- plot_model(trump_model_2, type = "std2", show.values = TRUE, value.offset = .3) + 
  ggtitle("Model 2: Standardized (2SD)")

plot_grid(plot1, plot2, plot3, plot4, ncol = 2)

Interpreting Unstandardized Coefficients

Model 1: Partisanship and Cognitive Racism

The first model examines how partisanship, cognitive racism, and their interaction predict Trump voting in 2016:

\[\text{votetrump} = -0.06 + 0.13(\text{pid7na}) + 0.11(\text{lcograc}) + 0.01(\text{pid7na} \times \text{lcograc})\]

Intercept (-0.06): This represents the predicted value of the Trump vote variable for someone who is a Strong Democrat (pid7na = 1) and has the lowest possible level of cognitive racism (lcograc = 0). Since the outcome is binary (0 or 1), this negative value is not directly interpretable as a probability but rather as a point on the linear predictor scale.

Partisanship (0.13): For each one-point increase on the 7-point partisanship scale (moving toward Republican identification), the predicted Trump vote increases by 0.13 when cognitive racism is at zero. Across the full range of the partisanship scale (from 1 to 7), this represents a substantial predicted difference of 0.78 (6 × 0.13).

Cognitive Racism (0.11): For each one-unit increase in the cognitive racism scale, the predicted Trump vote increases by 0.11 for Strong Democrats (pid7na = 1). This coefficient captures how beliefs about racial advantages and the prevalence of racism relate to voting behavior.

Interaction (0.01): The positive interaction term indicates that the effect of cognitive racism increases as respondents become more Republican. For each additional point on the partisanship scale, the effect of cognitive racism increases by 0.01. This means that for Strong Republicans (pid7na = 7), the effect of cognitive racism would be 0.11 + (6 × 0.01) = 0.17, compared to 0.11 for Strong Democrats.

Model 2: Age, Education, and Religiosity

The second model examines different predictors:

\[\text{votetrump} = 0.24 + 0.00(\text{age}) - 0.08(\text{collegeedCollege}) + 0.13(\text{lrelig}) - 0.00(\text{age} \times \text{collegeedCollege})\]

Intercept (0.24): This represents the predicted Trump vote for a person with no college education (the reference category), age zero (not meaningful), and zero religiosity.

Age (0.00): For each additional year of age, the predicted Trump vote increases very slightly among non-college educated respondents. Though statistically significant, the magnitude is so small that it appears as 0.00 when rounded to two decimal places.

College Education (-0.08): College-educated respondents had a predicted Trump vote 0.08 points lower compared to non-college educated respondents of the same age and religiosity. This captures the educational divide in 2016 voting patterns.

Religiosity (0.13): For each one-unit increase in religiosity, the predicted Trump vote increases by 0.13, regardless of age and education. This substantial effect highlights the importance of religious values in predicting Trump support.

Age × College Education (-0.00): While statistically significant (p = 0.030), this interaction effect is very small in magnitude. It suggests that the negative effect of college education on Trump voting becomes slightly stronger with increasing age.

Interpreting Standardized Coefficients (2SD Method)

Standardization allows us to compare coefficients measured on different scales by expressing them in standard deviation units. Gelman’s 2SD method divides by two standard deviations rather than one, making continuous and binary predictors more directly comparable.

Model 1: Standardized

Partisanship (0.57): A two standard deviation increase in Republican partisanship is associated with a 0.57 increase in the predicted Trump vote. This is the strongest predictor in either model.

Cognitive Racism (0.28): A two standard deviation increase in cognitive racism is associated with a 0.28 increase in the predicted Trump vote.

Interaction (0.05): The standardized interaction effect is relatively small but still significant.

Model 2: Standardized

Age (0.14): A two standard deviation increase in age is associated with a 0.14 increase in the predicted Trump vote. In standardized form, we can see that age does have a meaningful effect, despite its small unstandardized coefficient.

College Education (-0.22): Having a college degree is associated with a 0.22 decrease in the predicted Trump vote, compared to not having a college degree.

Religiosity (0.26): A two standard deviation increase in religiosity is associated with a 0.26 increase in the predicted Trump vote, making it the strongest predictor in Model 2.

Age × College Education (-0.02): The standardized interaction effect remains small.

Comparing Models Using Standardization

The standardized coefficients reveal important insights that weren’t immediately apparent from the unstandardized results:

  1. Scale differences: In Model 1’s unstandardized coefficients, partisanship (0.13) and cognitive racism (0.11) appeared similar in magnitude. However, when standardized, partisanship (0.57) is twice as strong as cognitive racism (0.28). This occurs because the partisanship scale has a wider range and greater variance.

  2. Binary vs. continuous predictors: College education appears to have a modest effect (-0.08) in unstandardized form, but its standardized coefficient (-0.22) reveals it has a substantial impact, comparable to the effect of religiosity (0.26).

  3. Small but meaningful effects: Age’s unstandardized coefficient (0.00) appeared negligible, but its standardized value (0.14) shows it has a meaningful, if modest, relationship with Trump voting.

  4. Cross-model comparison: Standardization allows us to see that partisanship in Model 1 (0.57) has a much stronger relationship with Trump voting than any predictor in Model 2, where religiosity (0.26) is the strongest predictor.

  5. Model fit comparison: The R² values reveal that Model 1 (R² = 0.581) explains substantially more variance in Trump voting than Model 2 (R² = 0.114). This indicates that partisanship and cognitive racism together are much stronger predictors of Trump support than age, education, and religiosity combined.

Standardization is particularly valuable when comparing predictors measured on different scales (like age measured in years versus partisanship measured on a 1-7 scale) or when comparing binary predictors (like college education) with continuous variables. The 2SD method specifically helps make binary and continuous variables more comparable in regression models by addressing the fact that a binary predictor can only have a maximum “change” of one unit, while continuous predictors can vary across multiple standard deviations.

Now, let’s see visualization options:

# Interaction plot for Model 1: Partisanship and Cognitive Racism
interact_plot(trump_model_1, pred = "pid7na", modx = "lcograc", 
              modx.values = c(-2, 0, 2),
              plot.points = TRUE, point.alpha = 0.3,
              main = "Interaction between Partisanship and Cognitive Racism",
              x.label = "Partisanship (D to R)",
              y.label = "Predicted Trump Vote",
              legend.main = "Cognitive Racism") +
  theme_minimal()

# Interaction plot for Model 2: Age and College Education
interact_plot(trump_model_2, pred = "age", modx = "collegeed",
              plot.points = TRUE, point.alpha = 0.3,
              main = "Interaction between Age and College Education",
              x.label = "Age", 
              y.label = "Predicted Trump Vote",
              legend.main = "Education") +
  theme_minimal()

# Marginal effects plot for Model 1
# Create a grid of values to show all combinations of predictors
eff1 <- plot_model(trump_model_1, type = "pred", terms = c("pid7na", "lcograc[-2,0,2]"),
                  grid = TRUE) +
  theme_minimal() +
  labs(title = "Marginal Effects of Partisanship and Cognitive Racism",
       y = "Predicted Trump Vote")
eff1

# Marginal effects plot for Model 2
eff2 <- plot_model(trump_model_2, type = "pred", terms = c("age", "collegeed"),
                  grid = TRUE) +
  theme_minimal() +
  labs(title = "Marginal Effects of Age and College Education",
       y = "Predicted Trump Vote")
eff2

# Marginal effects of religiosity in Model 2
eff3 <- plot_model(trump_model_2, type = "pred", terms = "lrelig",
                  grid = TRUE) +
  theme_minimal() +
  labs(title = "Marginal Effect of Religiosity",
       y = "Predicted Trump Vote")
eff3

# Using effects package for a different perspective
# Model 1: Partisanship × Cognitive Racism interaction
plot(effect("pid7na:lcograc", trump_model_1), 
     main = "Effect of Partisanship and Cognitive Racism on Trump Vote",
     xlab = "Partisanship (D to R)", ylab = "Predicted Trump Vote")

# Using effects package for Model 2: Age × College Education
plot(effect("age:collegeed", trump_model_2), 
     main = "Effect of Age and College Education on Trump Vote",
     xlab = "Age", ylab = "Predicted Trump Vote")

Understanding Different Approaches to Visualizing Regression Interactions

Interaction Plots

Interaction plots display how the relationship between a predictor variable and the outcome changes depending on the value of another variable. These plots typically show multiple lines representing the predictor-outcome relationship at different levels of the moderating variable. The non-parallel lines in these plots visually demonstrate the interaction effect—the steeper the difference in slopes, the stronger the interaction. These visualizations are particularly valuable for communicating to audiences how one variable’s effect depends on the context provided by another variable.

Marginal Effects Plots

Marginal effects plots focus on the predicted outcomes across the range of a predictor variable while holding other variables constant at specific values (often means or meaningful reference points). They effectively show “what happens to the outcome when this predictor changes, assuming all else is equal.” When examining interactions, marginal effects plots can display multiple prediction lines for different values of the interacting variable, allowing us to see how predictions differ across contexts. These plots help translate abstract regression coefficients into concrete predicted values that stakeholders can more easily understand.

The Value of Visual Interpretations

These visualization approaches complement traditional regression tables by transforming abstract numbers into intuitive visual patterns. While tables of coefficients provide precision, visualizations reveal relationships that might otherwise remain hidden. They’re particularly valuable for communicating with non-technical audiences, exploring interaction effects, identifying threshold points where effects change meaningfully, and building more intuitive understanding of statistical relationships. In practice, using multiple visualization approaches often provides the most complete understanding of regression models.

Lesson 6: You have to think about your models

trump_lm <- lm(votetrump ~ ideo, data = TV16)
summary(trump_lm)
## 
## Call:
## lm(formula = votetrump ~ ideo, data = TV16)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.95086 -0.41189  0.04914  0.31863  1.12709 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.396577   0.005467  -72.55   <2e-16 ***
## ideo         0.269488   0.001696  158.87   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3924 on 43428 degrees of freedom
##   (21170 observations deleted due to missingness)
## Multiple R-squared:  0.3676, Adjusted R-squared:  0.3675 
## F-statistic: 2.524e+04 on 1 and 43428 DF,  p-value: < 2.2e-16

Notice that the intercept is negative (-0.397). This immediately signals a problem, as it suggests voters with a very liberal ideology would have a negative probability of voting for Trump, which is not possible (or substantively interpretable).

Let’s visualize this issue:

trump_glm <- glm(votetrump ~ ideo, data = TV16, family = binomial(link = "logit"))

newdata <- data.frame(ideo = seq(min(TV16$ideo, na.rm = TRUE), 
                                max(TV16$ideo, na.rm = TRUE), 
                                length.out = 100))
newdata$linear_pred <- predict(trump_lm, newdata = newdata)
newdata$logistic_pred <- predict(trump_glm, newdata = newdata, type = "response")

ggplot(TV16, aes(x = ideo, y = votetrump)) +
  geom_jitter(height = 0.05, width = 0.2, alpha = 0.3, color = "black") +
  geom_line(data = newdata, aes(x = ideo, y = linear_pred, color = "Linear Model"), 
            size = 1) +
  geom_line(data = newdata, aes(x = ideo, y = logistic_pred, color = "Logistic Model"), 
            size = 1) +
  labs(
    title = "Trump Vote by Ideology",
    subtitle = "Linear model produces impossible negative probabilities",
    x = "Ideology (1 = Very Liberal, 5 = Very Conservative)",
    y = "Voted for Trump (0 = No, 1 = Yes)",
    color = "Model Type"
  ) +
  scale_y_continuous(limits = c(-0.2, 1)) +
  scale_color_manual(values = c("Linear Model" = "red", "Logistic Model" = "blue")) +
  theme_minimal() +
  geom_hline(yintercept = c(0, 1), linetype = "dashed", color = "darkgrey")

This visualization clearly illustrates the fundamental problem with linear regression for binary outcomes: it can predict impossible values outside the [0,1] range. For very liberal voters (ideology = 1), the linear model predicts negative probabilities, which violates the basic definition of probability.

Understanding Linear and Generalized Linear Models

The Foundation of OLS Regression: Why Assumptions Matter

Ordinary Least Squares (OLS) regression is more than just a statistical technique—it’s a method for discovering the relationship between variables in a way that provides meaningful, interpretable results. Let’s explore why each assumption matters fundamentally for the integrity of our models.

The Core Purpose of OLS

When we fit a linear regression model using OLS, we’re attempting to find the “line of best fit” that minimizes the sum of squared differences between observed values and the values predicted by the line. This optimization has a specific goal: to recover the true underlying relationship between predictor and outcome variables.

The coefficient estimates in OLS have clear interpretations:

  • The slope coefficient (β₁) represents the expected change in Y for a one-unit increase in X

  • The intercept (β₀) represents the expected value of Y when X equals zero

These interpretations depend critically on the assumptions of OLS. When assumptions are violated, these interpretations become questionable or even meaningless.

Why Each Assumption Matters for Interpretation

  1. Linearity: OLS assumes the relationship between variables is linear. If the true relationship is non-linear:

    • The estimated line will be a poor approximation of the actual relationship

    • Coefficients will represent an “average” effect that might be misleading at different values of X

    • Predictions will be systematically biased in regions where the true relationship deviates from linearity

  2. Independence: OLS assumes observations are independent of each other. If observations are correlated:

    • Standard errors will be underestimated, leading to overconfidence in results

    • Significance testing becomes invalid

  3. Homoscedasticity: OLS assumes constant variance across all levels of predictors. If variance changes with predictor values:

    • Coefficient estimates remain unbiased but are no longer the most efficient

    • Standard errors become biased, typically underestimated where variance is higher

    • Confidence intervals and hypothesis tests become unreliable

    • Some observations have disproportionate influence on the model

  4. Normality: OLS assumes errors follow a normal distribution. If errors are non-normal:

    • Inference (p-values, confidence intervals) becomes less reliable, especially with small samples

    • Prediction intervals may be misleading

  5. No perfect multicollinearity: OLS assumes predictors aren’t perfectly correlated. If they are:

    • The model becomes mathematically unsolvable (the matrix becomes singular)

    • Coefficient estimates become unstable and potentially meaningless

The Consequences of Violated Assumptions for Binary Outcomes

When modeling binary outcomes with OLS (a linear probability model), the violations are not merely technical—they’re fundamental:

  1. Bounded outcome vs. unbounded predictions: A probability must be between 0 and 1, but linear models can predict values outside this range. This isn’t just a technical issue; it means the model is making logically impossible predictions.

  2. Heteroscedasticity is guaranteed: With a binary outcome, the variance at any given X value is p(1-p), where p is the probability. This variance is highest at p = 0.5 and lowest at p = 0 or p = 1. This systematic pattern of changing variance means:

    • Standard errors are incorrect

    • Hypothesis tests are invalid

    • Confidence intervals are misleading

  3. Non-normal errors are inevitable: With binary outcomes, residuals can only take on two possible values at any given predicted probability, making a normal distribution impossible.

OLS as a Model, Not a Magic Wand

It’s crucial to recognize that OLS is a model with embedded assumptions (just like any model!!) — not a universal tool that automatically discovers “truth.” The model specification carries assumptions about how the world works:

  • The relationship is assumed to be linear

  • The effects of variables are assumed to be additive

  • The errors are assumed to be random noise, not systematic patterns

These assumptions constitute a simplified model of reality. When they align with the actual data-generating process, OLS provides powerful insights. When they don’t, the results can be misleading or uninformative.

As statistician George Box famously stated, “All models are wrong, but some are useful.” The usefulness of OLS depends on how well its assumptions match the characteristics of our data and research question.

The Shift to GLMs: A Response to Violated Assumptions

Generalized Linear Models (GLMs) emerged precisely because researchers needed methods that could maintain the interpretability of linear models while accommodating different types of outcomes.

With binary outcomes, the shift to logistic regression involves:

  • Accepting that the relationship with the probability is non-linear

  • Modeling the relationship with the log-odds instead, which can be linear

  • Using maximum likelihood estimation instead of least squares

  • Incorporating the correct variance structure for binary data

This shift preserves what we value about linear models—interpretable coefficients, tests of significance, predictions—while respecting the constraints of binary data.

The Three Components of GLMs

A GLM consists of three essential components:

  1. Random Component (Distribution Family):

    • Specifies the probability distribution of the response variable

    • Comes from the exponential family of distributions (e.g., normal, binomial, Poisson, gamma)

    • For binary outcomes, we use the binomial distribution

  2. Systematic Component (Linear Predictor):

    • The linear combination of predictors: η = β₀ + β₁X₁ + β₂X₂ + … + βₚXₚ

    • The coefficients are estimated through maximum likelihood rather than ordinary least squares

  3. Link Function:

    • Connects the expected value of the response to the linear predictor: g(μ) = η

    • Different link functions are appropriate for different types of outcomes

    • For binary outcomes, the logit link is most common: logit(p) = log(p/(1-p))

Logistic Regression: The GLM for Binary Outcomes

Logistic regression is a specific type of GLM designed for binary outcomes:

Mathematical Formulation

  1. Distribution: Y ~ Binomial(n, p)

    • For binary outcomes, n = 1, so Y ~ Bernoulli(p)
  2. Link Function: logit(p) = log(p/(1-p)) = β₀ + β₁X₁ + β₂X₂ + … + βₚXₚ

  3. Inverse Link Function: p = 1 / (1 + e^(-η)) = e^η / (1 + e^η)

    • This transforms the linear predictor back to probability scale

Estimation Method: Maximum Likelihood

Unlike linear regression which uses ordinary least squares, logistic regression uses maximum likelihood estimation (MLE) to find the parameter values (β) that make the observed data most probable under the model.

The likelihood function for logistic regression is: L(β) = Π[p_i^y_i × (1-p_i)^(1-y_i)]

Where: - y_i is the observed outcome (0 or 1) for observation i

  • p_i is the predicted probability for observation i

  • Π represents the product over all observations

In practice, we maximize the log-likelihood: log(L(β)) = Σ[y_i × log(p_i) + (1-y_i) × log(1-p_i)]

The GLM framework extends beyond binary outcomes to handle a wide variety of response types (e.g., binary, count, nominal categories)

Each type of GLM handles the specific characteristics of its response distribution. For example, Poisson regression for count data accounts for the fact that:

  • Counts are non-negative integers

  • The variance of a Poisson distribution equals its mean

  • Count data often shows increasing variance with the mean

Practical Benefits of Using Logistic Regression

Using logistic regression for binary outcomes offers several practical benefits:

  1. Valid predictions: Results are constrained to the probability range [0,1]

  2. Proper error structure: Accounts for the binomial nature of binary data

  3. Unbiased estimates: Provides consistent and efficient parameter estimates

  4. Flexibility: Accommodates both categorical and continuous predictors

  5. Interpretability: Results can be interpreted in terms of odds ratios or probabilities

  6. Theoretical coherence: Based on sound statistical principles

Logistic Regression in R

To fit logistic regression models, we will use the glm() function, specifying the binomial family:

trump_glm <- glm(votetrump ~ ideo, data = TV16, family = binomial(link = "logit"))
summary(trump_glm)
## 
## Call:
## glm(formula = votetrump ~ ideo, family = binomial(link = "logit"), 
##     data = TV16)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -5.83832    0.05670  -103.0   <2e-16 ***
## ideo         1.74135    0.01706   102.1   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 59055  on 43429  degrees of freedom
## Residual deviance: 39468  on 43428  degrees of freedom
##   (21170 observations deleted due to missingness)
## AIC: 39472
## 
## Number of Fisher Scoring iterations: 5

Notice how this model provides coefficients on the log-odds scale. These are harder to interpret directly, but they ensure our predictions will be valid probabilities (once we transform them)

The Logistic Function: Ensuring Valid Probabilities

The logistic function transforms the linear predictor (which can range from -∞ to +∞) into a valid probability (0 to 1):

linear_pred <- seq(-6, 6, by = 0.1)
probabilities <- 1 / (1 + exp(-linear_pred))

link_data <- data.frame(
  linear_pred = linear_pred,
  probability = probabilities
)

ggplot(link_data, aes(x = linear_pred, y = probability)) +
  geom_line(color = "blue", size = 1.5) +
  geom_hline(yintercept = c(0, 0.5, 1), linetype = "dashed", color = "darkgrey") +
  geom_vline(xintercept = 0, linetype = "dashed", color = "darkgrey") +
  labs(
    title = "The Logistic Function",
    subtitle = "Converting linear predictor values to valid probabilities",
    x = "Linear Predictor (β0 + β1X1 + β2X2 + ...)",
    y = "Probability"
  ) +
  theme_minimal() +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1))

Interpreting Logistic Regression Coefficients

Let’s interpret the coefficients from our logistic regression model:

trump_glm <- glm(votetrump ~ ideo, data = TV16, family = binomial(link = "logit"))
summary(trump_glm)
## 
## Call:
## glm(formula = votetrump ~ ideo, family = binomial(link = "logit"), 
##     data = TV16)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -5.83832    0.05670  -103.0   <2e-16 ***
## ideo         1.74135    0.01706   102.1   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 59055  on 43429  degrees of freedom
## Residual deviance: 39468  on 43428  degrees of freedom
##   (21170 observations deleted due to missingness)
## AIC: 39472
## 
## Number of Fisher Scoring iterations: 5

1. Log-Odds Interpretation

The coefficient for ideology (1.74) means that for each one-unit increase in ideology (moving from liberal toward conservative), the log-odds of voting for Trump increase by 1.74 units. The large negative intercept (-5.84) represents the log-odds of voting for Trump for someone with an ideology value of 0 (which is outside our scale).

2. Odds Ratio Interpretation

By exponentiating the coefficients, we get odds ratios, which are easier to interpret:

exp(coef(trump_glm))
## (Intercept)        ideo 
## 0.002913746 5.705053892

The odds ratio for ideology is 5.71. This means that for each one-unit increase in ideology (e.g., from “Liberal” to “Moderate”), the odds of voting for Trump multiply by a factor of 5.71. This strong effect confirms that more conservative voters were much more likely to vote for Trump.

3. Predicted Probabilities

The most intuitive approach is to calculate predicted probabilities at different values of the predictor:

ideology_values <- data.frame(ideo = 1:5)  # From very liberal to very conservative
ideology_values$probability <- predict(trump_glm, newdata = ideology_values, type = "response")

kable(
  data.frame(
    "Ideology Level" = c("Very Liberal (1)", "Liberal (2)", "Moderate (3)", 
                        "Conservative (4)", "Very Conservative (5)"),
    "Predicted Probability" = round(ideology_values$probability, 3)
  ),
  caption = "Predicted Probability of Voting for Trump by Ideology"
)
Predicted Probability of Voting for Trump by Ideology
Ideology.Level Predicted.Probability
Very Liberal (1) 0.016
Liberal (2) 0.087
Moderate (3) 0.351
Conservative (4) 0.755
Very Conservative (5) 0.946

These values show how the probability of voting for Trump increases dramatically as ideology becomes more conservative - from just 1.6% for very liberal voters to 94.6% for very conservative voters.

Multiple Logistic Regression

Let’s now examine our model that includes both ideology and partisanship:

trump_glm2 <- glm(votetrump ~ ideo + pid7na, data = TV16, family = binomial(link = "logit"))
summary(trump_glm2)
## 
## Call:
## glm(formula = votetrump ~ ideo + pid7na, family = binomial(link = "logit"), 
##     data = TV16)
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -6.459700   0.066466  -97.19   <2e-16 ***
## ideo         0.937928   0.019760   47.47   <2e-16 ***
## pid7na       0.813130   0.009468   85.88   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 58511  on 43028  degrees of freedom
## Residual deviance: 28512  on 43026  degrees of freedom
##   (21571 observations deleted due to missingness)
## AIC: 28518
## 
## Number of Fisher Scoring iterations: 5

When we control for partisanship, the coefficient for ideology decreases from 1.74 to 0.94, suggesting that part of the ideological effect was capturing partisanship differences. Both predictors remain highly significant, indicating that both ideology and partisanship independently contribute to the probability of voting for Trump.

The odds ratio for ideology in this model is 2.55 (compared to 5.71 in the ideology-only model), and the odds ratio for partisanship is 2.25. This means that, holding partisanship constant, each one-unit increase in ideology multiplies the odds of voting for Trump by 2.56. Similarly, holding ideology constant, each one-unit increase in partisanship multiplies the odds by 2.25.

Visualizing Predicted Probabilities

Let’s visualize how ideology and cognitive racism affect the probability of voting for Trump:

trump_glm3 <- glm(votetrump ~ lcograc, data = TV16, family = binomial(link = "logit"))

ideology_values <- 1:5
cognitive_values <- seq(-3, 3, by = 1)

ideo_pred <- data.frame(ideo = ideology_values)
ideo_pred$probability <- predict(trump_glm, newdata = ideo_pred, type = "response")
ideo_pred$variable <- "Ideology"
ideo_pred$value <- ideo_pred$ideo
ideo_pred$label <- c("Very Liberal", "Liberal", "Moderate", "Conservative", "Very Conservative")

cog_pred <- data.frame(lcograc = cognitive_values)
cog_pred$probability <- predict(trump_glm3, newdata = cog_pred, type = "response")
cog_pred$variable <- "Cognitive Racism"
cog_pred$value <- cog_pred$lcograc
cog_pred$label <- c("Very Low", "Low", "Somewhat Low", 
                   "Average", "Somewhat High", "High", "Very High")

combined_pred <- rbind(
  ideo_pred[, c("variable", "value", "label", "probability")],
  cog_pred[, c("variable", "value", "label", "probability")]
)

combined_pred
##            variable value             label probability
## 1          Ideology     1      Very Liberal  0.01635127
## 2          Ideology     2           Liberal  0.08662083
## 3          Ideology     3          Moderate  0.35108842
## 4          Ideology     4      Conservative  0.75530222
## 5          Ideology     5 Very Conservative  0.94626441
## 6  Cognitive Racism    -3          Very Low  0.00117355
## 7  Cognitive Racism    -2               Low  0.00934179
## 8  Cognitive Racism    -1      Somewhat Low  0.07035849
## 9  Cognitive Racism     0           Average  0.37788866
## 10 Cognitive Racism     1     Somewhat High  0.82979239
## 11 Cognitive Racism     2              High  0.97507961
## 12 Cognitive Racism     3         Very High  0.99682576
plot_ideo <- ggplot(ideo_pred, aes(x = value, y = probability)) +
  geom_line(size = 1.2, color = "darkblue") +
  geom_point(size = 3, color = "darkred") +
  labs(
    title = "Ideology Effect on Trump Vote",
    y = "Predicted Probability",
    x = "Ideology"
  ) +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  scale_x_continuous(
    breaks = 1:5,
    labels = c("Very Liberal", "Liberal", "Moderate", "Conservative", "Very Conservative")
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 12, face = "bold"),
    axis.text.x = element_text()
  )

plot_cog <- ggplot(cog_pred, aes(x = value, y = probability)) +
  geom_line(size = 1.2, color = "darkblue") +
  geom_point(size = 3, color = "darkred") +
  labs(
    title = "Cognitive Racism Effect on Trump Vote",
    y = "Predicted Probability",
    x = "Cognitive Racism"
  ) +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  scale_x_continuous(
    breaks = -3:3,
    labels = c("Very Low (-3)", "Low (-2)", "Somewhat Low (-1)", 
             "Average (0)", "Somewhat High (+1)", "High (+2)", "Very High (+3)")
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 12, face = "bold"),
    axis.text.x = element_text()
  )

plot_ideo + plot_cog + 
  plot_layout(ncol = 2) +
  plot_annotation(
    title = "Predicted Probability of Voting for Trump",
    theme = theme(plot.title = element_text())
  )

Enhanced Visualization of Predicted Probabilities with Custom Color Palette

ideology_effects <- ggeffect(trump_glm, terms = "ideo")

okabe_ito <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")

ggplot(ideology_effects, aes(x = x, y = predicted)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.2, fill = okabe_ito[2]) +
  geom_line(color = okabe_ito[2], size = 1.2) +
  geom_point(size = 3, color = okabe_ito[6]) +
  geom_rug(data = TV16, aes(x = ideo, y = votetrump), 
           sides = "b", alpha = 0.2, color = okabe_ito[7]) +
  labs(
    title = "Predicted Probability of Voting for Trump by Ideology",
    subtitle = "With 95% confidence intervals",
    x = "Ideology (1 = Very Liberal, 5 = Very Conservative)",
    y = "Predicted Probability"
  ) +
  scale_x_continuous(breaks = 1:5, 
                    labels = c("Very Liberal", "Liberal", "Moderate", "Conservative", "Very Conservative")) +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = okabe_ito[6]),
    axis.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  )

Visualizing Age Effects on Trump Vote Probability

trump_age_model <- glm(votetrump ~ age, data = TV16, family = binomial(link = "logit"))

age_probs <- data.frame(
  age = seq(20, 80, by = 5)
)

age_probs$predicted <- predict(trump_age_model, 
                              newdata = age_probs, 
                              type = "response")

ggplot(age_probs, aes(x = age, y = predicted)) +
  geom_line(color = okabe_ito[3], size = 1.2) +
  geom_point(data = subset(age_probs, age %in% seq(20, 80, by = 10)), 
             size = 3, color = okabe_ito[6]) +
  labs(
    title = "Effect of Age on Probability of Voting for Trump",
    subtitle = "Older voters were more likely to support Trump",
    x = "Age (years)",
    y = "Predicted Probability of Voting for Trump"
  ) +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 0.7)) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = okabe_ito[6]),
    axis.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  )

trump_interaction_model <- glm(
  votetrump ~ age * ideo,
  data = TV16, 
  family = binomial(link = "logit")
)

summary(trump_interaction_model)
## 
## Call:
## glm(formula = votetrump ~ age * ideo, family = binomial(link = "logit"), 
##     data = TV16)
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -3.275514   0.172646  -18.97   <2e-16 ***
## age         -0.051241   0.003462  -14.80   <2e-16 ***
## ideo         0.651335   0.052333   12.45   <2e-16 ***
## age:ideo     0.021408   0.001051   20.36   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 59055  on 43429  degrees of freedom
## Residual deviance: 38579  on 43426  degrees of freedom
##   (21170 observations deleted due to missingness)
## AIC: 38587
## 
## Number of Fisher Scoring iterations: 5

These coefficients tell us several important things:

  1. Negative age coefficient (-0.051): For very liberal voters (ideology = 1), age has a negative effect on Trump voting. This means that among the most liberal voters, older age is associated with a lower probability of voting for Trump.

  2. Positive ideology coefficient (0.651): More conservative ideology is associated with higher probability of Trump voting, which is expected.

  3. Positive interaction term (0.021): This is crucial - it indicates that as ideology becomes more conservative, the effect of age becomes more positive. In other words, age has a different effect depending on one’s ideological position.

age_seq <- seq(20, 80, by = 10)
ideo_values <- c(1, 3, 5) 
pred_grid <- expand.grid(age = age_seq, ideo = ideo_values)

pred_grid$predicted <- predict(
  trump_interaction_model, 
  newdata = pred_grid,
  type = "response"
)

pred_grid$ideo_label <- factor(
  pred_grid$ideo,
  levels = c(1, 3, 5),
  labels = c("Very Liberal", "Moderate", "Very Conservative")
)

ggplot(pred_grid, aes(x = age, y = predicted, color = ideo_label, group = ideo_label)) +
  geom_line(size = 1.2) +
  geom_point(size = 3) +
  scale_color_manual(values = okabe_ito) +
  labs(
    title = "Age × Ideology Interaction Effect on Trump Vote Probability",
    subtitle = "How age influences Trump support across ideological groups",
    x = "Age (years)",
    y = "Predicted Probability of Voting for Trump",
    color = "Ideological Position"
  ) +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  theme_minimal() +
  theme(
    legend.position = "bottom",
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(size = 11),
    axis.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  )

Interpreting the Age × Ideology Interaction Effect on Trump Voting

The interaction model between age and ideology helps reveal the relationship in how these factors influence the probability of voting for Trump. Let’s analyze the model coefficients and predicted probabilities:

Predicted Probabilities Analysis

The predicted probabilities reveal striking patterns:

  1. For very liberal voters (ideology = 1):

    • The probability of voting for Trump decreases with age, from 3.8% at age 20 to 0.7% at age 80

    • This is counter to the common assumption that older voters are more likely to vote Republican

    • Liberal voters remain highly unlikely to vote for Trump regardless of age

  2. For moderates (ideology = 3):

    • The probability increases modestly with age, from 25.7% at age 20 to 43.0% at age 80

    • This represents a substantial effect of age (17.3 percentage point increase)

    • Age could potentially be a decisive factor for moderates, pushing some over the 50% threshold

  3. For very conservative voters (ideology = 5):

    • The probability increases dramatically with age, from 75.0% at age 20 to 98.8% at age 80

    • Conservative voters already have a high baseline probability, but age strengthens this tendency

    • Older conservative voters are nearly certain Trump voters (approaching 99% probability)

The Diverging Effects of Age

What’s particularly interesting is how the effect of age reverses direction across the ideological spectrum:

  • For liberals, older age slightly decreases Trump support

  • For moderates, older age moderately increases Trump support

  • For conservatives, older age strongly increases Trump support

This pattern suggests that age amplifies existing ideological tendencies rather than having a uniform effect. The older someone gets, the more their voting behavior aligns with their ideological position.

Conclusion: When to Use Logistic Regression

Logistic regression is the appropriate choice whenever you’re modeling a binary outcome. Key advantages include:

  1. Valid predictions: Always produces probabilities between 0 and 1, unlike linear regression.

  2. Proper error structure: Models the binomial distribution appropriate for binary data.

  3. Non-linear relationships: Captures the S-shaped relationship between predictors and probability.

  4. Multiple predictors: Can include any number of predictors, just like linear regression.

  5. Interactions: Can model how the effect of one predictor depends on the value of another.