View source: R/clusterRobustSE.R
| clusterRobustSE | R Documentation |
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().
clusterRobustSE(model, cluster, details = FALSE, smallSample = FALSE)
model |
A fitted, single-level |
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 |
smallSample |
If |
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.
A named vector of standard errors, or a list when
details=TRUE. The cov element is the full covariance matrix.
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/ss/1028905886")}
imxRobustSE, imxRowGradients,
sem
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.