An R package for generalised linear mixed model (GLMM) selection.
glmmsel
uses an \(\ell_0\)
regulariser to simultaneously select fixed and random effects. A
hierarchical constraint is included that a random effect cannot be
selected unless its corresponding fixed effect is also selected.
Gaussian and binomial families are currently supported.
To install the latest version from GitHub, run the following code:
::install_github('ryan-thompson/glmmsel') devtools
The glmmsel()
function fits a sparse GLMM over a
sequence of the regularisation parameter \(\lambda\), with different values yielding
different sparsity levels. The cv.glmmsel()
function
provides a convenient method for automatically cross-validating \(\lambda\).
library(glmmsel)
# Generate some clustered data
<- 100 # Number of observations
n <- 4 # Number of clusters
m <- 5 # Number of predictors
p <- 2 # Number of nonzero fixed effects
s.fix <- 1 # Number of nonzero random effects
s.rand <- matrix(rnorm(n * p), n, p) # Predictor matrix
x <- c(rep(1, s.fix), rep(0, p - s.fix)) # True fixed effects
beta <- cbind(matrix(rnorm(m * s.rand), m, s.rand), matrix(0, m, p - s.rand)) # True random effects
u <- sample(1:m, n, replace = TRUE) # Cluster labels
cluster <- rowSums(x * sweep(u, 2, beta, '+')[cluster, ]) # x %*% (beta + u) matrix
xb <- rnorm(n, xb) # Response vector
y
# Fit the ℓ0 regularisation path
<- glmmsel(x, y, cluster)
fit coef(fit, lambda = 10)
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 0.2011281 4.4667421 1.057887 0 0.1274537 0
## [2,] 0.2011281 2.2780872 1.057887 0 0.1274537 0
## [3,] 0.2011281 1.8789984 1.057887 0 0.1274537 0
## [4,] 0.2011281 -0.7071298 1.057887 0 0.1274537 0
# Cross-validate the ℓ0 regularisation path
<- cv.glmmsel(x, y, cluster)
fit coef(fit)
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 0.1940913 4.5180991 1.056909 0 0 0
## [2,] 0.1940913 2.3148964 1.056909 0 0 0
## [3,] 0.1940913 1.8666893 1.056909 0 0 0
## [4,] 0.1940913 -0.7452709 1.056909 0 0 0