Computes the linear regression coefficient estimates (ridge-penalization and weights, optional)
linearr(X, y, lam = seq(0, 2, 0.1), alpha = 1.5, penalty = c("none", "ridge", "bridge"), weights = NULL, intercept = TRUE, kernel = FALSE, method = c("SVD", "MM"), tol = 1e-05, maxit = 1e+05, vec = NULL, init = 1, K = 5)
X | matrix or data frame |
---|---|
y | matrix or data frame of response values |
lam | optional tuning parameter for ridge regularization term. If passing a list of values, the function will choose the optimal value based on K-fold cross validation. Defaults to 'lam = seq(0, 2, 0.1)' |
alpha | optional tuning parameter for bridge regularization term. If passing a list of values, the function will choose the optimal value based on K-fold cross validation. Defaults to 'alpha = 1.5' |
penalty | choose from c('none', 'ridge', 'bridge'). Defaults to 'none' |
weights | optional vector of weights for weighted least squares |
intercept | add column of ones if not already present. Defaults to TRUE |
kernel | use linear kernel to compute ridge regression coefficeients. Defaults to TRUE when p >> n (for 'SVD') |
method | optimization algorithm. Choose from 'SVD' or 'MM'. Defaults to 'SVD' |
tol | tolerance - used to determine algorithm convergence for 'MM'. Defaults to 10^-5 |
maxit | maximum iterations for 'MM'. Defaults to 10^5 |
vec | optional vector to specify which coefficients will be penalized |
init | optional initialization for MM algorithm |
K | specify number of folds for cross validation, if necessary |
returns the selected tuning parameters, coefficient estimates, MSE, and gradients
library(dplyr)#> #>#>#> #>#>#> #>X = dplyr::select(iris, -c(Species, Sepal.Length)) y = dplyr::select(iris, Sepal.Length) linearr(X, y, lam = 0.1, penalty = 'ridge')#> #> Call: linearr(X = X, y = y, lam = 0.1, penalty = "ridge") #> #> Tuning parameters: #> lam alpha #> [1,] 0.1 NaN #> #> MSE: #> [1] 0.09631325 #> #> Coefficients: #> [,1] #> intercept 1.87785 #> 0.64624 #> 0.70231 #> -0.54160