Skip to content

Commit

Permalink
vignettte update
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhuling committed Mar 25, 2018
1 parent da60540 commit db0415a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
Binary file modified docs/articles/using_the_vennLasso_package.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion vennLasso.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --compact-vignettes=both
PackageCheckArgs: --compact-vignettes=both
PackageRoxygenize: rd,collate,namespace
PackageRoxygenize: rd,collate,namespace,vignette
3 changes: 2 additions & 1 deletion vignettes/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ @preamble{
@unpublished{huling18,
author = "Huling, Jared and Yu, Menggang and Liang, Muxuan and Smith, Maureen",
title = "Risk Prediction for Heterogeneous Populations with Application to Hospital Admission Prediction",
Note = {To appear in \textit{Biometrics}},
note = {To appear in \textit{Biometrics}},
journal = {Biometrics},
year = {2018},
doi = {10.1111/biom.12769},
url = {http://dx.doi.org/10.1111/biom.12769}
Expand Down
69 changes: 69 additions & 0 deletions vignettes/using_the_vennLasso_package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
## ---- eval = FALSE-------------------------------------------------------
# install.packages("devtools")
# devtools::install_github("jaredhuling/vennLasso")

## ---- warning=FALSE, message=FALSE---------------------------------------
library(vennLasso)

## ----simdata-------------------------------------------------------------
set.seed(123)
dat.sim <- genHierSparseData(ncats = 3, # number of binary stratifying factors
nvars = 50, # number of variables
nobs = 150, # number of observations per subpopulation
nobs.test = 5000,
hier.sparsity.param = 0.6, # the following two parameters
prop.zero.vars = 0.5, # determine how many variables
family = "gaussian") # have no impact on response

# design matrices
x <- dat.sim$x # one for training
x.test <- dat.sim$x.test # one for testing

# 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

## ----fitmodel------------------------------------------------------------
fit1 <- vennLasso(x = x, y = y, groups = grp, adaptive.lasso = TRUE)

## ----lookatcoefs---------------------------------------------------------
round(fit1$beta[,1:10,35], 3)

## ----truecoefs-----------------------------------------------------------
round(dat.sim$beta.mat[,1:9], 3)

## ----plotpaths, fig.height = 8, fig.cap = "Coefficient paths for each subpopulation. The subpopulation denoted by '0,1,1' is the subpopulation of samples who have the second and third binary factor but not the first, the '0,1,0' subpopulation is the subpopulation of those who have only the second binary factor, and so on."----
layout(matrix(1:9, ncol = 3))
for (i in 1:nrow(fit1$beta)) plot(fit1, which.subpop = i, xvar = "loglambda")

## ----cvvennlasso---------------------------------------------------------
cvfit1 <- cv.vennLasso(x = x, y = y, groups = grp, adaptive.lasso = TRUE, nfolds = 5)

## ----minlam--------------------------------------------------------------
cvfit1$lambda.min

## ----plotcv--------------------------------------------------------------
plot(cvfit1)

## ----predict_cv----------------------------------------------------------
preds <- predict(cvfit1,
newx = x.test,
group.mat = grp.test,
s = "lambda.min")
mean((y.test - preds) ^ 2)
mean((y.test - mean(y.test)) ^ 2)

## ----fitmodel_confint----------------------------------------------------
fit2 <- vennLasso(x = x, y = y, groups = grp,
adaptive.lasso = TRUE,
gamma = 1,
conf.int = 0.90) # specify the confidence level (90% here) for CIs

## ----lookatcis-----------------------------------------------------------
round(fit2$lower.ci[,7:11,35], 3)
round(fit2$upper.ci[,7:11,35], 3)

Binary file added vignettes/using_the_vennLasso_package.pdf
Binary file not shown.

0 comments on commit db0415a

Please sign in to comment.