c060

Extended Inference for Lasso and Elastic-Net Regularized Cox and Generalized Linear Models

Maintainer F. Bertrand

https://doi.org/10.32614/CRAN.package.c060

DOI Lifecycle: stable Project Status: Active – The project has reached a stable, usable state and is being actively developed. R-CMD-check Codecov test coverage CRAN status CRAN RStudio mirror downloads GitHub Repo stars R-CMD-check

The goal of the c060 package is to provide additional functions to perform stability selection, model validation and parameter tuning for glmnet models.

Installation

You can install the released version of c060 from CRAN with:

install.packages("c060")

And the development version from GitHub with:

install.packages("devtools")
devtools::install_github("fbertran/c060")

Examples

Gaussian Stability Selection

set.seed(1234)
x=matrix(rnorm(100*1000,0,1),100,1000)
y <- x[1:100,1:1000] %*% c(rep(2,5),rep(-2,5),rep(.1,990))
res <- stabpath(y,x,weakness=1,mc.cores=2)
#> Error in `stabpath()`:
#> ! could not find function "stabpath"
stabsel(res,error=0.05,type="pfer")
#> Error in `stabsel()`:
#> ! could not find function "stabsel"

Gaussian Stability Paths

set.seed(1234)
x <- matrix(rnorm(100*1000,0,1),100,1000)
y <- x[1:100,1:1000] %*% c(rep(2,5),rep(-2,5),rep(.1,990))
res <- stabpath(y,x,weakness=1,mc.cores=2)
#> Error in `stabpath()`:
#> ! could not find function "stabpath"
plot(res)
#> Error:
#> ! object 'res' not found

Binomial Stability Paths

y=sample(1:2,100,replace=TRUE)
res <- stabpath(y,x,weakness=1,mc.cores=2,family="binomial")
#> Error in `stabpath()`:
#> ! could not find function "stabpath"
plot(res)
#> Error:
#> ! object 'res' not found

Multinomial Stability Paths

y=sample(1:4,100,replace=TRUE)
res <- stabpath(y,x,weakness=1,mc.cores=2,family="multinomial")
#> Error in `stabpath()`:
#> ! could not find function "stabpath"
plot(res)
#> Error:
#> ! object 'res' not found

Poisson Stability Paths

N=100; p=1000
nzc=5
x=matrix(rnorm(N*p),N,p)
beta=rnorm(nzc)
f = x[,seq(nzc)] %*% beta
mu=exp(f)
y=rpois(N,mu)
res <- stabpath(y,x,weakness=1,mc.cores=2,family="poisson")
#> Error in `stabpath()`:
#> ! could not find function "stabpath"
plot(res)
#> Error:
#> ! object 'res' not found

Cox Stability Paths

library(survival)
set.seed(10101)
N=100;p=1000
nzc=p/3
x=matrix(rnorm(N*p),N,p)
beta=rnorm(nzc)
fx=x[,seq(nzc)] %*% beta/3
hx=exp(fx)
ty=rexp(N,hx)
tcens=rbinom(n=N,prob=.3,size=1)
y=cbind(time=ty,status=1-tcens)
res <- stabpath(y,x,weakness=1,mc.cores=2,family="cox")
#> Error in `stabpath()`:
#> ! could not find function "stabpath"
plot(res)
#> Error:
#> ! object 'res' not found

Example from glmnet package

set.seed(10101)
library(glmnet)
library(survival)
library(peperr)
N=1000;p=30
nzc=p/3
x=matrix(rnorm(N*p),N,p)
beta=rnorm(nzc)
fx=x[,seq(nzc)] %*% beta/3
hx=exp(fx)
ty=rexp(N,hx)
tcens=rbinom(n=N,prob=.3,size=1)# censoring indicator
y=Surv(ty,1-tcens)

EPSGO

set.seed(1010)
n=1000;p=100
nzc=trunc(p/10)
x=matrix(rnorm(n*p),n,p)
beta=rnorm(nzc)
fx= x[,seq(nzc)] %*% beta
eps=rnorm(n)*5
y=drop(fx+eps)
px=exp(fx)
px=px/(1+px)
ly=rbinom(n=length(px),prob=px,size=1)
set.seed(1011)

y - binomial

y.classes<-ifelse(y>= median(y),1, 0)
set.seed(1234)
nfolds = 10
foldid <- balancedFolds(class.column.factor=y.classes, cross.outer=nfolds)
#> Error in `balancedFolds()`:
#> ! could not find function "balancedFolds"
bounds <- t(data.frame(alpha=c(0, 1)))
colnames(bounds)<-c("lower","upper")
 
fit <- EPSGO(Q.func="tune.glmnet.interval", 
             bounds=bounds, 
             parms.coding="none", 
             seed = 1234, 
             show="final",
             fminlower = -100,
             x = x, y = y.classes, family = "binomial", 
             foldid = foldid,
             my.mfrow = c(4, 4),
             type.min = "lambda.1se",
             type.measure = "mse",
             verbose = FALSE)
#> Error in `EPSGO()`:
#> ! could not find function "EPSGO"
summary(fit)
#> Error in `h()`:
#> ! error in evaluating the argument 'object' in selecting a method for function 'summary': object 'fit' not found

y - multinomial: low - low 25%, middle - (25,75)-quantiles, high - larger 75%.

y.classes<-ifelse(y <= quantile(y,0.25),1, ifelse(y >= quantile(y,0.75),3, 2))
set.seed(1234)
nfolds = 10
foldid <- balancedFolds(class.column.factor=y.classes, cross.outer=nfolds)
#> Error in `balancedFolds()`:
#> ! could not find function "balancedFolds"
bounds <- t(data.frame(alpha=c(0, 1)))
colnames(bounds)<-c("lower","upper")
 
fit <- EPSGO(Q.func="tune.glmnet.interval", 
             bounds=bounds, 
             parms.coding="none", 
             seed = 1234, 
             show="none",
             fminlower = -100,
             x = x, y = y.classes, family = "multinomial", 
             foldid = foldid,
             type.min = "lambda.1se",
             type.measure = "mse",
             verbose = FALSE)
#> Error in `EPSGO()`:
#> ! could not find function "EPSGO"
summary(fit)
#> Error in `h()`:
#> ! error in evaluating the argument 'object' in selecting a method for function 'summary': object 'fit' not found

Gaussian

set.seed(1234)
x=matrix(rnorm(100*1000,0,1),100,1000)
y <- x[1:100,1:1000]%*%c(rep(2,5),rep(-2,5),rep(.1,990))

foldid <- rep(1:10,each=10)

fit <- EPSGO(Q.func="tune.glmnet.interval", 
             bounds=bounds, 
             parms.coding="none", 
             seed = 1234, 
             show="none",
             fminlower = -100,
             x = x, y = y, family = "gaussian", 
             foldid = foldid,
             type.min = "lambda.1se",
             type.measure = "mse",
             verbose = FALSE)
#> Error in `EPSGO()`:
#> ! could not find function "EPSGO"
summary(fit) 
#> Error in `h()`:
#> ! error in evaluating the argument 'object' in selecting a method for function 'summary': object 'fit' not found