Bending the rules

Conditional saliva

🔔💦

Case 11: Conditioned on age

At AalboR Statistical Hospital, clinicians have been reviewing data from patients who underwent exercise testing as part of their cardiac evaluation.

One of the variables recorded during the test is maximum heart rate. When looking at the data as a whole, the clinicians notice an interesting pattern: patients with heart disease tend to have lower maximum heart rates than patients without heart disease.

At first, this seems fairly straightforward.

During a case discussion, however, a cardiologist points out something that makes the pattern less convincing:

“Before we interpret this relationship, we should remember that maximum heart rate also changes with age. A maximum heart rate that seems unusually low for a younger patient may not be unusual for an older patient.”

This prompts the team to look more closely at the data.

They begin comparing patients of different ages and notice that the relationship between maximum heart rate and heart disease does not look quite the same everywhere in the dataset.

What initially appeared to be a simple relationship may depend on who the patient is.

You are asked to investigate this pattern in the hospital’s patient data. The challenge is to understand what happens to the relationship between maximum heart rate and heart disease when we consider patients conditional on their age — and whether the relationship itself changes across ages.

The findings may reveal something that is easy to miss when looking only at the overall data.

Case supplemental material

Boxplot showing decreased max heart rate for heart disease patients

Scatter plot supporting the cardiologist’s statement

Follow-up data visualization based on the cardiologist’s statement

AalboR Statistical Hospital internal review data at the meeting

Deadly asbestos - according to whom?

Anyone knows what this is?

Read section 13.4

Conditional bells or cigarrts

  • conditioning: Dependence on state
  • everything is conditional
    • on data
    • on model
  • Interaction: Influence of predictor conditional on other predictor

Conditional modulation or interaction

When variable \(z\) changes the effect of \(x\) on outcome \(y\)

Do you have examples in your life?

Talk to your neighbor!

The additive assumption and linear assumption of regression

Reading task 13.5

The additivity assumption

  • the association between a predictor \(X_j\) and the response Y does linear not depend on the values of the other predictors.

The linearity assumption

  • the change in the response Y associated with a one-unit change in \(X_j\) is constant, regardless of the value of \(X_j\).

Making a regression model

Age is continuous: 0 — 125

Heart disease is binomial: {0,1} — yes or no.

\[ MaxHR_i = α + β_1Age_i \]

Now, what do we do with HD?

One question, two models…

We could split the data in two:

Those that have heart disease and everyone else…

(a) Regression fit for each group

… but no answer


Call:
lm(formula = MaxHR ~ Age, data = subset(hd_data, HD == "yes, heart disease"))

Coefficients:
(Intercept)          Age  
   160.0856      -0.3678  

Call:
lm(formula = MaxHR ~ Age, data = subset(hd_data, HD == "no heart disease"))

Coefficients:
(Intercept)          Age  
    213.928       -1.056  

No estimates for the estimand: MaxHR ~ HD | Age

In words, is the effect of heart disease on max heart rate mediated by age?

No value from pooling (σ and other uncertainty estimates)

Let’s try something else!

Any ideas?

Adding the variable to a regression model is not enough

\[ MaxHR_i = Normal(μ_i, σ) \]

\[ μ_i = α + β_1Age_i + β_2HD_i \]

Only adjust intercept!

  • It adds a constant \(β_1HD_i\) but the slope remains identical…

1hd_data <- medisr::hd_data

2model_additive <-
    lm(MaxHR ~ Age + HD,
    data = hd_data)

3library(marginaleffects)

4plot_predictions(
    model_additive,
    condition = c("Age", "HD")
)
1
First, we load in the dataset.
2
Next, we make a simple linear model adding the two variables of interest.
3
Here, we load the {marginaleffects} package
4
We plot how the model predicts the max heart rate based on age for both patients with and without heart disease. Note how we add the model variable and give a string vector to the argument condition.

We know they should not be parallel

(a) Subset models
(b) Raw data
Figure 2

Reading task: Making non-additive terms in linear models

Read section 13.8: Making non-additive terms in linear models

Conditional multiplication

Consider the cancer risk explained by asbestos exposure (h) conditioned on smoking status (or pack-year).

