A function to select the relevant predictors by partitioning the solution paths (the SPSP algorithm)
based on the user provided solution paths BETA.
Usage
SPSP_step(
x,
y,
family = c("gaussian", "binomial"),
BETA,
standardize = TRUE,
intercept = TRUE,
init = 1,
R = NULL,
...
)Arguments
- x
independent variables as a matrix, of dimension nobs x nvars; each row is an observation vector.
- y
response variable. Quantitative for
family="gaussian"orfamily="poisson"(non-negative counts). Forfamily="binomial"should be either a factor with two levels.- family
either a character string representing one of the built-in families, or else a glm() family object.
- BETA
the solution paths obtained from a prespecified fitting step
fitfun.SP = lasso.glmnetetc. It must be a p by k matrix, should be thicker and thicker, each column corresponds to a lambda, and lambda gets smaller and smaller. It is the returned coefficient matrixbetafrom aglmnetobject, or ancvregobject.- standardize
whether need standardization.
- intercept
logical. If x is a data.frame, this argument determines if the resulting model matrix should contain a separate intercept or not.
- init
initial coefficients, starting from init-th estimator of the solution paths. The default is 1.
- R
sorted adjacent distances, default is NULL. Will be calculated inside.
- ...
Additional optional arguments.
Value
A list containing at least the following components:
beta_SPSPthe estimated coefficients of SPSP selected model;
S0the estimated relevant sets;
nonzerothe selected covariates;
zerothe covariates that are not selected;
thresthe boundaries for abs(beta);
Rthe sorted adjacent distances;
interceptthe estimated intercept when
intercept == T.
This object has attribute contains:
mod.fitthe fitted penalized regression within the input function
fitfun.SP;familythe family of fitted object;
fitfun.SPthe function to obtain the solution paths for the SPSP algorithm;
args.fitfun.SPa named list containing additional arguments for the function
fitfun.SP.
Examples
data(HighDim)
library(glmnet)
x <- as.matrix(HighDim[,-1])
y <- HighDim[,1]
lasso_fit <- glmnet(x = x, y = y, alpha = 1, intercept = FALSE)
# SPSP+Lasso method
K <- dim(lasso_fit$beta)[2]
LBETA <- as.matrix(lasso_fit$beta)
spsp_lasso_1 <- SPSP_step(x = x, y = y, BETA = LBETA,
init = 1, standardize = FALSE, intercept = FALSE)
head(spsp_lasso_1$nonzero)
#> [1] "X1" "X2" "X3"
head(spsp_lasso_1$beta_SPSP)
#> X1 X2 X3 X4 X5 X6
#> 3.034047 2.042406 1.473175 0.000000 0.000000 0.000000