This package provides functions for performing stepwise split regularized regression.
You can install the stable version on R CRAN.
install.packages("stepSplitReg", dependencies = TRUE)
You can install the development version from GitHub
library(devtools)
::install_github("AnthonyChristidis/stepSplitReg") devtools
# Required Libraries
library(mvnfast)
# Setting the parameters
<- 800
p <- 40
n <- 2000
n.test <- 0.2
sparsity <- 0.5
rho <- 3
SNR set.seed(0)
# Generating the coefficient
<- floor(p*sparsity)
p.active <- 4*log(n)/sqrt(n)
a <- 0.2
neg.prob <- (-1)^(rbinom(p.active, 1, neg.prob))*(a + abs(rnorm(p.active)))
nonzero.betas
# Correlation structure
<- matrix(0, p, p)
Sigma 1:p.active, 1:p.active] <- rho
Sigma[diag(Sigma) <- 1
<- c(nonzero.betas, rep(0 , p - p.active))
true.beta
# Computing the noise parameter for target SNR
<- as.numeric(sqrt((t(true.beta) %*% Sigma %*% true.beta)/SNR))
sigma.epsilon
# Simulate some data
set.seed(1)
<- mvnfast::rmvn(n, mu=rep(0,p), sigma=Sigma)
x.train <- 1 + x.train %*% true.beta + rnorm(n=n, mean=0, sd=sigma.epsilon)
y.train <- mvnfast::rmvn(n.test, mu=rep(0,p), sigma=Sigma)
x.test <- 1 + x.test %*% true.beta + rnorm(n.test, sd=sigma.epsilon)
y.test
# Stepwise Split Regularized Regression
<- cv.stepSplitReg(x.train, y.train, n_models = c(5, 10), max_variables = NULL, keep = 4/4,
step.out model_criterion = c("F-test", "RSS")[1],
stop_criterion = c("F-test", "pR2", "aR2", "R2", "Fixed")[1], stop_parameter = 0.05,
shrinkage = TRUE, alpha = 4/4, include_intercept = TRUE,
n_lambda = 50, tolerance = 1e-2, max_iter = 1e5, n_folds = 5,
model_weights = c("Equal", "Proportional", "Stacking")[1],
n_threads = 1)
<- coef(step.out, group_index = 1:20)
step.coefficients <- predict(step.out, x.test, group_index = 1:20)
step.predictions <- mean((step.predictions-y.test)^2)/sigma.epsilon^2 mspe.step
This package is free and open source software, licensed under GPL (>= 2).