predict.walsGLM {WALS} | R Documentation |
Methods for walsGLM, walsGLMmatrix, walsNB and walsNBmatrix Objects
Description
Methods for extracting information from fitted model-averaging objects of
classes "walsGLM"
, "walsGLMmatrix"
, "walsNB"
and
"walsNBmatrix"
.
Usage
## S3 method for class 'walsGLM'
predict(
object,
newdata,
type = c("response", "link", "variance", "prob", "density", "logDens"),
at = NULL,
na.action = na.pass,
log = FALSE,
...
)
## S3 method for class 'walsGLMmatrix'
predict(
object,
newX1,
newX2,
newY = NULL,
type = c("response", "link", "variance", "prob", "density", "logDens"),
at = NULL,
log = FALSE,
...
)
## S3 method for class 'walsGLM'
residuals(object, type = c("deviance", "pearson", "response"), ...)
## S3 method for class 'walsGLM'
print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'walsGLM'
summary(object, ...)
## S3 method for class 'summary.walsGLM'
print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'walsGLM'
logLik(object, ...)
## S3 method for class 'walsNB'
summary(object, ...)
## S3 method for class 'summary.walsNB'
print(x, digits = max(3, getOption("digits") - 3), ...)
Arguments
object , x |
An object of class |
newdata |
Optionally, a data frame in which to look for variables with which to predict. If omitted, the original observations are used. |
type |
Character specifying the type of prediction, residual or model part to be returned. For details see below. |
at |
Optional. Only available if a family of class |
na.action |
Function determining what should be done with missing values
in |
log |
Logical. If |
... |
Further arguments passed to methods. |
newX1 |
Focus regressors matrix to be used for the prediction. |
newX2 |
Auxiliary regressors matrix to be used for the prediction. |
newY |
Response vector to be used in predictions. Only relevant when
|
digits |
The number of significant digits to display. |
Details
As the "-matrix"
classes "walsGLMmatrix"
and "walsNBmatrix"
inherit from the "non-matrix" classes, i.e. "walsGLM"
and "walsNB"
,
respectively, the following text will treat them as equivalent because
they inherit all methods but predict
from their "non-matrix" versions.
Thus, when "walsGLM"
or "walsNB"
are mentioned, we also refer to
their "-matrix"
versions, except when explicitly stated. Moreover,
note that "walsNB"
and "walsNBmatrix"
inherit most methods from
"walsGLM"
and "walsGLMmatrix"
.
A set of standard extractor functions for fitted model objects is available
for objects of class "walsGLM"
and "walsNB"
, including methods to
the generic functions print
and summary
which print the model-averaged estimation of the coefficients along with some
further information.
The summary
methods returns an object of
class "summary.walsGLM"
for objects of class "walsGLM"
and an
object of class "summary.walsNB"
for objects of class "walsNB"
.
They contain the relevant summary statistics which can then be printed using
the associated print()
methods.
Inspired by De Luca and Magnus (2011), the summary statistics
also show Kappa
which is an indicator for the numerical stability of
the method, i.e. it shows the square root of the condition number of the
matrix \bar{\Xi} = \bar{\Delta}_{2} \bar{X}_{2}^{\top} \bar{M}_{1}
\bar{X}_{2} \bar{\Delta}_{2}
. The summary further shows the deviance and
provides information on the prior and family used.
A logLik
method is provided that returns the log-likelihood
given the family used and the model-averaged estimates of the coefficients.
"walsGLM"
inherits from "wals"
, while "walsNB"
inherits from
both, "walsGLM"
and "wals"
. Thus, see predict.wals
for more methods.
The predict
and residuals
methods,
especially the different types of predictions/residuals controlled by
type
, are inspired by the corresponding methods in countreg
version 0.2-1 (2023-06-13) (Zeileis and Kleiber 2023; Zeileis et al. 2008), see
e.g. predict.hurdle()
from countreg
, and stats
version 4.3.1 (2023-06-16) (R Core Team 2023), see e.g.
residuals.glm
. The summary()
, print.summary()
,
print()
and logLik()
methods are also inspired by the corresponding
methods for objects of class "glm"
in stats
, see
e.g. print.summary.glm
.
coef
and vcov
are inherited from
"wals"
(see predict.wals
for more), except for
objects of class "walsNB"
(see vcov.walsNB
).
The type
argument specifies which part of the coefficient
vector/covariance matrix of the estimates should be returned.
For type = "all"
, they return the complete vector/matrix.
For type = "focus"
and type = "aux"
they return only the part
corresponding to the focus and auxiliary regressors, respectively.
Additionally, the user can choose whether to return the
estimated coefficients/covariance matrix for the original regressors X
(\beta
coefficients) or of the transformed regressors Z
(\gamma
coefficients).
The extractors terms
and model.matrix
are also inherited from "wals"
. They only allow type = "focus"
and type = "aux"
and extract the corresponding component of the model.
Value
predict.walsGLM()
and predict.walsGLMmatrix()
return
different types of predictions depending on the argument type
:
-
type = "response"
: vector. Predicted mean -
type = "link"
: vector. Predicted linear link -
type = "variance"
: vector. Predicted variance -
type = "prob"
: matrix. Only available if a family of class"familyWALScount"
was used for fitting or for objects of class"walsNB"
or"walsNBmatrix"
. Returns the probability at counts specified byat
. -
type = "density"
: vector. Predicted density -
type = "logDens"
: vector. For convenience, returns predicted log-density. Equivalent to settingtype = "density"
andlog = TRUE
.
If type = "prob"
, type = "density"
or type = "logDens"
,
then newdata
must contain the response or newY
must be
specified depending on the class of the object.
residuals.walsGLM()
returns different types of residuals
depending on the argument type
:
-
type = "deviance"
: deviance residuals -
type = "pearson"
: Pearson residuals (raw residuals scaled by square root of variance function) -
type = "response"
: raw residuals (observed - fitted)
print.walsGLM()
invisibly returns its input argument x
,
i.e. an object of object of class "walsGLM"
.
summary.walsGLM()
returns an object of class
"summary.walsGLM"
which contains the necessary fields for printing the
summary in print.summary.walsGLM()
.
print.summary.walsGLM()
invisibly returns its input argument
x
, i.e. an object of object of class "summary.walsGLM"
.
logLik.walsGLM()
returns the log-likelihood of the fitted
model.
summary.walsNB()
returns an object of class
"summary.walsNB"
which contains the necessary fields for printing the
summary in print.summary.walsNB()
.
print.summary.walsNB()
invisibly returns its input argument
x
, i.e. an object of object of class "summary.walsNB"
.
References
De Luca G, Magnus JR (2011).
“Bayesian model averaging and weighted-average least squares: Equivariance, stability, and numerical issues.”
The Stata Journal, 11(4), 518–544.
doi:10.1177/1536867X1201100402.
R Core Team (2023).
R: A Language and Environment for Statistical Computing.
R Foundation for Statistical Computing, Vienna, Austria.
https://www.R-project.org/.
Zeileis A, Kleiber C (2023).
countreg: Count Data Regression.
R package version 0.2-1, https://r-forge.r-project.org/projects/countreg/.
Zeileis A, Kleiber C, Jackman S (2008).
“Regression Models for Count Data in R.”
Journal of Statistical Software, 27(8), 1–25.
doi:10.18637/jss.v027.i08.
See Also
walsGLM, walsNB, predict.wals.
Examples
## Example for walsGLM objects
data("HMDA", package = "AER")
fitBinomial <- walsGLM(deny ~ pirat + hirat + lvrat + chist + mhist + phist |
selfemp + afam, family = binomialWALS(), data = HMDA,
prior = weibull())
summary(fitBinomial)
vcov(fitBinomial, type = "focus")
logLik(fitBinomial)
predict(fitBinomial, newdata = HMDA[1:10,], type = "response")
familyWALS(fitBinomial)
## Example for walsNB objects
data("NMES1988", package = "AER")
fWals <- (visits ~ chronic + age + I((age^2)/10) + insurance + medicaid |
adl + gender + married + income + school + afam + employed)
fitNB <- walsNB(fWals, data = NMES1988, link = "log", prior = weibull(),
method = "fullSVD")
summary(fitNB)
coef(fitNB, type = "aux")
residuals(fitNB, type = "pearson")
predict(fitNB, newdata = NMES1988[1:10,], type = "prob")
terms(fitNB, type = "aux")