walsFit {WALS}R 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 Magnus and De Luca (2016). 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 De Luca and Magnus (2011) 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 Huynh (2024b) for more details. The latter is used in the original MATLAB code for WALS in the linear regression model (Magnus et al. 2010; De Luca and Magnus 2011; Kumar and Magnus 2013; Magnus and De Luca 2016), see eq. (12) of Magnus and De Luca (2016). The first form is required in eq. (9) of De Luca et al. (2018). 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

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.

De Luca G, Magnus JR, Peracchi F (2018). “Weighted-average least squares estimation of generalized linear models.” Journal of Econometrics, 204(1), 1–17. doi:10.1016/j.jeconom.2017.12.007.

Huynh K (2024b). “WALS: Weighted-Average Least Squares Model Averaging in R.” University of Basel. Mimeo.

Kumar K, Magnus JR (2013). “A characterization of Bayesian robustness for a normal location parameter.” Sankhya B, 75(2), 216–237. doi:10.1007/s13571-013-0060-9.

Magnus JR, De Luca G (2016). “Weighted-average least squares (WALS): A survey.” Journal of Economic Surveys, 30(1), 117-148. doi:10.1111/joes.12094.

Magnus JR, Powell O, Prüfer P (2010). “A comparison of two model averaging techniques with an application to growth empirics.” Journal of Econometrics, 154(2), 139-153. doi:10.1016/j.jeconom.2009.07.004.

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")


[Package WALS version 0.2.5 Index]