Skip to content

Instantly share code, notes, and snippets.

@vankesteren
Last active September 24, 2018 12:29
Show Gist options
  • Save vankesteren/fefc683ad0107eb658b2c18c858bd916 to your computer and use it in GitHub Desktop.
Save vankesteren/fefc683ad0107eb658b2c18c858bd916 to your computer and use it in GitHub Desktop.
svd hidim regression
# 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))
@vankesteren
Copy link
Author

bhat_ridge ≈ bhat_svd

@vankesteren
Copy link
Author

magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment