This package provides functions for performing robust multi-model subset selection.
You can install the stable version on R CRAN.
{r installation, eval = FALSE} install.packages("RMSS", dependencies = TRUE)
You can install the development version from GitHub
library(devtools)
::install_github("AnthonyChristidis/RMSS") devtools
# Required libraries
install.packages("mvnfast")
# Simulation parameters
<- 50
n <- 500
p <- 0.8
rho <- 0.2
rho.inactive <- 25
group.size <- 100
p.active <- 1
snr <- 0.2
contamination.prop
# Setting the seed
set.seed(0)
# Block Correlation
<- matrix(0, p, p)
sigma.mat 1:p.active, 1:p.active] <- rho.inactive
sigma.mat[for(group in 0:(p.active/group.size - 1))
*group.size+1):(group*group.size+group.size),(group*group.size+1):(group*group.size+group.size)] <- rho
sigma.mat[(groupdiag(sigma.mat) <- 1
# Simulation of beta vector
<- c(runif(p.active, 0, 5)*(-1)^rbinom(p.active, 1, 0.7), rep(0, p - p.active))
true.beta
# Setting the SD of the variance
<- as.numeric(sqrt(t(true.beta) %*% sigma.mat %*% true.beta)/sqrt(snr))
sigma
# Simulation of test data
<- 2e3
m <- mvnfast::rmvn(m, mu = rep(0, p), sigma = sigma.mat)
x_test <- x_test %*% true.beta + rnorm(m, 0, sigma)
y_test
# Simulation of uncontaminated data
<- mvnfast::rmvn(n, mu = rep(0, p), sigma = sigma.mat)
x <- x %*% true.beta + rnorm(n, 0, sigma)
y
# Contamination of data
<- 1:floor(n*contamination.prop)
contamination_indices <- 2
k_lev <- 100
k_slo <- x
x_train <- y
y_train <- true.beta
beta_cont !=0] <- beta_cont[true.beta!=0]*(1 + k_slo)
beta_cont[true.beta==0] <- k_slo*max(abs(true.beta))
beta_cont[true.betafor(cont_id in contamination_indices){
<- runif(p, min = -1, max = 1)
a <- a - as.numeric((1/p)*t(a) %*% rep(1, p))
a <- mvnfast::rmvn(1, rep(0, p), 0.1^2*diag(p)) + k_lev * a / as.numeric(sqrt(t(a) %*% solve(sigma.mat) %*% a))
x_train[cont_id,] <- t(x_train[cont_id,]) %*% beta_cont
y_train[cont_id]
}
# CV RMSS
<- cv.RMSS(x = x_train, y = y_train,
cv.rmss_fit n_models = 10,
h_grid = c(35, 40), t_grid = c(8, 10, 12), u_grid = c(1:10),
tolerance = 1e-1,
max_iter = 1e3,
neighborhood_search = FALSE,
neighborhood_search_tolerance = 1e-1,
n_folds = 5,
alpha = 1/4,
gamma = 1,
n_threads = 1)
<- coef(cv.rmss_fit,
rmss_coefs h_ind = cv.rmss_fit$h_opt, t_ind = cv.rmss_fit$t_opt, u_ind = cv.rmss_fit$u_opt,
group_index = 1:cv.rmss_fit$n_models)
<- sum(which((rmss_coefs[-1]!=0)) <= p.active)/p.active
sens_rmss <- sum(which((rmss_coefs[-1]!=0)) <= p.active)/sum(rmss_coefs[-1]!=0)
spec_rmss <- predict(cv.rmss_fit, newx = x_test,
rmss_preds h_ind = cv.rmss_fit$h_opt, t_ind = cv.rmss_fit$t_opt, u_ind = cv.rmss_fit$u_opt,
group_index = 1:cv.rmss_fit$n_models,
dynamic = FALSE)
mean((y_test - rmss_preds)^2)/sigma^2
This package is free and open source software, licensed under GPL (>= 2).