Why not just use every variable? Why not just use least squares?
\(~\)
Three classes of methods:
Instead of finding and fitting a subset of parameters, we can constrain or regularize the coefficient estimates.
We fit models that minimize a function. In OLS we try to minimize RSS.
Question 1
What happens when \(\lambda=0\)? When \(\lambda\rightarrow\infty\)? When \(\lambda=\infty\)?
Question 2
In Least Squares, given \(Y=\beta_0+\beta_1 X\) how does \(\beta_1\) change if X is multiplied by a constant, c?
\(~\) \(~\) \(~\) \(~\)
PLEASE DON’T SCROLL DOWN TILL WE TALK ABOUT QUESTION 2
\(~\) \(~\) \(~\) \(~\)
OLS is scale equivariant (\(X_j\beta_j\) will always be the same). However, Ridge Regression is not. Therefore we should always standardized the predictors The book divides by the standard deviation of the predictor: \(x=\frac{x}{\sigma(x)}\). I prefer to subtract the mean as well which gives more interpretable \(\beta_0\) values. \(x=\frac{x-\bar{x}}{\sigma(x)}\)
Cross validation: select lowest error. Next week
Not today
\(~\)
Question 3 Generate 6 random variables of length 10. (Y and 5 X variables). Use a seed of 0 for replicability. Using only the first 5 values. Fit 6 models in order Y given nothing, Y given X1, Y given X1 and X2,… Y given everything else. Use the remaining 5 values as the test set.
\(~\)
Notes in high dimensions:
\(~\)\(~\)\(~\)\(~\)\(~\)\(~\)
This will be a short lab (number of questions), but a potentially long lab (depth of questions). For all questions use the below dataset
library(glmnet)
## Warning: package 'glmnet' was built under R version 4.4.2
## Loading required package: Matrix
## Loaded glmnet 4.1-8
library(leaps)
set.seed(0)
V1<-rnorm(100,0,1)
df=data.frame(V1)
for(i in 1:20){
df[,i]=rnorm(100,sample(-5:5,1),runif(1,min=0,max=4))
}
df$V21=df$V20/2
df$V22=df$V2-2
df$Y=5+df$V1-2*df$V2+3.5*df$V10-20*df$V21+10*df$V7+rnorm(100,0,1)
grid=c(0,1,10,100)
Question 4 This is the only question to turn in if you were in class today.
In this lab we reviewed the following: