Professional Documents
Culture Documents
Antonio Gasparrini
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Scatterplot of x and y
15
10
5
y
0
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Non-linearity
Scatterplot of x and y
15
10
5
y
0
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Regression models
P
X
yi = α + f (xi ) + γp zip (1)
p=1
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Smoothing methods
Parametric
Polynomials, fractional polynomials, regression splines
In between
Penalized splines
Non-parametric
Lowess, kernel, smoothing splines
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
d
X
f (xi ; β) = βj bj (xi ) = xT β (2)
j=1
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Regression splines
2
N
X P
X
y − α − f (x; β) + γp zp = ||y − α − Xβ − Zγ||2 (3)
i=1 p=1
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Graphical representation - I
1.0
Splines
0.5
0.0
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Graphical representation - II
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
15
10
Terms
5
0
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Graphical representation - IV
Estimated relationship
15
10
5
y
0
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Graphical representation - V
15
10
5
y
0
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Number of knots
Degree of smoothness
15 df = 1
df = 3
df = 5
df = 7
10
5
y
0
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Knots location
15 5k at eq.−spaced val
8k at eq.−spaced per
10
5
y
0
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
P
X
yi = α + f (xi ) + f (zip ) (4)
p=1
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Penalty
2
N
X P
X Z
y − α − f (x; β) + f (zip ) + λ [f 00 (x)]2 dx (5)
i=1 p=1
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Penalized splines
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Smoothers
Alternative smoothers available, differing by parameterization and
penalty:
Thin-plate splines
Cubic splines
P-splines
Random-effects
Markov random fields
Soap film smooths
...
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Graphical representation - I
Increasing knots and splines
1.0
Splines
0.5
0.0
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Graphical representation - II
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
10
Terms
−5
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Estimation
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Advantages
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Comparison
Comparison of smoothing methods
Fractional polynomials
Regression splines
10 Penalized splines
5
y
0 2 4 6 8 10
x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Simulations
Comparing alternative methods:
Fractional polynomials
Regression splines
Penalized splines
Different shapes:
Linear
Decay
Peak
Complex
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Simulated shapes
Linear Decay
10 10
8 8
6 6
4 4
y
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Peak Complex
10 10
8 8
6 6
4 4
y
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Simulation results - I
Fractional polynomials
Linear Decay
10 10
8 8
6 6
4 4
y
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Peak Complex
10 10
8 8
6 6
4 4
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Simulation results - II
Regression splines
Linear Decay
10 10
8 8
6 6
4 4
y
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Peak Complex
10 10
8 8
6 6
4 4
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Linear Decay
10 10
8 8
6 6
4 4
y
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Peak Complex
10 10
8 8
6 6
4 4
y
2 2
0 0
−2 −2
0 2 4 6 8 10 0 2 4 6 8 10
x x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Simulation results - IV
Statistics
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
An example
1.10
1.05
RR
1.00 0
5
0.95
10
g
La
20
15 15
Tem 10
p erat 5
ure 20
(C) 0
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Penalized DLNMs
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Simulated surfaces
0.6 0.5
0.4
0.10
0.4
Outcome
0.3
Outcome
Outcome
0.2
0.05
0.2
0.1
0.00 0.0
0.0
10 10 10
8 0 8 0 8 0
6 10 6 10 6 10
x 4 20 x 4 20 x 4 20
g g g
2 30 La 2 30 La 2 30 La
0 40 0 40 0 40
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Simulation results
0.5
0.20
0.3
0.3
Outcome
Outcome
Outcome
0.05
0.1
0.1
−0.10
−0.1
−0.1
0 10 20 30 40 0 10 20 30 40 0 10 20 30 40
Lag Lag Lag
0.5
0.20
0.3
0.3
Outcome
Outcome
Outcome
0.05
0.1
0.1
−0.10
−0.1
−0.1
0 2 4 6 8 10 0 2 4 6 8 10 0 2 4 6 8 10
x x x
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
An application
3.0
1.3
2.5
1.2
2.0
RR
RR
1.2
1.1
1.5
1.1 1.0
RR
1.0
1.0
0
0.9
0.5
0.9 5
10
0 5 10 15 20 0 5 10 15 20 25 30
g
20
La
15
Tem 10
pera Lag Temperature
ture 0 20
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Example of code:
library(dlnm) ; library(mgcv)
cb <- crossbasis(x,lag=c(10), argvar=list(fun="ps"),
arglag=list(fun="ps"))
pen <- cbPen(cb)
model <- model <- gam(y ~ cb + z, data, family=gaussian,
method="REML",parapen=list(cb=list(pen)))
pred <- crosspred(cb,model)
plot(pred,"3d",xlab="x",ylab="Lag",zlab="Effect")
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Outline
1 The issue
2 Splines
3 A penalized approach
4 A comparison
5 An extension
6 Software
7 Some comments
Gasparrini A LSHTM
Smoothing with penalized splines
Outline The issue Splines Penalized Comparison An extension Software Comments
Some comments
Gasparrini A LSHTM
Smoothing with penalized splines