Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Outline
• The simple linear regression model
1
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Preliminaries
η(x) = E (Y |x)
η(x) = α + βx
2
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Linearity assumption?
η(x) = α + βx
Almost always thought of as an approximation to the truth. Functions in
nature are rarely linear.
7
6
f(X)
5
4
3
2 4 6 8
3
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Minimize:
N
X
(βˆ0 , β̂) = arg min (yi − β0 − βxi )2
β0 ,β i=1
Solutions are
PN
j=1 (xi − x̄)yi
β̂ = PN 2
j=1 (xi − x̄)
βˆ0 = ȳ − β̂ x̄
4
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
6
5
4
Y
3
2
1
5
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
yi = β0 + βxi + i
2 2
(yi − ŷi )2 /(N − 2).
P
Estimate σ by σ̂ =
Under additional assumption of normality for the i s, a 95% confidence
interval for β is: β̂ ± 1.96se(
ˆ β̂)
2
21
σ̂
se
ˆ (β̂) = P
(xi − x̄)2
6
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
h i 21
se[η̂(x)] = var(ȳ) + var(β̂)(x − x̄)2
2 2 2
21
σ σ (x − x̄)
= +
(xi − x̄)2
P
n
7
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• •
6
•
•
• •
•
• •• • ••
• •
• •
4
•
•• • •
• • •• • • •
• •
• • •
Y
•
• • •
2
•
• •
••
• •
• •
••
0
8
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Model is
p
X
f (xi ) = β0 + xij βj
j=1
f = Xβ
9
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
X p
X
β̂0 , β̂ = arg min (yi − β0 − xij βj )2
β0 ,β i j=1
β̂ = (XT X)−1 XT y
ŷ = Xβ̂
10
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
•
• •••
•
•• •
• • •• •• • • •
• • • • • •
•
•
• • • • ••
•• • • • • • •
•
•• • •• • X2
• •
•
X1
11
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
x2
ŷ
x1
(y − ŷ) ⊥ xj , j = 1, . . . , p
12
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Properties of OLS
• If X1 and X2 are mutually orthogonal matrices (XT1 X2 = 0), then
the joint regression coefficients for X = (X1 , X2 ) on y can be found
from the separate regressions.
Proof: XT1 (y − Xβ̂) = XT1 (y − X1 β̂1 ) = 0. Same for β̂2 .
13
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
14
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
σ2 n o
= σ 2 (XT X)−1 pp .
Var (β̂p ) =
||zp ||2
• Last statements true for all j, not just the pth (last) term.
15
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
The course canvas website has some additional more technical notes in
the supplements folder named linearR.pdf on multiple linear
regression, with an emphasis on computations.
16
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• Next page shows a scatterplot matrix of all the date. This is created
using the R expression
pairs(lpsa ∼., data=lprostate).
• Notice that several variables are correlated, and that svi is binary.
17
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Scatterplot matrix of
the Prostate Cancer
data. The top vari-
able is the response
lpsa, and the top row
shows its relationship
with each of the oth-
ers.
18
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Call :
lm ( formula = l p s a ∼ . , d a t a = l p r o s t a t e )
Coefficients :
E s t i m a t e S t d . E r r o r t v a l u e P r (>| t | )
( I n t e r c e p t ) 0.180899 1.320601 0.137 0.89136
lcavol 0.564355 0.087831 6 . 4 2 5 6 . 5 4 e−09 ∗∗∗
lweight 0.622081 0.200892 3.097 0.00263 ∗∗
age −0.021248 0 . 0 1 1 0 8 4 −1.917 0 . 0 5 8 4 8 .
lbph 0.096676 0.057915 1.669 0.09862 .
svi 0.761652 0.241173 3.158 0.00218 ∗∗
lcp −0.106055 0 . 0 8 9 8 6 6 −1.180 0 . 2 4 1 1 2
gleason 0.049287 0.155340 0.317 0.75178
pgg45 0.004458 0.004365 1.021 0.30999
R e s i d u a l s t a n d a r d e r r o r : 0 . 6 9 9 5 on 88 d e g r e e s o f f r e e d o m
M u l t i p l e R−s q u a r e d : 0 . 6 6 3 4 , A d j u s t e d R−s q u a r e d : 0 . 6 3 2 8
F−s t a t i s t i c : 2 1 . 6 8 on 8 and 88 DF , p−v a l u e : < 2 . 2 e−16
19
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
20
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
21
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
22
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• If the linear model is correct for a given problem, then the least
squares prediction f̂ is unbiased, and has the lowest variance among
all unbiased estimators that are linear functions of y (Gauss-Markov
thm)
• But there can be (and often exist) biased estimators with smaller
Mse .
23
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Model Selection
Truth MODEL
SPACE
Model bias
Estimation
Variance
RESTRICTED
MODEL SPACE
24
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Truth MODEL
SPACE
Model bias
Estimation
Variance
RESTRICTED
MODEL SPACE
25
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
26
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
vola.Lj — volatilityday−j , j = 1, 2, 3
We randomly selected a training set of size 50 and a test set of size 500, from the
first 600 observations.
27
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
-2 1 -2 1 -1 2 -1 1 -1 1 3 -2 0 2
• • • • • •• •• • •••• ••••••••• • • • ••• •••• •• ••••••••••• •• •••• ••• ••
• •••••••••••••• • •••••••••••••••• • •••• • ••• •••••••• • ••••• • • •••••••••••••••••••••• •••••• •• • • •••••••••••••• •• •
•••••••••••••••••••••••••••••
0.4
••••••••• • ••••••••••••••••••• • •••••••••••••••••••••••••••• •• •••••••••••••••••••••••••••• • ••••••••••••••••••••••• • ••••••••••••••••••••••• •• • •• •
••••••••••••••••••••••••••••••••• • ••• • ••••••••••••••••••••••••••••• •••••••••••••••••••••••••••••
volume •
•• •••• •• •
• • • • •
•••••••••• •••• • •••••••••••••••••••• • ••••••••••••••••••••••••• •
• • • •••••••••••• •••••••• • • •••••••••••• •••
•••••••••• ••••••••••••••••••••••••••••••• • • •••••••••••••••••• ••••••••••••••••••
• •••••••••
•••••••••••••••••••••••• 0.0
• •••••••••••••••••••••••• •••••••••••••••••••• ••••••••••••••••
• ••• •
••••••••••••••••••••• • •• ••••••••••• • ••••••••••••••••• •••••• •• •• ••••••••••• • ••••••••••• • •••••
•• •••••••••••••• • •••••••••••••• • •••••••••••• ••• • • • • •• ••• ••••••••• ••••••••• •••••••• -0.4
• •• • •• •• ••• ••• • •• • • • • • • • • •
2
•••••••••••••
•• •••••••••
•• • •• • •••••••••••••••• • ••••••••••••••• • ••••••••••• • •••••••••••••• ••• • ••
••••••••• • ••••••••••••• ••••• •• • • ••
•••••••••••• •••• • •••••••••••••••••••••••••
• • ••
••••••••••••••••••••••• ••••••••••••••••••••
0 ••••••••••••••••••• volume.L1 •••••••••••••••••••••••••••• • •••••••••••••••••••••••••••••••• • •••••••••••••••••••••••••••••••• ••••••••••••••••
• •••• • ••• • • •••• •
•
• •••••••••• •••••••••••••••••••••••••••••••••••• ••••••••••••••••••••••••••••• • •• •••••••••••••• •• •• •
••••••• • • •••••••••••••••••••••• •
•• • • • • • •••••••••••••••••••••• • •••••••••••••••••••••••••••••••••
•••••••••••••••••••••• ••••• •••••••••••• ••••••••••••• •• •••••••••• ••• •••••••••••••••••••••••• •• •••••••••••••••••••••• • ••••••••••••••••• ••••• ••••••• • •••••••••••••
•• ••• •• •• •••• ••• •••••••••••••••••• •••••••••••••••••••••••
-2 • • • •• •••• • •• •• ••••• •• • • •• • •
• •• • • •• • • • • • • •
•••••••••••••• • ••••• • • •• •••• • •••••••
• •• •• • ••••••••• • ••••••••••• • ••• • • •• •••• ••••••••• • • • •••• • • • ••••• • • • •••• 2
• •••••• •••••••••• • •••••••••••• •••••••••• •• ••••••••••••••••••• •••••••••••••••••
••• • •••• •••••••••••••••••• • • • •••••• •• • •••••••••••••••• ••••••••••••••••••••••••••••••••••• • ••••••• ••••••••••••••••••••
••••••••••••••••••• ••••••••••••••••••••• volume.L2 ••••••••••••••••••••••••••••••••••• • ••••••••••••••••••••••••••••••• • ••••••••••••• ••••• •• •••••••• • • •••••••••••••••••••••••••••• • • •
•••••••••••••••••••• •• ••••••
••••• • • • • •
••• •• • •••••••••••••••••••••• •
• • • • • • • ••••••••••••••••••• • •
••••••••••••••••••••••••••• 0
••••••••••••••••••••••••••••••• ••••••••••••••••••••••••• • ••••••••••••••••• ••
•••• •••••••••• •• ••••••••••••••••••••• • ••••••••••••••••••••••••••
• ••••••••••••••••• •••
••
•••••••••• • ••••••••••••••••••••••••••••• • •••••••••••••••
• •• • ••••••••• •••••••••••••••
• •• -2
• ••• ••••••• • •• •• •••••••••• • • •• ••••••••• •• • • •••• •••••• ••• • •••••••••
2 ••••••• •••• • ••••••••• • •••••••••••• ••• •••• • ••••••• ••• • ••• • • • • •••••
•••••••••••••••••••••••••• • •••••••••••••••••••••••••• •• ••••••••••••••• • •••••••••••• volume.L3 • •••••••• • •••••••••••••• • ••••••••••••••••••••••• •••••••••••••••••••••••••••• • • •••••••••••••••••••••••••••• •• ••••••••••••••••••• •••• ••• •• • ••• •
••••••••••••••••••••••••••••••• • •••••••••••••••••••••••••••••••••• • ••••••••••••••••••••••••••••••••••••••• •
• • ••
•••••••••••••••••••••••••••••••••••
0 •
•••••••••••••• •••••• • • •
••••••••••••• ••••••
•••• • • •
••• ••• ••• • •
•• ••••••• •• ••• • • •••••• •••
•••••••••••••• •••••• •
••••••••••• •••••••••••••• •• •
• ••••
•• ••••••••••••••••••• ••• •••••••••••••••
••••••••••••• • •••••••••••••••• ••••••••• • ••••••••••••••••• •• • ••••••••••••
•• • •••
•••••••••••• •••• •••••••••••••• • •••• •••••••• •• •••• •• •
••••••••••••• • •••••••••••••••••••••
-2 • ••••••••••• ••••••• • •••••••••• • •
•••••• •• • •••• ••••• • • •• ••
•• ••••••
••• •
• •••
•• ••
••••• •
•
•• ••
•
•• ••••
• • •• 2
• •
•••••••••••••••••• •• ••••••••••••••• ••••••••••••••••• • • • • • • •• • • ••••••••••••••••••• •••••••••••••••• •
•
•••••• •••••••••••••••••••••• •••••••••••••• •• •••• •• • • •
•• ••••••••••••••••••
••••••••••••••••••••••••• •
•••••••••••••••••••••••••••••• • ••• ••••••••• • •• • ••• •••••••••••••• • •••••••••••••••••••••••••• • retd.L1 ••••••
••••••••••• ••••••••••••••••••••••••••••••• •• • ••••••••••••••• •••••••
••••
••••••••••••••
•
•••••••••••••••••••••••••••• • •••••••••••• •••••••••••••••••••••••••••••• ••••••••••••• ••••••••••••••••••••••••••••••
•••• ••••••••••••• ••••••••••••••••••••••• ••••••••• •••••••••• •••• • •••••••••••••••••••••••••••• •• •••
••••• •••
•••••••••• ••• • ••
••••
•• •••••••••• ••• •••••••••• • • •• •••••• • •
•••••••••••••••••••
• • • •
•••••••••••••••••••• 0
•• ••• •• • • •• ••• • •••• ••• • ••• •
•••••
•• • • ••• • • • •• • -2
• •• ••• • •• • •• • • • • • •• •• •
• • • ••• • • •• • • • •• • • • ••• •••••••••
••••••••••••••••••
1 •••••••••••••••••••••••• ••••• •••••••••••••• ••••• • • •• ••••••••••••••••• •• •••••••••••••••••••••• •• •••••••••••••••••••• ••••••••••••• ••••••••••••••••••••• • •••• •••••••••••••••••••• •••••••••• •••••••••••••• •••••••••••
•
••••••••• • • • • • • •• • • • •
•••••••••••••••• ••••••••••••••••••••••••••• ••••••••••••
• ••• •••
• • • • • • • •• •
•••••••••••• •••••••••••••••••••••••••• • •••••••••
• • • • • • • •••••••••••••• •
•• retd.L2 •••••••••••••••••• ••••••••• •••••••• • ••••••••• •• • • •••••••••••• •••• •••••••••••••••••••••• • •
••• •• • • • •• • • • • • • •
••••••••••••••••••••••••••••••••
••
• •• •
• ••
• • • •
•••••••••••••••••••••••••••••
• • • • • •
••••••
•••••••• • ••••••••• • •
•• ••
•••••••••• • •• •••••• • ••• • • • •
••• • • • •••••
••• ••••••••••• • • ••••••••••••••••••••••••••••• • ••• ••••• ••
-1 ••••• • • •• •• •• •• ••• • ••• •• • • ••••• •• • •• •
• •• • • •• • •• • •• • • • • • •• • •••
• ••• • • • • • • ••• •••• • • ••• 2
••••••••••••••• ••••••••••••• •••••••••••••••••••••••••••• • ••••••
•••••• ••••••••••••••••••• ••••••••••••••••• •• •••••••••••••••••••••••••• • •
•••••••••••••••••••••••••••••• • •••••••••••••••••••• ••••• • ••• •
•••••••••••••••••••••••••••••••••••••• ••••••••••••••••••••••
•
•••••••••••••••••••••••••••••••••••••
• • • • • •• •• • •• •• • • • • • • •••• retd.L3 ••••• •••••••••••••••••••••••• ••••••••••••••••••••• • • ••••••••••••• •••••••••••
•••••••
• • • • • • • • • • • • •
• • •••••••• • • •••••••••••••••••••••••••••• •••••••••••••••••••••••• ••• • ••••••••••••••••••••••••• •• •••••••••••••••••••••••• •
• • •• • • •••••••••••••••••• • ••••••••••••••••• •••• •• •
•••••••••• • • • • ••••••• • ••••••••••••• • • •••••• • •••••••• ••••••• •
•••••••••••••••••• • •• ••••••••••
0
••••••••••• •••• •••• •• • • • • ••• ••••• •• ••• •••• • • •• •••• •••••••• •• •• -2
• • ••• •• • •• • •• ••• • • • • ••• •• • • • • •••• • ••••• •• ••••
••••••• • • •• ••• • • ••••••• •• ••• •
•
••• • • • • •• •• • ••• •••• • •• •
•••••• •• •
•••••••••••••••••• ••• ••••• • • •• • • • •••••••••• •• •••••••••••••••••• ••• •••••••••••• ••••••••••••••••••••• ••• ••••••••••••••• •••• •• •• ••••• •••• •
1
••••••••••••••••••••••••••••••• ••••
• • ••
•••••••••••• • ••••••••••••
• •
•••••••• •••••••••••••••••••••••••
•••• •• ••
•••••• •••••••••••••••••••• •
aretd.L1 •••••••••••••••••• • •• ••• • • • •• ••••• • ••••••••••••••••••••••••••••••••••
••••••••••••• •••••• •••••••••• ••••••••••• •••••••••••••••
•••••••••••••• •• • ••••••••••••••••••••• •••••••••••••••••••••••••••••••••••••••
-1 ••• •••••• • • ••••• ••••••••••••••• •••••••••• •••••••••••••••• • • •••••••••••••••••••••••••• ••••
•••• • ••••••••• •• ••••• •• ••• •••••••••••• ••• ••••••••••••••••
•• •••• •••••••• •••••••••••••••••••••••• ••••••••••• •••••••••••••••••••••
• •
• • •• • • •
• •• • •• • • •• •• •• •• •
• • • • • •• • •• • •
••••••••• ••• •• •
•••••••••••• • • ••••••••••••••• ••• ••••••••••••••• • ••••••••••••••••••••
• • • • • ••• • •• ••• • ••• •
• • •
•
• ••••••••••••• • • •••••••••••• •
•
• ••••••••••••••• •
•• • ••
•• •••••••••••••••••
•••••••••••••••••• ••• ••• • •
•••••••••••••••• • • • • •••• • aretd.L2 1
• •
••
• • •• • • • •• • ••• • ••
•••••••••••••••••••••••••••••• ••••••••••••••••••••••••••••••• • ••••••••••••••••••••• • • • • • • ••• •• • • • •
•••••••••••• •••••••••••••••••••••••••••••• ••• •••••••••••
• • •• •••••••••••• • •••••••• •••••••• ••••••••••••••••••••••••••••••••••• •••• •••••••••••••••••• •
•• • • • ••••
•••••••••••••••••••••
•
• • ••
••• ••• • • • •• • • • • •
•••••••••••••• ••••
••••••••••••••••••••••••••••••••••••
•
• • • •• • •••••• •
• • •
• •••
•• •• •••••••••••••••• •
••••••• ••••••• • ••••••••••••••••••••••• •••••••••• •••••••••••••••••••••••• -1
3 • • • • • • • • • • • •
•••••••••••••• •••••••• •••• • •
•••••••••• • • •• •••••••••• •••
• • • •
••••••••••••••• •
•• • ••• • ••
••• •• ••••• •••• • •• ••• ••••• ••• • • ••
•••••••••••••• • •••• • ••
• •••••••••• •• ••• ••• ••••••••••••••• • •••••••••••••••• • ••••••••••••••••••
1 •••••••••••••••••••••••• ••••••••••••••••••••••••••• ••••••••• ••••••••••• • • ••••••••••••••••• • • •••••• • •••••• ••••••••• ••••••••••••••••••••• •• aretd.L3
• •••••••••• •
• • •••••••••••
••••••••••••••••••••••••••••••••••••••
•••••••••••••••••••••••••••• • •••••••••••••••••••••••••• • ••••••••••••••••••••••••••••••••• ••••••••••••••••••••••••••••••••••• • •••••••••••••••••••••••••••••••••••• ••••••••••••••••••••••••••••••••••• • ••• •••
••
••••• •
••••••••••••••••••••••••• •
•••••••••••••••••••• • •
••••••••• ••• ••••••••••••••••••••••••••••••• •••
••••••••••
••••••••••• ••••••••••••••••
•••• •••••• •
-1
• • • • • • • • • • • • • ••• 2
••••••••••••••••••••••••• • •••••••••••••••••••••••••• • •••••••••••••••••••••••••• • •••••••••• •••••••••• •• ••••••••••••• •• •••••••••••••• •••• •••••••••••••••••••• •• • ••••••••••••••• •••• •••••••••••••••• •••
•••••• •••••••••
• • •• •••••• •••••••
•••••••
••••••••••••••••••••••••••••••••• • ••••••••••••• ••••••••••• • •••• ••••••••••••••••••• •••••••••••••••••••••••••••••••• •••••••••••••••••••••••••••••••••••• •••••••••••••••••••••••••••• ••••••••••••••••••••••••••• •••••••••••••••••••••••••••••• • •••••••••••••••••••••••••••••• •••••••••••••••••••••••••••••••• ••••• ••••••••••• ••••••••••••••••••••••
•••••••••••••••••• ••••••••••••••••••••• • ••••••••••••••••••• •••••••••••••••• •••••••••••••••• ••••••••••••••• •••••••• • •• vola.L1 •
••••••
• 0
•••••• •••••••
• ••• •• • • • • • •• • •• •••••••••• • •
•••••
•••••• •••••••••••••••• • •••••••••••
•• •••••
•••• •••••••••••
-2
2 • • • • • •• • • • • • • •• •••
•••••••••••••••••••••••• • •••••••••••••••••••••• • • •••••••••••••••• •••••• • •••••••••• ••••••••••••• •• •• •••••••••••••••••••••••• • •
•• ••••••••••••••••••••• • •• ••••••••••••••••••• •• • ••••••••••••••••••••••• •• ••••••••••••• ••• ••• •••••••••••••• • ••••• ••• •••••
0 ••••••••••••••••••• ••••••• ••••••••••••••••••• • •••••••••••••••••••• ••••••••••••••••••••• • •••••••••••••••••••
• ••••••••••• •• • • ••• • ••••• •
•••••••••••••
••••••• • ••••••••••••••••••••• •••••••••••••••••••••• ••••••••••••••••••••••••••• ••••••••••••••••••••••••••••• •• •••••••• • vola.L2 •••••••••••••••
••••••••••••••••••••••••
••
•• •••••••••••• ••••••••••••••••••••••••• • •••••••••••••••••••••• •• •••••••••••••••••• • ••••••••••••••••••••• •••
•••••
•••••••••••••• •••••••••••••• •• •• • •
••••••••••••••••••• • ••• •••
••••••••••••• ••••••••• • ••••
-2 •• • •• •••••••• ••••••• •••••••
• • • • • •• • • • ••• • • •• • •• ••• •• • •• • •• •
••••••••••••••••••••••• • •••••••••••••••••••• • •••••••••••• •••• • ••••• •••••••••••• • • •••••••••••••••••••• •• ••• ••••••••••••• • •• ••••••••••••••••••••••• •• •••••••••••••••••••••• •••• ••••••••••••••••••••••• ••• •••••••••••••••••••••••••••• •••••• •••••••
•• ••• • •• •••••• • • •• •• •• •• ••• • ••••• •• •••••••••••••••••••••••••••• ••••••••••••••••• •••••••••••••••••••••••• ••••••••• ••••• •
•• ••••••••••••••••••••••••••••••• •••••••••••••••••••••••••• ••••••••••••••••••••••• ••• ••••••••••••••••••••••••••••• • ••••••••••••••••••••••••••••• •••••••••••• •••••••••••••••••••• ••• •••••••••••••••••••• • •• • • •
•
•• • vola.L3 0
•••••••••••••••••••• •••••••••••••••• • • ••••••••••••••• • ••••••••••••••••• •••••••••••••••••• ••
•••••••••••••••••• ••••••••••• ••••• ••••••••• ••••• • ••••••••••••••••• • ••••••••••• ••••••••• ••••• ••
• •• • •• ••• •• • •• • • • ••• •• •••••••• •••••• -2
-0.4 -2 1 -2 1 -2 1 3 -1 1 -2 0 2 -2 0
28
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
OLS Fit
29
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Subset selection
We retain only a subset of the coefficients and set to zero the coefficients
of the rest.
There are different strategies:
• All subsets regression finds for each s ∈ 0, 1, 2, . . . p the subset of
size s that gives smallest residual sum of squares (training error). The
question of how to choose s involves the tradeoff between bias and
variance: can use cross-validation (see below)
• Rather than search through all possible subsets, we can seek a good
path through them. Forward stepwise selection starts with the
intercept and then sequentially adds into the model the variable that
most improves the fit. The improvement in fit is usually based on the
RSS.
• Backward stepwise selection starts with the full OLS model, and
30
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• There are also hybrid stepwise selection strategies which add in the
best variable and delete the least important variable, in a sequential
manner.
31
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
100
•
••
• •
•
80 • •• ••
• •• ••
Residual Sum-of-Squares
• • •
•• •• •• •
60
•• •• •• ••
• •• ••• • •
• •• •• ••
• •• •• •• •• •
•• •
40
•• ••• ••
•• • •• •• • •
••• •• •
20
0
0 1 2 3 4 5 6 7 8
Subset Size k
All possible subset models for the prostate cancer example. At each
subset size is shown the residual sum-of-squares for each model of that
size.
32
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Model Assessment
Objectives:
1. Choose a value of a tuning parameter for a technique
2. Estimate the prediction performance of a given model
For both of these purposes, the best approach is to run the procedure on
an independent test set, if one is available
If possible one should use different test data for (1) and (2) above: a
validation set for (1) and a test set for (2)
33
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
K-Fold Cross-Validation
34
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• do this for many values of λ and choose the value of λ that makes
CV (λ) smallest.
35
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• β̂ −k (λ) are the coefficients for the best subset of size λ, found from
the training set that leaves out the kth part of the data
36
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
37
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• This process is repeated many times and the results are averaged.
38
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Cross-validation- revisited
39
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
40
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
41
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
42
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
CV was used on the 50 training observations (except for OLS). Test error
for constant: 0.061. Hence test R2 = 33% (% variance explained).
43
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Crossvalidation results
for NYSE data
Estimated prediction error
curves for the various selec-
tion and shrinkage methods.
The broken line indicates the
estimated minimizing value
of the complexity parameter.
Training sample size = 50.
44
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
1.8
1.8
sults for Prostate
1.6
1.6
• •
1.4
1.4
Cancer data
1.2
1.2
CV Error
CV Error
•
1.0
1.0
•
0.8
0.8
• •
• • • • •
0.6
0.6
• • • • • • •
Estimated prediction error 0 2 4 6 8 0 2 4 6 8
Subset Size Degrees of Freedom
1.8
1.8
tion and shrinkage methods.
1.6
1.6
• •
1.4
1.4
The vertical line indicates
1.2
1.2
CV Error
CV Error
•
1.0
1.0
the value of the complexity •
0.8
0.8
• •
• • • • • • • • •
0.6
0.6
• • •
parameter within one stan- 0.0 0.2 0.4 0.6 0.8 1.0 0 2 4 6 8
Shrinkage Factor s Number of Directions
•
1.4
•
•
0.6
• • • • • •
67. 0 2 4 6 8
Number of Directions
45
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Ridge Regression
Equivalently,
46
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• lcavol
••
0.6
•
•
•
•
•
•
•
0.4 •
•
•
•
• • svi
• • • • •• •• •• •• lweight
• •• • • • • pgg45
Coefficients
• •
• • •
• • •• • •• • lbph
0.2
• •• • • • •• •• • • •
• •
• • • • • • • •
• • • • • •
• • • • •
• • • • • • • •
• •
• • • •• ••• •
•• •• •• •• • • • •
• • • • • • • • • • • • • •
•• •• • • • • • • • • • •
• • • • ••
0.0
• • • •
• • • • gleason
• • •
• ••
•• • • •
• ••
• • age
•
•
-0.2
• lcp
0 2 4 6 8
df(λ)
47
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
With linear regression, the number of free parameters that determine the
model is called the degrees of freedom or df.
Suppose the vector of fitted values on the training data is given by
ŷ = Hy. Then
df = tr(H).
H is the LS projection matrix (idempotent). If X is full column rank, then
H = X(XT X)−1 XT .
By analogy, for ridge regression, if ŷλ = Hλ y, then
def
df(λ) = tr(Hλ ).
48
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
The Lasso
The lasso is a shrinkage method like ridge, but acts in a nonlinear manner
on the outcome y.
The lasso is defined by
βj2
P P
• Notice that ridge penalty is replaced by |βj |.
49
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
β2 ^
β
. β2 ^
β
.
β1 β1
50
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Transformed Lasso
Coefficient
Ridge
Coefficient
51
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Lasso in Action
Profiles of coefficients
for NYSE data as
lasso shrinkage is var-
ied. s = t/t0 ∈
[0, 1], where t0 =
P
|β̂OLS |.
52
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
0.6
0.4
svi
lweight
pgg45
Coefficients
lbph
0.2
0.0
gleason
age
−0.2
lcp
Shrinkage Factor s
53
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
for q ≥ 0. The contours of constant value of j |βj |q are shown for the
P
Thinking of |βj |q as the log-prior density for βj , these are also the
equi-contours of the prior.
54
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Let X be the data matrix and X̃ the data matrix with centered columns.
The largest PC direction v maximizes Var(Xv)
d = N1 vT X̃T X̃v subject
to ||v||2 = 1. One can show that the eigenvector equations
T
1
N X̃ X̃vj = d2j vj , j = 1, . . . , p
55
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
4
Largest Principal o
Component
o o
o o oo o o
2
o oo o o
ooooo o
oooo o
o o oo
ooo oo o o ooo o o o
o o o
o o o o oo o o
o ooo ooooo o ooo o o
o ooooo ooooo o o oo o
X2
oo oo oo o o
o
0
o o o o oo ooo oo oo o
o o oo
o
o
o o oo oo o
oo o ooooo
o ooo ooo
oo o o
oo oo oooooooo o o
o o o o
o o o o oo o o
o ooo oo o o
o o oo o
o o
-2
oo o o
oo o Smallest Principal
o
Component
o
o
-4
-4 -2 0 2 4
X1
56
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
57
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
58
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
• • • • • • •
1.0
•
0.8
•
Shrinkage Factor
•
0.6
•
• •
0.4
ridge
pcr
•
•
0.2
• •
0.0
2 4 6 8
Index
59
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
60
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
61
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
62
ESL Chapter 3 — Linear Methods for Regression Trevor Hastie and Rob Tibshirani
Frank and Friedman (1993) show that ridge and PCR outperform PLS in
prediction, and that they are simpler to understand.
Lasso outperforms ridge when there are a moderate number of sizable
effects, rather than many small effects. It also produces more interpretable
models.
Elastic net combines ridge and lasso penalties: (1 − α)kβk22 + αkβk1 .
Good for sparse models but correlated predictors.
These are all topics for ongoing research, and have become extremely
relevant with massively wide datasets.
63