Monday 3 June, 2024 Esa L A Ar A
Monday 3 June, 2024 Esa L A Ar A
25 30 35 40 45
Gestational age (wk)
> with(births, plot(bweight ~ gestwks, xlim = c(24,45), pch = 16, cex.axis=1.5, cex.lab = 1.5,
+ xlab= "Gestational age (wk)", ylab= "Birth weight (g)" ) )
25 30 35 40 45
Gestational age (wk)
78 78
Standardized residuals
2
500
Residuals
0
0
−1000
−2
124
124
−2000
30
30
−4
1000 2000 3000 4000 −3 −2 −1 0 1 2 3
Fitted values Theoretical Quantiles
> par(mfrow=c(1,2))
> plot(m, 1:2, cex.lab = 1.5, cex.axis=1.5, cex.caption=1.5, lwd=2)
⇔ For each additional week the difference in mean bweight between H and N group
increases by 31.4 g.
▶ Interpretation of Intercept and “main effect” hypH?
Linear and generalized linear models 12/ 25
Model with interaction (cont’d)
More interpretable parametrization obtained if gestwks is centered at some
reference value, using e.g. the insulate operator I() for explicit transformation
of an original term.
▶ mi2 <- lm(bweight ~ hyp*I(gestwks-40), ...)
Estimate 2.5% 97.5%
(Intercept) 3395.6 3347.5 3443.7
hypH -77.3 -219.8 65.3
I(gestwks - 40) 183.9 163.5 204.4
hypH:I(gestwks - 40) 31.4 -8.3 71.1
▶ The “main effect” of hyp = −77.3 is the difference between H and N
at the reference value gestwks = 40.
▶ Intercept = 3395.6 is the estimated mean bweight
at the reference value 40 of gestwks in group N.
Linear and generalized linear models 13/ 25
Factors and contrasts in R
▶ A categorical explanatory variable or factor with L levels will be
represented by L − 1 linearly independent columns in the
model matrix of a linear model.
▶ These columns can be defined in various ways implying alternative
parametrizations for the effect of the factor.
▶ Parametrization is defined by given type of contrasts.
▶ Default: treatment contrasts, in which 1st class is the reference, and
regression coefficient βk for class k is interpreted as βk = µk − µ1
▶ Own parametrization may be tailored by ci.lin(mod, ctr.mat=CM) after
fitting, the pertinent contrast matrix given as the 2nd argument.
25 30 35 40 45
gestwks
25 30 35 40 45
gestwks
> library(mgcv)
> mpen <- gam( bweight ~ s(gestwks), data = births)