Skip to main content

Guidance on the model formula

The link function transforms the linear predictor into a scale useful for modelling YY. In R, you specify this by a 'model formula' - something like Y ~ A + B + C.... This page explains how this works.

For example, in the linear regression example, we showed this regression:

    lm(
# model 'formula':
blood_pressure ~ genotype + another_variable,
# model data:
data = simulated_data
)

The line

blood_pressure ~ genotype + another_variable

is the model formula. There was something similar in the logistic regression example.

To figure out how this works, the first thing to know is that by default R silently adds something to your model formula

  • specifically it adds a '1'. So it works like this:
Formula you typeFormula you get
Y ~ AY ~ 1 + A
Y ~ A + BY ~ 1 + A + B

In other words, R is going to model your YY in terms of a constant variable 11 along with the other variables you have specified.

The second thing to realise is that the formula doesn't actually mean "Add 11 and AA and BB". Instead, the + signs mean "please add this variable as a term to the model". It works like this:

Formula you typeFormula you getLinear predictor you get
Y ~ AY ~ 1 + Aβ0+β1×A\beta_0 + \beta_1 \times A
Y ~ A + BY ~ 1 + A + Bβ0+β1×A+β2×B\beta_0 + \beta_1 \times A + \beta_2 \times B

Maths note. In writing maths it's common to use ⋅\cdot instead of ×\times to represent multiplication - or even just omit the times sign altogether. So we will often remove the ×\times sign altogether to make our formula shorter:

Formula you typeFormula you getLinear predictor you get
Y ~ AY ~ 1 + Aβ0+β1A\beta_0 + \beta_1 A
Y ~ A + BY ~ 1 + A + Bβ0+β1A+β2B\beta_0 + \beta_1 A + \beta_2 B

Smooth!

Definition of the linear predictor

The term on the right-hand side of the tables above is the linear predictor.

It is the sum of parameter×variable\text{parameter} \times \text{variable} for all of the variables you have put in the model, plus the added constant term.

Note that in your actual model fit the parameters won't be called β0\beta_0, β1\beta_1 and so on. Instead they'll be called something more useful that identifies which predictor variable they corresponded to. For example in the original example:

# A tibble: 3 × 5
term estimate std.error
<chr> <dbl> <dbl>
1 (Intercept) -0.0147 0.0224 ... This is β_0!
2 genotype 0.239 0.0299 ... This is β_1!
3 another_variable 0.0342 0.0201 ... This is β_2!

The wonderful thing about the linear predictor is that it can be any real number at all - that is, those parameters can take on any values at all; they are unconstrained. THis is true even though YY might be on different scales. It is the job of the link function to turn this back into an interpretable scale.