predict.wals {WALS} | R Documentation |
Methods for wals and walsMatrix Objects
Description
Methods for extracting information from fitted model-averaging objects of
classes "wals"
and "walsMatrix"
. "walsMatrix"
objects
inherit from "wals"
, so the methods for "wals"
also work for
objects of class "walsMatrix"
.
Usage
## S3 method for class 'wals'
predict(object, newdata, na.action = na.pass, ...)
## S3 method for class 'walsMatrix'
predict(object, newX1, newX2, ...)
## S3 method for class 'wals'
fitted(object, ...)
## S3 method for class 'wals'
residuals(object, ...)
## S3 method for class 'wals'
print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'wals'
summary(object, ...)
## S3 method for class 'summary.wals'
print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'wals'
coef(object, type = c("all", "focus", "aux"), transformed = FALSE, ...)
## S3 method for class 'wals'
vcov(object, type = c("all", "focus", "aux"), transformed = FALSE, ...)
## S3 method for class 'wals'
nobs(object, ...)
## S3 method for class 'wals'
terms(x, type = c("focus", "aux"), ...)
## S3 method for class 'wals'
model.matrix(object, type = c("focus", "aux"), ...)
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. |
na.action |
Function determining what should be done with missing values
in |
... |
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. |
digits |
The number of significant digits to display. |
type |
Character specifying the part of the model that should be returned. For details see below. |
transformed |
Logical specifying whether the coefficients/covariance
matrix of original regressors ( |
Details
A set of standard extractor functions for fitted model objects is available
for objects of class "wals"
and "walsMatrix"
, including methods to
the generic functions print
and summary
which print the model-averaged estimation of the coefficients along with some
further information. As usual, the summary
method returns an object of
class "summary.wals"
containing the relevant summary statistics which
can then be printed using the associated print
method.
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 \Xi = \Delta_{2} X_{2}^{\top} M_{1} X_{2} \Delta_{2}
.
The summary further provides information on the prior used along with its
parameters. The summary()
, print.summary()
,
print()
and logLik()
methods are also inspired by the corresponding
methods for objects of class "lm"
in stats
version
4.3.1 (2023-06-16) (R Core Team 2023), see e.g. print.summary.lm
.
The residuals
method computes raw residuals
(observed - fitted).
For coef
and vcov
, the type
argument, either "all"
, "focus"
or "aux"
, specifies which
part of the coefficient vector/covariance matrix of the estimates should be
returned. Additionally, the transformed
argument specifies whether to
return the estimated coefficients/covariance matrix for the original
regressors X
or of the transformed regressors Z
.
The extractors terms
and model.matrix
behave similarly to coef
, but they only allow type = "focus"
and type = "aux"
. They extract the corresponding component of the model.
This is similar to the implementation of these extractors in countreg
version 0.2-1 (2023-06-13) (Zeileis and Kleiber 2023; Zeileis et al. 2008), see e.g.
terms.hurdle()
.
Value
predict.wals()
and predict.walsMatrix()
return a vector
containing the predicted means.
fitted.wals()
returns a vector containing the fitted means
for the data used in fitting.
residuals.wals()
returns the raw residuals of the fitted
model, i.e. response - fitted mean.
print.wals()
invisibly returns its input argument x
,
i.e. an object of object of class "wals"
.
summary.wals
returns an object of class "summary.wals"
which contains the necessary fields for printing the summary in
print.summary.wals()
.
print.summary.wals()
invisibly returns its input argument
x
, i.e. an object of object of class "summary.wals"
.
coef.wals()
returns a vector containing the fitted coefficients.
If type = "focus"
, only the coefficients of the focus regressors are
returned and if type = "aux"
, only the coefficients of auxiliary
regressors are returned. Else if type = "all"
, the coefficients
of both focus and auxiliary regressors are returned. Additionally if
transformed = FALSE
, coef.wals()
returns the estimated
coefficients for the original regressors X
(\beta
coefficients)
and else if transformed = TRUE
the coefficients of the transformed
regressors Z
(\gamma
coefficients).
vcov.wals()
returns a matrix containing the estimated
(co-)variances of the fitted regression coefficients. If type = "focus"
,
only the submatrix belonging to the focus regressors is returned and if
type = "aux"
, only the submatrix corresponding to the auxiliary
regressors is returned. Else if type = "all"
, the complete covariance
matrix is returned. Additionally if transformed = FALSE
,
vcov.wals()
returns the estimated covariance matrix for the original
regressors X
(\beta
coefficients) and else if
transformed = TRUE
the covariance matrix of the transformed regressors
Z
(\gamma
coefficients).
nobs.wals()
returns the number of observations used for
fitting the model.
terms.wals()
returns the terms representation of the fitted
model. It is of class c("terms", "formula")
, see terms
and terms.object
for more details. If type = "focus"
,
then returns the terms for the focus regressors, else if type = "aux"
returns the terms for the auxiliary regressors.
model.matrix.wals()
either returns the design matrix of the
focus regressors (type = "focus"
) or of the auxiliary regressors
(type = "aux"
). See model.matrix
for more details.
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
Examples
## Example for wals objects
fitGrowth <- wals(gdpgrowth ~ lgdp60 + equipinv + school60 + life60 + popgrowth |
law + tropics + avelf + confucian, data = GrowthMPP,
prior = laplace())
summary(fitGrowth)
fitted(fitGrowth)
vcov(fitGrowth, type = "aux")
familyPrior(fitGrowth)
nobs(fitGrowth)
## Example for walsMatrix objects
X1 <- model.matrix(fitGrowth, type = "focus")
X2 <- model.matrix(fitGrowth, type = "aux")
y <- GrowthMPP$gdpgrowth
fitGrowthMatrix <- wals(X1, X2, y, prior = laplace())
coef(fitGrowthMatrix)