walsGLM {WALS}R Documentation

Weighted Average Least Squares for Generalized Linear Models

Description

Performs model averaging of generalized linear models (GLMs) using the Weighted-Average Least Squares method described in De Luca et al. (2018).

Usage

walsGLM(x, ...)

## S3 method for class 'formula'
walsGLM(
  formula,
  family,
  data,
  subset = NULL,
  na.action = NULL,
  weights = NULL,
  offset = NULL,
  prior = weibull(),
  controlInitGLM = controlGLM(),
  model = TRUE,
  keepY = TRUE,
  keepX = FALSE,
  iterate = FALSE,
  tol = 1e-06,
  maxIt = 50,
  nIt = NULL,
  verbose = FALSE,
  ...
)

## S3 method for class 'matrix'
walsGLM(
  x,
  x2,
  y,
  family,
  subset = NULL,
  na.action = NULL,
  weights = NULL,
  offset = NULL,
  prior = weibull(),
  controlInitGLM = controlGLM(),
  keepY = TRUE,
  keepX = FALSE,
  iterate = FALSE,
  tol = 1e-06,
  maxIt = 50,
  nIt = NULL,
  verbose = FALSE,
  ...
)

## Default S3 method:
walsGLM(x, ...)

Arguments

x

Design matrix of focus regressors. Usually includes a constant (column full of 1s) and can be generated using model.matrix.

...

Arguments for workhorse walsGLMfit.

formula

an object of class "Formula" (or one that can be coerced to that class, e.g. "formula"): a symbolic description of the model to be fitted. The details of model specification are given under ‘Details’.

family

Object of class "familyWALS".

data

an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment which the function is called from.

subset

an optional vector specifying a subset of observations to be used in the fitting process.

na.action

not implemented yet.

weights

not implemented yet.

offset

not implemented yet.

prior

Object of class "familyPrior". For example weibull or laplace.

controlInitGLM

Controls estimation of starting values for one-step ML, see controlGLM.

model

if TRUE (default), then the model.frame is stored in the return.

keepY

if TRUE (default), then the response is stored in the return.

keepX

if TRUE, then the model matrices are stored in the return. the return.

iterate

if TRUE then the WALS algorithm is iterated using the previous estimates as starting values.

tol

Only used if iterate = TRUE and nIt = NULL. If the Euclidean distance between the previous and current coefficient vector divided by the square root of the length of the vector falls below tol, then the algorithm stops. See walsGLMfitIterate for more details.

maxIt

Only used if iterate = TRUE and nIt = NULL. Aborts iterative fitting when number of iterations exceed maxIt.

nIt

Only used if iterate = TRUE. If this is specified, then tol is ignored and the algorithm iterates nIt times. This option should not be used unless the user has a specific reason to run the algorithm nIt times, e.g. for replication purposes.

verbose

If verbose = TRUE, then it prints the iteration process (only relevant if iterate = TRUE).

x2

Design matrix of auxiliary regressors. Usually does not include a constant column and can also be generated using model.matrix.

y

Response as vector.

Details

Computes WALS estimates when focus regressors (X1) are present in all submodels and model averaging takes place over the auxiliary regressors (X2).

Formulas typically contain two parts, i.e. they are of the form "y ~ X11 + X12 | X21 + X22", where the variables before "|" are the focus regressors (includes a constant by default) and the ones after "|" are the auxiliary regressors. If only a one-part formula is specified, then all regressors are considered as auxiliary regressors and only a constant is employed as focus regressor, i.e. "y ~ X1 + X2" is equivalent to "y ~ 1 | X1 + X2".

WARNING: Interactions in formula do work work properly yet. It is recommended to manually create the interactions beforehand and then to insert them as 'linear terms' in the formula.

walsGLM.default() raises an error if x is not an object of class "matrix" or a class that extends "matrix". Otherwise it calls walsGLM.matrix(). It is a modified version of glmboost.default from the mboost package version 2.9-8 (2023-09-06) (Hofner et al. 2014).

Value

walsGLM.formula() returns an object of class "walsGLM" which inherits from "wals". This is a list that contains all elements returned from walsGLMfitIterate and additionally

cl

Call of the function.

formula

formula used.

terms

List containing the model terms of the focus and auxiliary regressors separately, as well as for the full model.

levels

List containing the levels of the focus and auxiliary regressors separately, as well as for the full model.

contrasts

List containing the contrasts of the design matrices of focus and auxiliary regressors.

model

If model = TRUE, contains the model frame.

See returns of walsGLMfit and walsGLMfitIterate for more details.

walsGLM.matrix() returns an object of class "walsGLMmatrix", which inherits from "walsGLM", "walsMatrix" and "wals". This is a list that contains all elements returned from walsGLMfitIterate and additionally the call in cl.

walsGLM.default() raises an error if x is not an object of class "matrix" or a class that extends "matrix". Otherwise returns an object of class "walsGLMmatrix". See above for more details.

References

De Luca G, Magnus JR, Peracchi F (2018). “Weighted-average least squares estimation of generalized linear models.” Journal of Econometrics, 204(1), 1–17. doi:10.1016/j.jeconom.2017.12.007.

Hofner B, Mayr A, Robinzonov N, Schmid M (2014). “Model-based Boosting in R: A Hands-on Tutorial Using the R Package mboost.” Computational Statistics, 29, 3–35.

Examples

data("HMDA", package = "AER")
fitBinomial <- walsGLM(deny ~ pirat + hirat + lvrat + chist + mhist + phist |
                       selfemp + afam, data = HMDA, family = binomialWALS(),
                       prior = weibull())
summary(fitBinomial)

data("NMES1988", package = "AER")
fitPoisson <- walsGLM(emergency ~ health + chronic + age + gender |
                      I((age^2)/10) + married + region, data = NMES1988,
                      family = poissonWALS(), prior = laplace())
summary(fitPoisson)

## Example for walsGLM.matrix()
data("HMDA", package = "AER")
X <- model.matrix(deny ~ pirat + hirat + lvrat + chist + mhist + phist + selfemp + afam,
                  data = HMDA)
X1 <- X[,c("(Intercept)", "pirat", "hirat", "lvrat", "chist2", "chist3",
        "chist4", "chist5", "chist6", "mhist2", "mhist3", "mhist4", "phistyes")]
X2 <- X[,c("selfempyes", "afamyes")]
y <- HMDA$deny
fit <- walsGLM(X1, X2, y, family = binomialWALS(), prior = weibull())
summary(fit)


[Package WALS version 0.2.5 Index]