walsFit: Fitter function for Weighted Average Least Squares estimation

View source: R/wals.R

walsFitR Documentation

Fitter function for Weighted Average Least Squares estimation

Description

Workhorse function behind wals and walsGLM.

Usage

walsFit(
  X1,
  X2,
  y,
  sigma = NULL,
  prior = weibull(),
  method = "original",
  svdTol = .Machine$double.eps,
  svdRtol = 1e-06,
  keepUn = FALSE,
  eigenSVD = TRUE,
  prescale = TRUE,
  postmult = FALSE,
  ...
)

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.

sigma

if NULL (default), then the variance of the error term is estimated, see p.136 of \insertCitemagnus2016wals;textualWALS. If sigma is specified, then the unrestricted estimator is divided by sigma before performing the Bayesian posterior mean estimation.

prior

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

method

Specifies method used. Available methods are "original" (default) or "svd".

svdTol

Tolerance for rank of matrix \bar{Z}_{1} Only used if method = "svd". Checks if smallest eigenvalue in SVD of \bar{Z}_1 and \bar{Z} is larger than svdTol, otherwise reports a rank deficiency.

svdRtol

Relative tolerance for rank of matrix \bar{Z}_{1}. Only used if method = "svd". Checks if ratio of largest to smallest eigenvalue in SVD of \bar{Z}_1 is larger than svdRtol, otherwise reports a rank deficiency.

keepUn

If TRUE, keeps the estimators of the unrestricted model, i.e. \tilde{\gamma}_{u}.

eigenSVD

If TRUE, then semiorthogonalize uses svd to compute the eigendecomposition of \bar{\Xi} instead of eigen. In this case, the tolerances of svdTol and svdRtol are used to determine whether \bar{\Xi} is of full rank (need it for \bar{\Xi}^{-1/2}).

prescale

If TRUE (default), prescales the regressors X1 and X2 with \Delta_1 and \Delta_2, respectively, to improve numerical stability and make the coefficients of the auxiliary regressors scale equivariant. See \insertCitedeluca2011stata;textualWALS for more details. WARNING: It is not recommended to set prescale = FALSE. The option prescale = FALSE only exists for historical reasons.

postmult

If TRUE, then it computes

Z_{2} = X_{2} \Delta_{2} T \Lambda^{-1/2} T^{\top},

where T contains the eigenvectors and \Lambda the eigenvalues from the eigenvalue decomposition

\Xi = \Delta_2 X_{2}^{\top} M_{1} X_{2} \Delta_2 = T \Lambda T^{\top},

instead of

Z_{2} = X_{2} \Delta_{2} T \Lambda^{-1/2}.

See \insertCitehuynhwals;textualWALS for more details. The latter is used in the original MATLAB code for WALS in the linear regression model \insertCitemagnus2010growth,deluca2011stata,kumar2013normallocation,magnus2016walsWALS, see eq. (12) of \insertCitemagnus2016wals;textualWALS. The first form is required in eq. (9) of \insertCitedeluca2018glm;textualWALS. It is not recommended to set postmult = FALSE when using walsGLM and walsNB.

...

Arguments for internal function computePosterior.

Value

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.

gamma1

Model averaged estimates of the coefficients of the transformed focus regressors.

gamma2

Model averaged estimates of the coefficients of the transformed auxiliary regressors.

vcovBeta

Estimated covariance matrix of the regression coefficients.

vcovGamma

Estimated covariance matrix of the coefficients of the transformed regressors.

sigma

Estimated or prespecified standard deviation of the error term.

prior

familyPrior. The prior specified in the arguments.

method

Stores method used from the arguments.

betaUn1

If keepUn = TRUE, contains the unrestricted estimators of the coefficients of the focus regressors.

betaUn2

If keepUn = TRUE, contains the unrestricted estimators of the coefficients of the auxiliary regressors.

gammaUn1

If keepUn = TRUE, contains the unrestricted estimators of the coefficients of the transformed focus regressors.

gammaUn2

If keepUn = TRUE, contains the unrestricted estimators of the coefficients of the transformed auxiliary regressors.

fitted.values

Estimated conditional means of the data.

residuals

Residuals, i.e. response - fitted mean.

X1names

Names of the focus regressors.

X2names

Names of the auxiliary regressors.

k1

Number of focus regressors.

k2

Number of auxiliary regressors.

n

Number of observations.

condition

Condition number of the matrix \Xi = \Delta_{2} X_{2}^{\top} M_{1} X_{2} \Delta_{2}.

References

\insertAllCited

See Also

wals, walsGLM.

Examples

X <- model.matrix(gdpgrowth ~ lgdp60 + equipinv + school60 + life60 + popgrowth
                  + law + tropics + avelf + confucian, data = GrowthMPP)
X1 <- X[, c("(Intercept)", "lgdp60", "equipinv", "school60", "life60", "popgrowth")]
X2 <- X[, c("law", "tropics", "avelf", "confucian")]
y <- GrowthMPP$gdpgrowth

walsFit(X1, X2, y, prior = weibull(), method = "svd")


WALS documentation built on June 22, 2024, 9:42 a.m.

Related to walsFit in WALS...