walsNBfit | R Documentation |
Workhorse function behind walsNB
and used internally in
walsNBfitIterate
.
walsNBfit(
X1,
X2,
y,
betaStart1,
betaStart2,
rhoStart,
family,
prior,
method = c("fullSVD", "original"),
svdTol = .Machine$double.eps,
svdRtol = 1e-06,
keepUn = FALSE,
keepR = FALSE,
eigenSVD = TRUE,
postmult = TRUE,
...
)
X1 |
Design matrix for focus regressors. Usually includes a constant
(column full of 1s) and can be generated using |
X2 |
Design matrix for auxiliary regressors. Usually does not include
a constant column and can also be generated using |
y |
Count response as vector. |
betaStart1 |
Starting values for coefficients of focus regressors X1. |
betaStart2 |
Starting values for coefficients of auxiliary regressors X2. |
rhoStart |
Starting value for log-dispersion parameter of NB2 |
family |
Object of class |
prior |
Object of class |
method |
Specifies method used. Available methods are |
svdTol |
Tolerance for rank of matrix |
svdRtol |
Relative tolerance for rank of matrix |
keepUn |
If |
keepR |
If |
eigenSVD |
If |
postmult |
If
where
instead of
See \insertCitehuynhwals;textualWALS for more details. The latter is used
in the original MATLAB code for WALS in the linear regression model,
see eq. (12) of \insertCitemagnus2016wals;textualWALS.
The first form is required in eq. (9) of \insertCitedeluca2018glm;textualWALS.
Thus, it is not recommended to set |
... |
Arguments for internal function |
The method to be specified in method
mainly differ in the way
they compute the fully restricted and unrestricted estimators for the
transformed regressors Z
, i.e. \tilde{\gamma}_{1r}
,
and \tilde{\gamma}_{u}
.
Recommended approach. First applies an SVD to \bar{Z}_{1}
to compute \bar{X}_{2}^{\top} \bar{M}_{1} \bar{X}_{2}
:
It is used for computing the inverse of
\bar{X}_{1}^{\top}\bar{X}_{1}
+ \bar{g} \bar{\epsilon} X_{1}^{\top}\bar{q} \bar{q}^{\top} X_{1},
when using the Sherman-Morrison-Woodbury formula. We further leverage the
SVD of \bar{Z}_1
and additionally \bar{Z}
to compute the
unrestricted estimator \tilde{\gamma}_{u}
and the fully restricted
estimator \tilde{\gamma}_{r}
. For \tilde{\gamma}_{u}
, we simply
use the SVD of \bar{Z}
to solve the full equation system derived from
the one-step ML problem for more details. The SVD of \bar{Z}_1
is further
used in computing the model averaged estimator for the focus regressors
\hat{\gamma}_1
.
Described in more detail in the appendix of \insertCitehuynhwals;textualWALS.
Computes all inverses directly using solve
and does not make use of the Sherman-Morrison-Woodbury formula for certain
inverses. Specifically, it directly inverts the matrix
\bar{Z}_{1}^{\top} \bar{Z}_{1}
using solve
in order to compute \bar{M}_1
. Moreover, it computes the fully
unrestricted estimators of the focus regressors
\tilde{\gamma}_{1u}
and of the auxiliary regressors
\tilde{\gamma}_{2u}
and the fully restricted estimator
\tilde{\gamma}_{1r}
by directly implementing the formulas derived
in \insertCitehuynhwalsnb;textualWALS.
This method should only be used as reference and for easier
debugging.
All variables in the code that contain "start" in their name are computed using the starting values of the one-step ML estimators. See section "One-step ML estimator" of \insertCitehuynhwalsnbWALS for details.
A list containing
coef |
Model averaged estimates of all coefficients. |
beta1 |
Model averaged estimates of the coefficients of the focus regressors. |
beta2 |
Model averaged estimates of the coefficients of the auxiliary regressors. |
rho |
Model averaged estimate of the log-dispersion parameter of the NB2 distribution. |
gamma1 |
Model averaged estimates of the coefficients of the transformed focus regressors. |
gamma2 |
Model averaged estimates of the coefficients of the transformed auxiliary regressors. |
condition |
Condition number of the matrix
|
vcovBeta |
|
vcovGamma |
|
betaStart |
Starting values of the regression coefficients for the one-step ML estimators. |
rhoStart |
Starting values of the dispersion parameter for the one-step ML estimators. |
method |
Stores |
prior |
|
betaUn1 |
If |
betaUn2 |
If |
gammaUn1 |
If |
gammaUn2 |
If |
gamma1r |
If |
k1 |
Number of focus regressors. |
k2 |
Number of auxiliary regressors. |
n |
Number of observations. |
X1names |
Names of the focus regressors. |
X2names |
Names of the auxiliary regressors. |
familyStart |
The family object of class |
family |
The family object of class |
fitted.link |
Linear link fitted to the data. |
fitted.values |
Estimated conditional mean for the data. Lives on the scale of the response. |
walsNB, walsNBfitIterate.
data("NMES1988", package = "AER")
NMES1988 <- na.omit(NMES1988)
form <- (visits ~ health + chronic + age + insurance + adl + region + gender
+ married + income + school + employed)
X <- model.matrix(form, data = NMES1988)
focus <- c("(Intercept)", "healthpoor", "healthexcellent", "chronic", "age",
"insuranceyes")
aux <- c("adllimited", "regionnortheast", "regionmidwest", "regionwest",
"gendermale", "marriedyes", "income", "school", "employedyes")
X1 <- X[, focus]
X2 <- X[, aux]
y <- NMES1988$visits
# starting values from glm.nb() from MASS
startFit <- MASS::glm.nb(y ~ X[,-1])
betaStart <- coef(startFit)
rhoStart <- startFit$theta
k1 <- ncol(X1)
k2 <- ncol(X2)
str(walsNBfit(X1, X2, y, rhoStart, family = negbinWALS(scale = rhoStart, link = "log"),
betaStart1 = betaStart[1:k1],
betaStart2 = betaStart[(k1 + 1):(k1 + k2)],
prior = weibull(), method = "fullSVD"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.