Learn R Programming

flexmix (version 2.3-19)

FLXMRglmnet: FlexMix Interface for Adaptive Lasso / Elastic Net with GLMs

Description

This is a driver which allows fitting of mixtures of GLMs where the coefficients are penalized using the (adaptive) lasso or the elastic net by reusing functionality from package glmnet.

Usage

FLXMRglmnet(formula = . ~ ., family = c("gaussian", "binomial", "poisson"),
              adaptive = TRUE, select = TRUE, offset = NULL, ...)

Value

Returns an object of class FLXMRglm.

Arguments

formula

A formula which is interpreted relative to the formula specified in the call to flexmix using update.formula. Default is to use the original flexmix model formula.

family

A character string naming a glm family function.

adaptive

A logical indicating if the adaptive lasso should be used. By default equal to TRUE.

select

A logical vector indicating which variables in the model matrix should be included in the penalized part. By default equal to TRUE implying that all variables are penalized.

offset

This can be used to specify an a priori known component to be included in the linear predictor during fitting.

...

Additional arguments to be passed to cv.glmnet fitter.

Author

Frederic Mortier and Nicolas Picard.

Details

Some care is needed to ensure convergence of the algorithm, which is computationally more challenging than a standard EM. In the proposed method, not only are cluster allocations identified and component parameters estimated as commonly done in mixture models, but there is also variable selection via penalized regression using $k$-fold cross-validation to choose the penalty parameter. For the algorithm to converge, it is necessary that the same cross-validation partitioning be used across the EM iterations, i.e., the subsamples for cross-validation must be defined at the beginning This is accomplished using the foldid option as an additional parameter to be passed to cv.glmnet (see glmnet package documentation).

References

Frederic Mortier, Dakis-Yaoba Ouedraogo, Florian Claeys, Mahlet G. Tadesse, Guillaume Cornu, Fidele Baya, Fabrice Benedet, Vincent Freycon, Sylvie Gourlet-Fleury and Nicolas Picard. Mixture of inhomogeneous matrix models for species-rich ecosystems. Environmetrics, 26(1), 39-51, 2015. doi:10.1002/env.2320

See Also

FLXMRglm

Examples

Run this code
    set.seed(12)
    p <- 10
    beta <- matrix(0, nrow = p + 1, ncol = 2)
    beta[1,] <- c(-1, 1)
    beta[cbind(c(5, 10), c(1, 2))] <- 1

    nobs <- 100
    X <- matrix(rnorm(nobs * p), nobs, p)
    mu <- cbind(1, X) %*% beta
    z <- sample(1:ncol(beta), nobs, replace = TRUE)
    y <- mu[cbind(1:nobs, z)] + rnorm(nobs)
    data <- data.frame(y, X)
    ## The maximum number of iterations is reduced to
    ## avoid a long running time.
    fo <- sample(rep(seq(10), length = nrow(data)))
    ex1 <- flexmix(y ~ ., data = data, k = 2, cluster = z,
                   model = FLXMRglmnet(foldid = fo),
                   control = list(iter.max = 2))
    parameters(ex1)

Run the code above in your browser using DataLab