Asbestos exposure (h) (\(X_1\)) smoking status (\(X_2\)) Interaction effect (\(X_1X_2\))
2 yes = 1 2
3 yes = 1 3
2 no = 3 6
3 no = 3 9

Conditional effects = Interaction effects

Additive models: Where the effect of one predictor does not depend on the other predictor.

Interaction models: Where the effect of one predictor can depend on the other predictor.

Adding an interaction - the equation

\[ y_i = Normal(μ_i, σ) \]

\[ μ_i = α + β_1Age_i + β_2HD_i + {\color{purple}{β_3Age_iHD_i}} \]

Adding an interaction - in R

Figure 3: Heart rate decline as a function of age conditioned on heart disease.

Adding an interaction in R

model_interact <-
    lm(MaxHR ~ Age + HD + Age:HD,
    data = hd_data)

same_model_interact <-
    lm(MaxHR ~ Age * HD, # expands to Age + HD + Age:HD
    data = hd_data)

Getting our estimand

(Intercept)         Age       HDYes   Age:HDYes 
213.9282010  -1.0563804 -53.8425770   0.6885871 

Finally, we have a coefficient for the interaction effect!

Interpreting interactions

  • Add interaction -> other parameters change meaning
  • Influence of predictor depens upon multiple parameters and their covariation

Experience interpreting interactions

Read the sections

  • “13.10 Interpreting an interaction estimate”

It’s a bit long…

Interpreting interactions together

Let’s try it together:

We model quality of life.

Sick = {0,1} no/yes Age = continuous

We get:

Coefficient Value
Intercept 10
Age 2
Sick -20
Age × Sick -1
  • What is the regression coefficient?
  • What is the intercept representing?
  • What is Sick representing?

Interpreting interactions together

Here’s the regression equation:

\[ \bar{Y} = 10 + 2 * age - 20 * sick - 1 * (age × sick) \]

  • What if I’m 32 years old and not sick?
  • What if I’m 24 years old and sick?

Symmetry of interactions

Which of the following questions have we been modeling until now:

How much does the influence of age (on max heart rate) depend on whether the patient has a heart disease?

or

How much does the influence of having a heart disease (on max heart rate) depend on age?

Reading task

section 13.11 Symmetry of the linear interaction

If the effect of HD depends on age

Figure 4: Heart rate as a function of age conditioned on heart disease.

Thought experiment: Effect of getting HD

  • If I give people a HD, how will their maxHR change depending on their age?

Plotting the slope

Thought experiment: Effect of getting age

  • If I make patients younger/older, how will having HD affect their maxHR change?

What if we have two continuous variables we allow to interact?

caption

What if we have two continuous variables we allow to interact?

  • MaxHR
  • Chol
  • Age

What if we have two continuous variables we allow to interact?

\[ μ_i = α + β_xx_i + β_zz_i + β_{xz}x_iz_i \]

Change in Y per unit change in x

\[ \frac{\partial μ}{\partial x} = β_x + β_{xz}x \]

Change in Y per unit change in x

\[ \frac{\partial μ}{\partial z} = β_z + β_{xz}z \]

What if we have two continuous variables we allow to interact?

Meaning of parameters change when you add interaction:

  • The coefficients are now non-linear
  • coefficients in model without interaction:
    • change in outcome per unit change in predictor
    • e.g., when age increase 1 year, MaxHR increase 0.50 BPM
  • Coefficients within interactions:
    • Change in outcome per unit change in predictor when other predictor is zero
    • e.g., change in MaxHR per unit change in age when HD is zero

Interpreting continuous interaction

α: when x and z = 0

z: change in y per unit change z, when x = 0.

x: change in y per unit change x, when z = 0.

xz: interaction. Don’t even try… Just plot!

Pain relief as an example


Call:
lm(formula = MaxHR ~ Age + Chol + Age:Chol, data = hd_data)

Coefficients:
(Intercept)          Age         Chol     Age:Chol  
 251.955403    -2.004447    -0.194792     0.004053  

Unlike the HD condition {yes/no}, both Chol and Age have infinite values!

How to we plot that? 👀

Triptych plotting

Raising of the Cross, Rubens, 1610–11, Antwerp Cathedral

Raising of the Cross, Rubens, 1610–11, Antwerp Cathedral

A triptych (/ˈtrɪptɪk/ TRIP-tik) is a work of art (usually a panel painting) that is divided into three sections, or three carved panels that are hinged together and can be folded shut or displayed open.

