Learn R Programming

metaSEM (version 2.0)

clusterRobustSE: Cluster-robust covariance for a single-level OpenMx model

Description

Calculates a sandwich covariance from per-row derivatives of the log likelihood, summed within independent clusters. The model is not refitted. This function is for single-level raw-data maximum-likelihood models, including flat multiple-group models; relational two-level models use the separate cluster-score calculation in vcov.mxsem().

Usage

clusterRobustSE(model, cluster, details = FALSE, smallSample = FALSE)

Value

A named vector of standard errors, or a list when details=TRUE. The cov element is the full covariance matrix.

Arguments

model

A fitted, single-level MxModel with raw data and a maximum-likelihood fit function.

cluster

A vector of cluster identifiers in the same order as the model's data rows, or a single character string naming a column in the model's raw data. For a multiple-group model, a vector follows the order of the contributing submodels, and a named column is taken from the data of each of them. An ID that appears in more than one group is one cluster.

details

If TRUE, return a list containing the covariance, standard errors, bread, meat (including the correction factor), cluster count, and correction factor applied to the meat. Otherwise return the standard errors.

smallSample

If TRUE, also multiply the meat by (N-1)/(N-p), where N is the number of rows and p the number of free parameters, so that the total factor is G/(G-1) * (N-1)/(N-p). This conventional correction is optional and is not a general solution for inference with few clusters. p counts all free parameters, including those determined by equality constraints or estimated at a bound, so the factor is slightly larger than with the number of parameters that are actually free to vary.

Details

The method follows OpenMx's imxRobustSE() by Michael D. Hunter. Row derivatives are computed by central differences of the row likelihoods returned by OpenMx, which needs \(2p+1\) model evaluations regardless of the number of rows; OpenMx::imxRowGradients() is used if the row likelihoods cannot be evaluated this way. No OpenMx source code is copied. OpenMx's original R/MxRobustSE.R is distributed under the Apache License, Version 2.0.

The meat is multiplied by \(G/(G-1)\), where \(G\) is the number of clusters. With one row per cluster, this is OpenMx's observation-level factor \(N/(N-1)\), so the result equals that of imxRobustSE(). The bread is the inverse of the observed information. The result matches lavaan's cluster-robust standard errors of single-group models (se="robust.huber.white" with cluster=) when lavaan also uses the observed information (information="observed"). lavaan's default for cluster= is the expected information, which gives the same result for complete data and saturated models but can differ otherwise. With data missing at random, the expected information can make the standard errors much too small, and the observed information is the appropriate choice (Kenward & Molenberghs, 1998).

Parameters estimated at a binding lower or upper bound have no valid sandwich covariance. Their rows and columns are NA, with a warning, and the covariance of the remaining parameters treats them as fixed, while respecting equality constraints and binding inequality constraints. A bound or an inequality constraint binds if the estimates would move past it without it: the Newton step of -2LL under the other binding constraints would violate it by more than 0.001 of its standard error. An estimate that is merely close to a bound or to the boundary of an inequality is not restricted by it and has the usual covariance. A warning is also given when the OpenMx status code is neither 0 nor 1, because the fit may not have converged.

For models with mxConstraints, the bread is not taken from OpenMx, whose covariance for these models can be wrong. It is computed from the Hessian of the Lagrangian, i.e., a numerical Hessian of -2LL without the constraints minus the curvature of nonlinear constraints weighted by their Lagrange multipliers, restricted to the null space of the binding constraints (all equality constraints and the binding inequality constraints). This equals the covariance of the same model with the constraints substituted into it. A warning is given if the gradient of -2LL is not orthogonal to these constraints, because the fit may then not be at a constrained optimum.

References

OpenMx Project, R/MxRobustSE.R: https://github.com/OpenMx/OpenMx/blob/master/R/MxRobustSE.R.

Kenward, M. G., & Molenberghs, G. (1998). Likelihood based frequentist inference when data are missing at random. Statistical Science, 13(3), 236--247. tools:::Rd_expr_doi("10.1214/ss/1028905886")

See Also

imxRobustSE, imxRowGradients, sem

Examples

Run this code
# \donttest{
set.seed(1)
id <- rep(seq_len(20), each=5)
d <- data.frame(id=id, x=rnorm(100), y=rnorm(100))
ram <- lavaan2RAM("y ~ b*x", obs.variables=c("y", "x"))
fit <- sem(RAM=ram, data=d, cluster="id")
clusterRobustSE(fit$mx.fit, cluster="id")
vcov(fit, robust=TRUE)
# }

Run the code above in your browser using DataLab