Learn R Programming

WALS (version 0.2.5)

walsGLMfit: Fitter function for Weighted Average Least Squares estimation of GLMs

Description

Workhorse function behind walsGLM and used internally in walsGLMfitIterate.

Usage

walsGLMfit(
  X1,
  X2,
  y,
  betaStart1,
  betaStart2,
  family,
  prior = weibull(),
  postmult = TRUE,
  ...
)

Value

A list containing all elements returned by walsFit, except for residuals, and additionally (some fields are replaced)

condition

Condition number of the matrix \(\bar{\Xi} = \bar{\Delta}_{2} \bar{X}_{2}^{\top} \bar{M}_{1} \bar{X}_{2} \bar{\Delta}_{2}\).

family

Object of class "familyWALS". The family used.

betaStart

Starting values of the regression coefficients for the one-step ML estimators.

fitted.link

Linear link fitted to the data.

fitted.values

Estimated conditional mean for the data. Lives on the scale of the response.

Arguments

X1

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

X2

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

y

Response as vector.

betaStart1

Starting values for coefficients of focus regressors X1.

betaStart2

Starting values for coefficients of auxiliary regressors X2.

family

Object of class "familyWALS".

prior

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

postmult

If TRUE (default), then it computes $$\bar{Z}_{2} = \bar{X}_{2} \bar{\Delta}_{2} \bar{T} \bar{\Lambda}^{-1/2} \bar{T}^{\top},$$ where \(\bar{T}\) contains the eigenvectors and \(\bar{\Lambda}\) the eigenvalues from the eigenvalue decomposition $$\bar{\Xi} = \bar{T} \bar{\Lambda} \bar{T}^{\top},$$ instead of $$\bar{Z}_{2} = \bar{X}_{2} \bar{\Delta}_{2} \bar{T} \bar{\Lambda}^{-1/2}.$$ See huynhwals;textualWALS for more details. The latter is used in the original MATLAB code for WALS in the linear regression model, see eq. (12) of magnus2016wals;textualWALS. The first form is required in eq. (9) of deluca2018glm;textualWALS. Thus, it is not recommended to set postmult = FALSE.

...

Further arguments passed to walsFit.

Details

Uses walsFit under the hood after transforming the regressors X1 and X2 and the response y. For more details, see huynhwalsWALS and deluca2018glm;textualWALS.

References

See Also

walsGLM, walsGLMfitIterate, walsFit.

Examples

Run this code
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

# starting values from glm.fit()
betaStart <- glm.fit(X, y, family = binomialWALS())$coefficients
k1 <- ncol(X1)
k2 <- ncol(X2)

str(walsGLMfit(X1, X2, y,
               betaStart1 = betaStart[1:k1],
               betaStart2 = betaStart[(k1 + 1):(k1 + k2)],
               family = binomialWALS(), prior = weibull()))


Run the code above in your browser using DataLab