Max heart rate exampled by age conditioned on cholesterole

Questions about interaction?

Otherwise, we’ll shift gears a bit….

Polynomials - bending the rules, literally!

Remember the linearity assumption?

Question:

  • Imagine two variables that don’t have a linear relationship

Human height is not linear! Is regression broken?

Demographic data from Kalahari !Kung San people collected by Nancy Howell

Polynomials - bending the rules, literally!

Can we use interaction?

Well, sort of — In this case, the variable is interacting with itself!

Polynomial madness

Polynomial degree Regression model
1 \(y = \beta_0 + \beta_1 x\)
2 \(y = \beta_0 + \beta_1 x + \beta_2 x^2\)
3 \(y = \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3\)
4 \(y = \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 + \beta_4 x^4\)

Polynomial madness

Live demo:

shiny::runApp("apps/polynomial-app/app.R")

Discussion of polynomial regression

Think for yourself for 3 minutes:

  • Which model is the best?
  • What makes some models better or worse?
  • Would you trust predictions from these models? Which would you (not)?

Talk to your neiggbour and try to come to agreement.

Interaction madness

Imagine we wanted to predict heart disease.

logit(p) = HD

We could use the variables:

  • Chol Cholesterole
  • RestBP resting blood pressure
  • MaxHR
  • ChestPain type of chest pain (if present)
#| echo: true
#| code-fold: true

five_way_model <- glm(
    as.factor(HD) ~ Chol * RestBP * MaxHR * ChestPain,
    family = binomial,
    data=hd_data
    )

Interaction madness

# Fixed Effects

Parameter                             | Coefficient
---------------------------------------------------
(Intercept)                           |      -39.08
Chol                                  |        0.10
RestBP                                |        0.34
MaxHR                                 |        0.19
ChestPainnonanginal                   |      -24.81
ChestPainnontypical                   |     -321.23
ChestPaintypical                      |      263.16
Chol:RestBP                           |   -6.82e-04
Chol:MaxHR                            |   -4.17e-04
RestBP:MaxHR                          |   -1.71e-03
Chol:ChestPainnonanginal              |        0.11
Chol:ChestPainnontypical              |        1.33
Chol:ChestPaintypical                 |       -1.08
RestBP:ChestPainnonanginal            |        0.15
RestBP:ChestPainnontypical            |        2.23
RestBP:ChestPaintypical               |       -2.51
MaxHR:ChestPainnonanginal             |        0.23
MaxHR:ChestPainnontypical             |        1.90
MaxHR:ChestPaintypical                |       -1.77
Chol:RestBP:MaxHR                     |    2.91e-06
Chol:RestBP:ChestPainnonanginal       |   -7.17e-04
Chol:RestBP:ChestPainnontypical       |   -9.36e-03
Chol:RestBP:ChestPaintypical          |        0.01
Chol:MaxHR:ChestPainnonanginal        |   -1.06e-03
Chol:MaxHR:ChestPainnontypical        |   -8.01e-03
Chol:MaxHR:ChestPaintypical           |    7.64e-03
RestBP:MaxHR:ChestPainnonanginal      |   -1.48e-03
RestBP:MaxHR:ChestPainnontypical      |       -0.01
RestBP:MaxHR:ChestPaintypical         |        0.02
Chol:RestBP:MaxHR:ChestPainnonanginal |    6.95e-06
Chol:RestBP:MaxHR:ChestPainnontypical |    5.66e-05
Chol:RestBP:MaxHR:ChestPaintypical    |   -6.66e-05

Interaction madness

Oh my, that’s a lot of coefficients! 👀

How in the world are we ever going to interpret this monster?! And now it’s a logistic regression, so the coefficients are in log-odds! 😅

Truth is — we can’t infer much (if anything at all) from the coefficients alone. We would need to do a marginal effect estimate, which we’ll cover in ?@sec-marginal-effects.

Example of interaction madness

Genetics x environment

We believe that genes are expressed conditional on lived experiences:

  • Adverse Child Experiences (psychiatry)
  • Exposure to toxins/viruses (nervous system)
  • Availability to food (obesity)

These could be 50-way or 1000-way interactions!

Exercises:

Go to the website

You know what to do!