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 |
... |
Arguments for workhorse |
formula |
an object of class |
family |
Object of class |
data |
an optional data frame, list or environment
(or object coercible by |
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 |
controlInitGLM |
Controls estimation of starting values for one-step ML,
see |
model |
if |
keepY |
if |
keepX |
if |
iterate |
if |
tol |
Only used if |
maxIt |
Only used if |
nIt |
Only used if |
verbose |
If |
x2 |
Design matrix of auxiliary regressors. Usually does not include
a constant column and can also be generated using |
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 |
|
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 |
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)