R/OLS_SVD.R

Defines functions OLS_SVD

Documented in OLS_SVD

#' Solve OLS problem using SVD decomposition
#'
#' @param X A n by d matrix
#' @param y A n by 1 column vector
#'
#' @export
OLS_SVD <- function(X,y) {
  SVD <- svd(X)
  U <- SVD$u
  S <- diag(1/SVD$d)
  V <- SVD$v
  beta <- V%*%S%*%t(U)%*%y
  return(beta)
}
jcorrett/stats230.Rpackage documentation built on March 21, 2022, 5:36 a.m.