Description Usage Arguments Details Value References See Also Examples
SMuRF algorithm to fit a generalized linear model (GLM) with multiple types of predictors via regularized maximum likelihood.
glmsmurf.fit
contains the fitting function for a given design matrix.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | glmsmurf(
formula,
family,
data,
weights,
start,
offset,
lambda,
lambda1 = 0,
lambda2 = 0,
pen.weights,
adj.matrix,
standardize = TRUE,
control = list(),
x.return = FALSE,
y.return = TRUE,
pen.weights.return = FALSE
)
glmsmurf.fit(
X,
y,
weights,
start,
offset,
family,
pen.cov,
n.par.cov,
group.cov,
refcat.cov,
lambda,
lambda1 = 0,
lambda2 = 0,
pen.weights,
adj.matrix,
standardize = TRUE,
control = list(),
formula = NULL,
data = NULL,
x.return = FALSE,
y.return = FALSE,
pen.weights.return = FALSE
)
|
formula |
A |
family |
A |
data |
A data frame containing the model response and predictors for |
weights |
An optional vector of prior weights to use in the likelihood. It should be a numeric vector of length |
start |
A vector containing the starting values for the coefficients. It should either be a numeric vector
of length |
offset |
A vector containing the offset for the model. It should be a vector of size |
lambda |
Either the penalty parameter, a positive number; or a string describing the method and measure used to select the penalty parameter:
E.g. |
lambda1 |
The penalty parameter for the L_1-penalty in Sparse (Generalized) Fused Lasso or Sparse Graph-Guided Fused Lasso is λ \times λ_1. A positive numeric with default 0 (no extra L_1-penalty). |
lambda2 |
The penalty parameter for the L_2-penalty in Group (Generalized) Fused Lasso or Group Graph-Guided Fused Lasso is λ \times λ_2. A positive numeric with default 0 (no extra L_2-penalty). |
pen.weights |
Either a string describing the method to compute the penalty weights:
or a list with the penalty weight vector per predictor. This list should have length equal to the number of predictors and predictor names as element names. |
adj.matrix |
A named list containing the adjacency matrices (a.k.a. neighbor matrices) for each of the predictors with a Graph-Guided Fused Lasso penalty. The list elements should have the names of the corresponding predictors. If only one predictor has a Graph-Guided Fused Lasso penalty, it is also possible to only give the adjacency matrix itself (not in a list). |
standardize |
Logical indicating if predictors with a Lasso or Group Lasso penalty are standardized, default is |
control |
A list of parameters used in the fitting process. This is passed to |
x.return |
Logical indicating if the used model matrix should be returned in the output object, default is |
y.return |
Logical indicating if the used response vector should be returned in the output object, default is |
pen.weights.return |
Logical indicating if the list of the used penalty weight vector per predictor should be returned in the output object, default is |
X |
Only for |
y |
Only for |
pen.cov |
Only for |
n.par.cov |
Only for |
group.cov |
Only for |
refcat.cov |
Only for |
See the package vignette for more details and a complete description of a use case.
As a user, it is important to take the following into acocunt:
The estimated coefficients are rounded to 7 digits.
The cross-validation folds are not deterministic. The validation sample for selecting lambda out-of-sample is determined at random when no indices are provided in 'validation.index' in the control object argument. In these cases, the selected value of lambda is hence not deterministic. When selecting lambda in-sample, or out-of-sample when indices are provided in 'validation.index' in the control object argument, the selected value of lambda is deterministic.
The glmsmurf
function can handle many use cases and is preferred for general use.
The glmsmurf.fit
function requires a more thorough understanding of the package internals and should hence be used with care!
An object of class 'glmsmurf
' is returned. See glmsmurf-class
for more details about this class and its generic functions.
Devriendt, S., Antonio, K., Reynkens, T. and Verbelen, R. (2021). "Sparse Regression with Multi-type Regularized Feature Modeling", Insurance: Mathematics and Economics, 96, 248–261. <doi:10.1016/j.insmatheco.2020.11.010>.
Hastie, T., Tibshirani, R., and Wainwright, M. (2015). Statistical Learning with Sparsity: The Lasso and Generalizations. CRC Press.
glmsmurf-class
, glmsmurf.control
, p
, glm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # Munich rent data from catdata package
data("rent", package = "catdata")
# The considered predictors are the same as in
# Gertheiss and Tutz (Ann. Appl. Stat., 2010).
# Response is monthly rent per square meter in Euro
# Urban district in Munich
rent$area <- as.factor(rent$area)
# Create formula with 'rentm' as response variable,
# 'area' with a Generalized Fused Lasso penalty,
formu <- rentm ~ p(area, pen = "gflasso")
# Quick comparison with previous package in terms of speed
rbenchmark::benchmark(smurf::glmsmurf(formula = formu, family = gaussian, data = rent,
pen.weights = "glm.stand", lambda = 5e-3,
control = glmsmurf.control(epsilon = 1e-8, print = F , ncores = 1, po.ncores = 1)),
ssmurf::glmsmurf(formula = formu, family = gaussian, data = rent,
pen.weights = "glm.stand", lambda = 5e-3,
control = glmsmurf.control(epsilon = 1e-8, print = F , ncores = 1, po.ncores = 1)),
replications = 20)
# The following comparison takes a bit longer
l = c(exp(seq(log(64), log(1e-4), length.out = 50)))
# Speed comparison to the previous package
rbenchmark::benchmark(smurf::glmsmurf(formula = formu, family = gaussian, data = rent,
pen.weights = "glm.stand", lambda = "cv1se.dev",
control = glmsmurf.control(epsilon = 1e-8, print = F , k = 10, ncores = 1, po.ncores = 1,
lambda.vector = l)),
ssmurf::glmsmurf(formula = formu, family = gaussian, data = rent,
pen.weights = "glm.stand", lambda = "cv1se.dev",
control = glmsmurf.control(epsilon = 1e-8, print = F, k = 10, ncores = 1, po.ncores = 1,
lambda.vector = l)), replications = 10)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.