Learn R Programming

glmmPen

glmmPen package

Generalized linear mixed models (GLMMs) are popular for their flexibility and their ability to estimate population-level effects while accounting for between-group heterogeneity. While GLMMs are very versatile, the specification of fixed and random effects is a critical part of the modeling process. The package glmmPen simultaneously selects fixed and random effects from high dimensional penalized generalized linear mixed models (pGLMMs) using the funcion glmmPen. This function glmmPen fits a sequence of pGLMMs and chooses the best model using one of several Bayesian Information Criterion (BIC)-derived selection criteria. The package can also fit single GLMM models (with or without penalization) using the function glmm. Model parameters are estimated using a Monte Carlo Expectation Conditional Maximization (MCECM) algorithm, which leverages Stan and RcppArmadillo to increase computational efficiency.

Our package supports the penalty functions MCP, SCAD, and LASSO, and the distributional families Binomial, Gaussian, and Poisson (with canonical links). The available BIC-derived selection criteria include the BIC-ICQ, the regular BIC, and the hybrid BICh (see documentation for further details). The user interface of the package was designed to be similar to the popular lme4 R package, including the specification of the model equation with fixed and random effects.Tools available in the package include automated tuning parameter selection and automated initialization of the random effect variance.

Windows users must perform an additional step to create/edit a "~/.R/Makevars.win" document, which is required due to the dependence on the rstan package. These adjustments are required for the package to properly install. The appropriate adjustment depends on what version of R is being used (a version earlier than 4.0 or the version 4.0 or later).

For Windows users using a version of R earlier than 4.0, first run the following lines of code:

# Create "~/.R/Makevars.win" file if it does not currently exist
dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars.win")
if (!file.exists(M)) file.create(M)
# Run code below to add the appropriate lines to the Makevars.win file:
cat("\nCXX14FLAGS=-O3 -march=corei7 -mtune=corei7",
    "CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y",
    "CXX11FLAGS=-O3 -march=corei7 -mtune=corei7",
    file = M, sep = "\n", append = TRUE)

For Windows users using a version of R 4.0 or later (and the corresponding Rtools40), first run the following lines of code: (instructions and further comments also given by the Stan team here: <https://discourse.mc-stan.org/t/dealing-with-r-4-0/14586>)

# If file "~/.R/Makevars.win" already exists, rename or delete and 
#   create a new Makevars.win file (uncomment and run following line).
# file.rename(from = "~/.R/Makevars.win", to = "~/.R/Makevars_old")

# If file "~/.R/Makevars.win" does not exist, first run the first four 
#   lines in the previous code chunck to create such a file.
#   Then run the code below to add the appropriate line
#   to the Makevars.win file:
cat("CXX14FLAGS += -mtune=native -march=native -Wno-ignored-attributes -Wno-deprecated-declarations \n", file = "~/.R/Makevars.win")

The package can then be installed using the following lines of code:

#install.packages("devtools")
devtools::install_github("hheiling/glmmPen")

The manual is available in the 'inst/' folder of the package and gives more specifics about the required and optional arguments for the main functions glmmPen and glmm.

The output object, of class pglmmObj, includes the following S3 methods of interest: fixef, ranef, sigma, fitted, predict, print, and summary, which act similar to the same S3 methods for the output object of lme4 functions.

There is also a plot_mcmc function that can perform some diagnostic plots on the posterior draw outputs.

Contact information: email hheiling@live.unc.edu

Copy Link

Version

Install

install.packages('glmmPen')

Monthly Downloads

319

Version

1.5.4.8

License

GPL (>= 2)

Maintainer

Hillary Heiling

Last Published

August 29th, 2024

Functions in glmmPen (1.5.4.8)

lambdaControl

Control of Penalization Parameters and Selection Criteria
LambdaSeq

Calculation of Penalty Parameter Sequence (Lambda Sequence)
optimControl

Control of Penalized Generalized Linear Mixed Model Fitting
pglmmObj-class

Class pglmmObj of Fitted Penalized Generalized Mixed-Effects Models for package glmmPen
adaptControl

Control of Metropolis-within-Gibbs Adaptive Random Walk Sampling Procedure Controls the adaptive random walk Metropolis-within-Gibbs sampling procedure.
basal

Basal dataset: A composition of cancer datasets with top scoring pairs (TSPs) as covariates and binary response indicating if the subject's cancer subtype was basal-like. A dataset composed of four datasets combined from studies that contain gene expression data from subjects with several types of cancer. Two of these datasets contain gene expression data for subjects with Pancreatic Ductal Adenocarcinoma (PDAC), one dataset contains data for subjects with Breast Cancer, and the fourth dataset contains data for subjects with Bladder Cancer. The response of interest is whether or not the subject's cancer subtype was the basal-like subtype. See articles Rashid et al. (2020) "Modeling Between-Study Heterogeneity for Improved Replicability in Gene Signature Selection and Clinical Prediction" and Moffitt et al. (2015) "Virtual microdissection identifies distinct tumor- and stroma-specific subtypes of pancreatic ductal adenocarcinoma" for further details on these four datasets.
phmmPen_FA

Fit a Penalized Proportional Hazards Mixed Model via Monte Carlo Expectation Conditional Minimization (MCECM) using a Piecewise Constant Hazard Mixed Model Approximation
glmm

Fit a Generalized Mixed Model via Monte Carlo Expectation Conditional Minimization (MCECM)
phmmPen

Fit Penalized Proportional Hazards Mixed Models via Monte Carlo Expectation Conditional Minimization (MCECM) using a Piecewise Constant Hazard Mixed Model Approximation
phmm_FA

Fit a Proportional Hazards Mixed Model via Monte Carlo Expectation Conditional Minimization (MCECM) using a Piecewise Constant Hazard Mixed Model Approximation
phmm

Fit a Proportional Hazards Mixed Model via Monte Carlo Expectation Conditional Minimization (MCECM) using a Piecewise Constant Hazard Mixed Model Approximation
sim.data

Simulates data to use for the glmmPen package
survival_data

Convert Input Survival Data Into Long-Form Data Needed for Fitting a Piecewise Exponential Model
survivalControl

Control for Fitting Piecewise Constant Hazard Mixed Models as an Approximation to Fitting Cox Proportional Hazards Mixed Models
plot_mcmc

Plot Diagnostics for MCMC Posterior Draws of the Random Effects
rControl

Control of Latent Factor Model Number Estimation Constructs the control structure for the estimation of the number of latent factors (r) for use within the glmmPen_FA and glmm_FA estimation procedures.
glmm_FA

Fit a Generalized Mixed Model via Monte Carlo Expectation Conditional Minimization (MCECM)
glmmPen

Fit Penalized Generalized Mixed Models via Monte Carlo Expectation Conditional Minimization (MCECM)
glmmPen_FA

Fit Penalized Generalized Mixed Models via Monte Carlo Expectation Conditional Minimization (MCECM)