penalized regression bmtry 726 3/7/14. maximum likelihood has been a statistics “staple” (and...

45
Penalized Regression BMTRY 726 3/7/14

Upload: whitney-lifton

Post on 16-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Penalized Regression

BMTRY 7263/7/14

Page 2: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Maximum LikelihoodHas been a statistics “staple” (and still is)

ML approach-specify a distribution for our data -From this obtain a log-likelihood function, , which specifies how likely the data are for various values of the unknown parameters-Estimate the parameters by maximizing

In regression we also use likelihood ratio tests to conduct hypothesis testing about regression parameters and models

f x

L x

L x

Page 3: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Maximum LikelihoodHowever, maximum likelihood estimation can be unsatisfactory

-Lack of interpretability: when p is large we may prefer a smaller set of predictors to determine those most strongly associated with y

-Large variability: when p is large relative to n, or when columns in our design matrix are highly correlated, variance of parameter estimates is large

Page 4: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Subset SelectionWe began to address the issue of interpretability of a

regression model using the idea of subset selection

(1) Examine all possible subsets of predictors from 1 to p and compare models on some criteria (Cp, AIC, …)

-Computationally difficult for p > 30

(2) Use a stepwise procedure to select a subset-Forward selection: start with null model and add predictors one at a time according to most significant F-value until no additional predictors have F-value < a -Backward selection: Start with all predictors and

remove least significant until all predictors have F-value < a

Page 5: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Problems with Subset Selection

The first method is more systematic but still may not provide a clear best subset

The second method is done post-hoc and generally can’t be replicated easily

Subset selection is also discontinuous -i.e. small changes in the data can results in very different estimates

As a result subset selection is often unstable and highly variable, particularly when p is large

Page 6: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Problems with Subset Selection

What about collinearity?-difficult to ensure we’ve chosen the “best” subset of predictors

-Addition of a predictor to a model when a collinear predictor is already in the model often results in one or both predictors being non-significant due to the variance inflation

This results because our estimate of (X’X)-1 is nearly singular due to the near linearity of columns in X- i.e. X is not really full rank

Page 7: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Problems with Subset SelectionModels identified by subset selection are reported as if the model was specified apriori

This violates statistical principles for estimation and hypothesis testing:

-standard errors biased low -p-values falsely small -regression coefficients biased away from zero (as much as 1-2 standard errors off!- Miller, 2002)

This brings us to penalized regression -achieve same goals but more stable, continuous, and computationally efficient fashion

Page 8: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Penalized RegressionDeals with some of the regression problems by introducing a penalty and changing what we maximize

M( q ) is called the objective function and includes the additional terms-The penalty function p( q ): penalizes “less realistic” values of the b ’s-The regularization (shrinkage) parameter l: controls the tradeoff between bias and variance

Originally maximize log

Instead maximize

l L

M l p

x x

x

Page 9: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Penalized RegressionIn statistical testing we tend to believe that without tremendous evidence to the contrary, the null hypothesis is true

In regression this means that unless you give me a lot of evidence to suggest otherwise, I tend to think most of the model coefficients are closer to zero

Thus we are arguing that large coefficients are “less likely”

So in penalized regression we want to penalize coefficients the further they get from zero

Page 10: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Penalized RegressionWe can also think about this in terms of minimizing a loss function rather than maximizing our likelihood. In this case we rewrite our expression as

In the regression setting we can write M( q ) in terms of our regression parameters b as follows

The penalty function takes the form

'M p y X y X

M L p x

1

, for 0qr

jjp q

Page 11: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Constrained Regression

Alternatively, we can think about penalized regression as applying a constraint on the values of q

For example we may want to maximize our likelihood but subjected to the constraint that P( q ) < t

By the Lagrange multiplier method we arrive at the same regression function

2

0 1 1Minimize: 0

qn p p

i ij j ji i j jY X q

Page 12: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Bayesian Interpretation

From a Bayesian prospective, we can think of the penalty arising from a prior distribution on the parameters

The objective function M(q ) is proportional to the log of the posterior distribution of q given the data

By optimizing this objective function, we are finding the mode of the posterior distribution

Page 13: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

More on the Penalty Function

Let’s consider the impact of the penalty function

When q > 1, fq( b ) is continuous and convex

It is also convex when q = 1 but not continuous

When q < 1 it is not convex and minimization much more difficult

2

0 1 1Minimize: 0

qn p p

q i ij j ji i j jY X q

Page 14: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Regularization Parameter

Note the regularization parameter l controls the trade-off between the penalty and the fit

-If l is too small the tendency is to overfit the data and have a model with large variance

-If l is too large, the model may underfit the data yielding a model that is too simple

We will discuss how to select an appropriate l a little later

Page 15: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

The Intercept

In penalized regression we are assuming that the coefficient values near zero are more likely

However, there are some considerations in application

It does not make sense to apply this to the intercept as this would imply that the mean of y is 0

Thus the intercept isn’t included in the penalty

Page 16: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Other ConcernsAnother concern is that predictor variable can vary greatly in magnitude (and type)

What if the data contain one predictor that takes values between 0 and 1 and a another that takes values between 0 and 100000

In this case, certainly a one unit change is not equivalent in the two predictors q

To get around this issue, predictor variables are usually standardized prior to fitting the model to have mean 0 and standard deviation of 1

'

0j

j j

x

n j

x x

Page 17: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Other ConcernsThis can be done without loss of generality as

(1) location shifts are absorbed into the intercept(2) Scale shifts can be reversed after the model has been fit

If we had to divide xj by a to standardize, we simply divide our transformed coefficient by a to get on our original scale

ijij j j

ij j

xx a

a

x

j j

Page 18: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

CenteringThere are other benefits to centering and scaling our predictors

Predictors are now orthoganol to the intercept, thus in the standardized covariate space regardless of the rest of the model

This implies that if we center y by subtracting the mean, we don’t really have to estimate

0ˆ y

Page 19: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Ridge RegressionNow let’s focus on a specific penalized regression

Ridge regression penalizes the regression estimated by minimizing

In statistics this is also referred to as shrinkage since we are shrinking our coefficients towards 0

We therefore also call the regularization parameter l the shrinkage parameter

2' 2

01 1

n p

i i ji jy

x β

Page 20: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Ridge RegressionFortunately the ridge solution is easy to find because our loss function is still a quadratic function of b

2' 2

01 1

' '

' ' ' ' ' '

'

1' '

Loss function:

We can rewrite this as:

Solve 0 to get:

ˆ

n p

i i ji j

ridge

M y

M

M

x β

y Xβ y Xβ β β

β X X I β β X y y Xβ y y

β X X I X y

Page 21: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Consider an Example

What if X has perfect collinearity

X’X has eigenvalues 10, 6, and 0

'

1 1 24 2 2

1 0 12 6 4

1 2 12 4 6

1 1 0

X X X

Page 22: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Consider an Example

In the ridge fix we add lI so X’X has non-zero eigenvalues, for example:

'

'

5 2 2

1: 2 7 4 with eigenvalues 11, 7, and 1

2 4 7

6 2 2

2 : 2 2 8 4 with eigenvalues 12, 8, and 2

2 4 8

X X I

X X I

Page 23: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Consider an Example

Now suppose we had a response vector

Each choice of l results in specific estimates of the coefficients

'

'

'

'

1.3 0.5 2.6 0.9

1: 0.614 0.548 0.066

2 : 0.537 0.490 0.048

10 : 0.269 0.267 0.002

y

Page 24: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Ridge RegressionNote the solution is very similar to the OLS solution but there is a “ridge” down the diagonal of X’X

So how does l impact our solution?

This illustrates why we call l the shrinkage parameter

In the special case of an orthonormal design matrix we get

ˆ ˆ0

ˆridge OLS

ridge

β β

β 0

,,

ˆˆ

1OLS j

ridge j

Page 25: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Ridge RegressionRidge regression has the most benefit in instances where there is high collinearity.

In such a case, the OLS solution for b may not be unique as X may not really be full rank (i.e. X’X is not necessarily invertible)

However, in ridge regression, for any design matrix X, the matrix X’X +lI is always invertible!

Therefore there is always a unique solution for ˆridgeβ

Page 26: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Bias-Variance Trade OffIn introducing a penalty, when developing our likelihood estimate, we are also introducing bias

This is the tradeoff we have to accept for reduced variance

Note, the total variance is monotone decreasing with respect to l, while the total squared biasis monotone increasing wrt l.

2 '

1'

ˆVariance:

where

ˆ ˆBias:

ridge

ridge ridge

Var

Bias

β WX XW

W X X I

β Wβ

ridge jjVar

2

ridge jjBias

Page 27: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

vs.

Existence Theorem:There always exists a l such that the MSE of is less than the MSE of

This theorem has huge implications!

Even if our model is exactly correct and follows the specified distribution, we can always obtain an estimator with lower MSE by shrinking the parameters towards zero

ˆridge ˆ

OLS

ˆridge

ˆOLS

Page 28: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Choosing Shrinkage ParameterAIC is a one way of choosing models to balance fit and parsimony

To apply AIC (or BIC for that matter) to choosing l, we need estimate the degrees of freedom

In linear regression we have

ˆ , where is the projection ("hat") matrix

, are the degrees of freedomtr r

y Hy H

H

Page 29: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Choosing Shrinkage ParameterIn ridge regression, this relationship is similar but our H is:

What happens if l = 0? What if it is infinity?

1' '

'

1, where are the eigen values of

ridge

r jridge ridge jj

j

tr df

H X X X I X

H X X

Page 30: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Choosing Shrinkage Parameter

Now that we can quantify the degrees of freedom in our ridge regression model, we have a was to calculate AIC or BIC

We can use this information to choose l, using our estimated degrees of freedom

log 2*

log log *

AIC n SSE df

BIC n SSE n df

Page 31: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Choosing Shrinkage ParameterAlternatively we could base our choice of l on how well our ridge model predicts y

However, this would be using the data twice (a statistical no-no)

In an ideal world we have new data to externally validate our choice of l

But wait! We know how to do this in statistics… -We split the data into test and training sets and build the

model on the training data and test it on the test data-Even better we could….

Page 32: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

K-fold Cross-ValidationWe split the data into K equally size subsets and construct models on the data leaving out the kth subset (data X-k)

We can repeat this for all k subsets at each level of l we want to consider and average the results across the k models

.…

This procedure is referred to as K-fold cross-validation5 and 10 are the most common choices for K

1 2 3 4 K

Page 33: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Leave-One-Out CVWhen K = n we refer to this as leave-one-out cross-validation

Similar to leave-one-out residuals (jackknife) in which we look at the effect of leaving an observation out.

The main concern here would be poor computational efficiency of repeatedly calculating H

However the following approximation, called generalized cross-validation (GCV), may be used instead

2

1

ˆ1

1

n i itri

n

y yGCV

n

H

ˆ where is the diagonalof the hat matrix1

thii iii i

ii

ry y H i

H

Page 34: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Choosing Shrinkage ParameterIn general GCV is a popular method for choosing an appropriate shrinkage factor

GCV is also the only method readily provided in certain statistical software

In this case, though we can do ridge regression in R and SAS, only R provides GCV

Lets look at an example

Page 35: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Body Fat ExampleRecall our regression model

> summary(mod13)

Call:lm(formula = PBF ~ Age + Wt + Ht + Neck + Chest + Abd + Hip + Thigh + Knee + Ankle + Bicep + Arm + Wrist, data = bodyfat,

x = T)

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -18.18849 17.34857 -1.048 0.29551 Age 0.06208 0.03235 1.919 0.05618 . Wt -0.08844 0.05353 -1.652 0.09978 . Ht -0.06959 0.09601 -0.725 0.46925 Neck -0.47060 0.23247 -2.024 0.04405 * Chest -0.02386 0.09915 -0.241 0.81000 Abd 0.95477 0.08645 11.04 < 2e-16 ***Hip -0.20754 0.14591 -1.422 0.15622 Thigh 0.23610 0.14436 1.636 0.10326 Knee 0.01528 0.24198 0.063 0.94970 Ankle 0.17400 0.22147 0.786 0.43285 Bicep 0.18160 0.17113 1.061 0.28966 Arm 0.45202 0.19913 2.270 0.02410 * Wrist -1.62064 0.53495 -3.030 0.00272 **

Residual standard error: 4.305 on 238 degrees of freedom. Multiple R-squared: 0.749, Adjusted R-squared: 0.7353 . F-statistic: 54.65 on 13 and 238 DF, p-value: < 2.2e-16

Page 36: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data
Page 37: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Body Fat ExampleRecall our regression model

> summary(mod13)

Call:lm(formula = PBF ~ Age + Wt + Ht + Neck + Chest + Abd + Hip + Thigh + Knee + Ankle + Bicep + Arm + Wrist, data = bodyfat,

x = T)

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -18.18849 17.34857 -1.048 0.29551 Age 0.06208 0.03235 1.919 0.05618 . Wt -0.08844 0.05353 -1.652 0.09978 . Ht -0.06959 0.09601 -0.725 0.46925 Neck -0.47060 0.23247 -2.024 0.04405 * Chest -0.02386 0.09915 -0.241 0.81000 Abd 0.95477 0.08645 11.04 < 2e-16 ***Hip -0.20754 0.14591 -1.422 0.15622 Thigh 0.23610 0.14436 1.636 0.10326 Knee 0.01528 0.24198 0.063 0.94970 Ankle 0.17400 0.22147 0.786 0.43285 Bicep 0.18160 0.17113 1.061 0.28966 Arm 0.45202 0.19913 2.270 0.02410 * Wrist -1.62064 0.53495 -3.030 0.00272 **

Residual standard error: 4.305 on 238 degrees of freedom. Multiple R-squared: 0.749, Adjusted R-squared: 0.7353 . F-statistic: 54.65 on 13 and 238 DF, p-value: < 2.2e-16

Page 38: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Body Fat ExampleWhat if we consider ridge regression as an alternative? In R the code is:

>library(MASS)>bodyfat2<-scale(bodyfat)>bodyfat2<-as.data.frame(bodyfat2)> lam<-c(seq(0,9.99, by=.01),seq(10,99.9, by=.1),seq(101,10000, by=1))> ridgemod<-lm.ridge(PBF~., data=bodyfat2, lam=lam)> select(ridgemod)

modified HKB estimator is 1.677373modified L-W estimator is 3.902049smallest value of GCV at 1.18

Page 39: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Body Fat ExampleWe can plot l versus our estimated coefficientsThis is called a trace plotThere is no direct function in R, we must specify this ourselves-

for example

> par(mfrow=c(1,2))> plot(x=0, y=0, xlim=c(0,10000),ylim=c(-0.3, 1.2), type="n", ylab="Coefficients“, xlab="Lambda")> for (i in 1:nrow(ridgemod$coef)) lines(lam, ridgemod$coef[i,])> for (i in 1:nrow(ridgemod$coef)) lines(lam, ridgemod$coef[i,], col=i)> abline(h=0, lty=2)> abline(v=1.18, lty=3, col="red", lwd=2)

> plot(x=0, y=0, xlim=c(0,25),ylim=c(-0.3, 1.2), type="n", ylab="Coefficients“, xlab="Lambda")> for (i in 1:nrow(ridgemod$coef)) lines(lam, ridgemod$coef[i,])> for (i in 1:nrow(ridgemod$coef)) lines(lam, ridgemod$coef[i,], col=i)> abline(h=0, lty=2)> abline(v=1.18, lty=3, col="red", lwd=2)

Page 40: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Trace Plot

Page 41: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Effect of df(l)Alternatively we can look at the effect of the effective

degrees of freedom on lambda

Page 42: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Body Fat ExampleOLS> summary(mod)Call: lm(formula = PBF ~ ., data = bodyfat2)

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 5.452032 24.760561 0.220 0.82592 Age 0.065291 0.033604 1.943 0.05324 . Wt -0.002408 0.072163 -0.033 0.97341 Ht -0.239064 0.196291 -1.218 0.22451 Neck -0.388059 0.243861 -1.591 0.11291 Chest -0.132094 0.112572 -1.173 0.24184 Abd 0.901663 0.093813 9.611 < 2e-16 ***Hip -0.212855 0.158553 -1.342 0.18076 Thigh 0.202608 0.150403 1.347 0.17928 Knee -0.008189 0.253012 -0.032 0.97421 Ankle -0.008517 0.365308 -0.023 0.98142 Bicep 0.190207 0.187009 1.017 0.31017 Arm 0.191335 0.341657 0.560 0.57601 Wrist -1.605308 0.595433 -2.696 0.00754 **

Residual standard error: 4.28 on 230 degrees of freedomMultiple R-squared: 0.7444, Adjusted R-squared: 0.73 F-statistic: 51.54 on 13 and 230 DF, p-value: < 2.2e-16

Ridge Regression> ridgemod<-lm.ridge(PBF~., data=bodyfat, lam=1.18)> ridgemodInt -16.07 Age 0.070 Wt -0.074 Ht -0.084 Neck -0.469 Chest 0.005 Abd 0.901 Hip -0.188 Thigh 0.232 Knee -0.002 Ankle 0.151 Bicep 0.165 Arm 0.440 Wrist -1.659

Page 43: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

Body Fat ExampleWhat can we do in SAS?SAS doesn’t estimate GCV which is the preferred method for finding the “best” lHowever, it does generate trace plots and a plot of the VIF relative to the ridge coefficientsHere’s the basic SAS code

ods graphics on;proc reg data=bf plots(only)=ridge(unpack VIFaxis=log) outest=b ridge=0 to 10 by .01; model pbf=age wt ht neck chest abd hip thigh knee ankle bicep

arm wrist;run;ods graphics off;

Page 44: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

SAS Trace Plot

Page 45: Penalized Regression BMTRY 726 3/7/14. Maximum Likelihood Has been a statistics “staple” (and still is) ML approach -specify a distribution for our data

VIF versus Our Ridge Coefficients