A Practical Introduction with R
Generalized Additive Models (GAMs) are an extension of Generalized Linear Models (GLMs) that:
Statistical Benefits:
Practical Benefits:
Basic form: \[g(μᵢ) = β₀ + f₁(x₁ᵢ) + f₂(x₂ᵢ) + ... + fₖ(xₖᵢ)\]
Where:
chicago
data death pm10median pm25median o3median so2median time tmpd
1 130 -7.4335443 NA -19.59234 1.9280426 -2556.5 31.5
2 150 NA NA -19.03861 -0.9855631 -2555.5 33.0
3 101 -0.8265306 NA -20.21734 -1.8914161 -2554.5 33.0
4 135 5.5664557 NA -19.67567 6.1393413 -2553.5 29.0
5 126 NA NA -19.21734 2.2784649 -2552.5 32.0
6 130 6.5664557 NA -17.63400 9.8585839 -2551.5 40.0
model1
gam
functiontemperature
and median pm 10
Common basis types:
Family: poisson
Link function: log
Formula:
death ~ s(tmpd) + s(pm10median)
Parametric coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 4.746282 0.001337 3549 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
edf Ref.df Chi.sq p-value
s(tmpd) 8.343 8.852 1789.7 <2e-16 ***
s(pm10median) 7.822 8.616 134.2 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) = 0.181 Deviance explained = 19.3%
UBRE = 0.56431 Scale est. = 1 n = 4863
Key components:
Parametric coefficients: - Intercept and linear terms
Smooth terms:
edf
: Effective degrees of freedomRef.df
: Reference degrees of freedomF-statistic
and p-value
Method: UBRE Optimizer: outer newton
full convergence after 6 iterations.
Gradient range [2.524847e-07,2.604434e-06]
(score 0.5643101 & scale 1).
Hessian positive definite, eigenvalue range [0.0001783152,0.0002205525].
Model rank = 19 / 19
Basis dimension (k) checking results. Low p-value (k-index<1) may
indicate that k is too low, especially if edf is close to k'.
k' edf k-index p-value
s(tmpd) 9.00 8.34 0.93 <2e-16 ***
s(pm10median) 9.00 7.82 1.01 0.78
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tmpd
extremestmpd
range visiblepm10median
associated with higher mortalityThank you for your attention!
Contact: drkamarul@usm.my