Last active
September 24, 2018 12:29
-
-
Save vankesteren/fefc683ad0107eb658b2c18c858bd916 to your computer and use it in GitHub Desktop.
svd hidim regression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Try-out of Hastie, Tibshirani, & Friedman (ESL, 2009) p.659 | |
# Generate high-dimensional dataset | |
beta <- -100:100/100 | |
X <- matrix(rnorm(100*201), 100) | |
y <- X%*%beta + rnorm(100, 0, sqrt(crossprod(beta))) | |
# Ridge estimates | |
bhat_ridge <- solve(crossprod(X) + diag(rep(.1, 201)), crossprod(X, y)) | |
# SVD estimates | |
s <- svd(X) | |
R <- s$u%*%diag(s$d) | |
V <- s$v | |
bhat_svd <- V%*%solve(crossprod(R), crossprod(R, y)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
magic.