vennLasso v0.1

0

Monthly downloads

0th

Percentile

by Jared Huling

Variable Selection for Heterogeneous Populations

Provides variable selection and estimation routines for models stratified based on binary factors.

Readme

Build Status

vennLasso

Hierarchical variable selection for models stratified on binary factors

Installation and Help Files

Install using the devtools package:

devtools::install_github("jaredhuling/vennLasso")

or by cloning and building.

Load the vennLasso package:

library(vennLasso)

Access help file for the main fitting function vennLasso() by running:

?vennLasso

Help file for cross validation function cv.vennLasso() can be accessed by running:

?cv.vennLasso

A Quick Example

Simulate heterogeneous data:

set.seed(100)
dat.sim <- genHierSparseData(ncats = 3,  # number of stratifying factors
                             nvars = 25, # number of variables
                             nobs = 150, # number of observations per strata
                             nobs.test = 10000,
                             hier.sparsity.param = 0.5,
                             prop.zero.vars = 0.75, # proportion of variables
                                                   # zero for all strata
                             snr = 0.5,  # signal-to-noise ratio
                             family = "gaussian")

# design matrices
x        <- dat.sim$x
x.test   <- dat.sim$x.test

# response vectors
y        <- dat.sim$y
y.test   <- dat.sim$y.test

# binary stratifying factors
grp      <- dat.sim$group.ind
grp.test <- dat.sim$group.ind.test

Inspect the populations for each strata:

plotVenn(grp)

Fit vennLasso model with tuning parameter selected with 5-fold cross validation:

fit.adapt <- cv.vennLasso(x, y,
                          grp,
                          adaptive.lasso = TRUE,
                          nlambda        = 50,
                          family         = "gaussian",
                          standardize    = FALSE,
                          intercept      = TRUE,
                          nfolds         = 5)

Plot selected variables for each strata (not run):

library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
plotSelections(fit.adapt)

Predict response for test data:

preds.vl <- predict(fit.adapt, x.test, grp.test, s = "lambda.min",
                    type = 'response')

Evaluate mean squared error:

mean((y.test - preds.vl) ^ 2)
## [1] 0.6852124
mean((y.test - mean(y.test)) ^ 2)
## [1] 1.011026

Compare with naive model with all interactions between covariates and stratifying binary factors:

df.x <- data.frame(y = y, x = x, grp = grp)
df.x.test <- data.frame(x = x.test, grp = grp.test)

# create formula for interactions between factors and covariates
form <- paste("y ~ (", paste(paste0("x.", 1:ncol(x)), collapse = "+"), ")*(grp.1*grp.2*grp.3)" )

Fit linear model and generate predictions for test set:

lmf <- lm(as.formula(form), data = df.x)

preds.lm <- predict(lmf, df.x.test)

Evaluate mean squared error:

mean((y.test - preds.lm) ^ 2)
## [1] 0.8056107
mean((y.test - preds.vl) ^ 2)
## [1] 0.6852124

Functions in vennLasso

Name Description
genHierSparseBeta function to generate coefficient matrix with hierarchical sparsity
genHierSparseData function to generate data with hierarchical sparsity
plot.cv.vennLasso Plot method for cv.vennLasso fitted objects
plotSelections plotting function to investigate hierarchical structure of selection
plotVenn plotting function for venn diagrams of overlapping conditions
predict.vennLasso Prediction for Hierarchical Shared Lasso
logLik.vennLasso log likelihood function for fitted vennLasso objects
oglasso Overlapping Group Lasso (OGLasso)
cv.vennLasso Cross Validation for the vennLasso
estimate.hier.sparsity.param function to estimate the hierarchical sparsity parameter for a desired level of sparsity for simulated hierarchical coefficients
predict.cv.vennLasso Prediction for Cross Validation Hierarchical Lasso Object
vennLasso Fitting vennLasso models
No Results!

Last month downloads

Details

Type Package
Date 2017-07-05
URL https://github.com/jaredhuling/vennLasso
BugReports https://github.com/jaredhuling/vennLasso/issues
License GPL (>= 2)
LazyData TRUE
LinkingTo Rcpp, RcppEigen, RcppNumerical
RoxygenNote 6.0.1
VignetteBuilder knitr
NeedsCompilation yes
Packaged 2017-07-15 15:16:28 UTC; Jared
Repository CRAN
Date/Publication 2017-07-15 21:06:36 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/vennLasso)](http://www.rdocumentation.org/packages/vennLasso)