| lavH1 | R Documentation |
Compute only the summary statistics of the unrestricted (H1) model: the
saturated mean vector and variance-covariance matrix (and thresholds, if
some variables are ordered) that normally end up in the @h1 slot
of a fitted lavaan object. Unlike sem or cfa,
no model is needed. If a model is provided anyway, it is only used to
determine the relevant variables, their role (exogenous, ordered,
per level, ...) and the data-related options, so that the result is
exactly the h1 information a fit of that model would use.
If the data are incomplete and missing = "ml" (fiml), the summary
statistics are the EM estimates of the saturated model; this is a
convenient way to obtain fiml estimates of standard descriptive
statistics. For multilevel data (using the cluster argument),
the within- and between-level summary statistics (and the intraclass
correlations) are computed.
lavH1(model = NULL, data = NULL, ordered = NULL, sampling_weights = NULL,
group = NULL, cluster = NULL, missing = "default",
ov_names_x = NULL, ov_names_l = list(),
estimator = "default", se = "default", test = "none", ...,
output = "list", wls_v = NULL, gamma = NULL, add_extra = TRUE,
add_labels = TRUE, add_class = TRUE, drop_list_single_group = TRUE)
model |
Optional. Either a description of the user-specified model
(as in |
data |
A |
ordered |
Character vector declaring additional variables as ordered
(ordinal). Variables that are declared as ordered factors in the data
frame are always treated as ordinal. If |
sampling_weights |
A variable name in the data frame containing sampling weight information. |
group |
A variable name in the data frame defining the groups in a multiple group analysis. |
cluster |
A variable name in the data frame defining the clusters in a two-level dataset. |
missing |
How to handle missing data. If |
ov_names_x |
Character vector. Variables that need to be treated as exogenous. Only used if no model is provided. |
ov_names_l |
List. Only used for two-level data when no model is provided: the variable names per level. By default, all variables are used at both levels. |
estimator |
The estimator (see |
se |
Only used if |
test |
Only used if |
... |
Optional parameters that are passed to the
|
output |
Character. If |
wls_v |
Logical. If |
gamma |
Logical. If |
add_extra |
Logical. If |
add_labels |
Logical. If |
add_class |
Logical. If |
drop_list_single_group |
Logical. If |
If output = "list" (the default), a list with the h1 summary
statistics (see the output argument above). If
output = "lavaan", a fitted lavaan object for
the unrestricted model; its summary() shows the standard errors,
Wald (z) statistics and p-values of the summary statistics (for
example, to flag significant correlations when
correlation = TRUE). The object may also serve as an ingredient
for two-stage estimation procedures. If output = "lavMoments", an
object of class lavMoments that can be passed directly as the
data= argument of lavaan/cfa/sem.
A lavMoments object reproduces the original raw-data fit
exactly for the estimators whose estimates, standard errors and
test statistics are functions of the summary statistics only. This
includes maximum likelihood ("ML") and generalized least squares
("GLS"); the robust variants ("MLM", "MLMV",
"MLMVS", ... and the Satorra-Bentler / scaled-shifted /
mean-variance-adjusted tests), provided the gamma (nacov)
matrix is requested (gamma = TRUE); the diagonally weighted least
squares estimators for ordered data ("WLSMV", "WLSM",
"DWLS", ..., which include wls_v and nacov by
default); and two-stage maximum likelihood for incomplete continuous data
(missing = "two.stage" or "robust.two.stage").
For the estimators whose weight matrix is estimator-specific (for
example the identity weight of the "ULS" family, or the ADF weight
of continuous "WLS"), pass the SAME estimator to
lavH1() as will be used in the refit, so that the matching
wls_v is returned.
A raw-data fit cannot be reproduced from summary statistics when the
standard errors or test statistic depend on the individual cases: the
Huber-White ('robust') sandwich ("MLR", se =
"robust.huber.white"), the first-order/outer-product information
("MLF"), cluster-robust (cluster =) standard errors, the
bootstrap (se = "bootstrap"), pairwise maximum likelihood
("PML"), and direct full-information maximum likelihood for
incomplete data (missing = "ml"; use missing = "two.stage"
instead).
lavCor for (polychoric, polyserial and Pearson)
correlations (which uses the same machinery), and
lavInspect with what = "h1" to extract the h1
summary statistics from a fitted lavaan object.
# saturated summary statistics of the Holzinger & Swineford data
lavH1(HolzingerSwineford1939[, paste0("x", 1:9)])
# fiml (EM) estimates of the descriptive statistics with missing data
HS.missing <- HolzingerSwineford1939
HS.missing$x5[1:10] <- NA
lavH1(HS.missing[, paste0("x", 1:9)], missing = "ml")
# a model is accepted, but only determines the variables and options
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
h1 <- lavH1(HS.model, data = HolzingerSwineford1939, group = "school")
# the unrestricted model as a fitted lavaan object; summary() shows the
# standard errors, z-statistics and p-values of the summary statistics
fit.h1 <- lavH1(HolzingerSwineford1939[, paste0("x", 1:9)],
output = "lavaan")
summary(fit.h1)
# which correlations are significant?
fit.cor <- lavH1(HolzingerSwineford1939[, paste0("x", 1:9)],
output = "lavaan", correlation = TRUE)
summary(fit.cor)
# categorical data: extract all summary statistics (including wls_v and
# nacov), then (re)fit a model from the summary statistics only
Data <- HolzingerSwineford1939[, paste0("x", 1:9)]
Data[] <- lapply(Data, cut, breaks = 3, labels = FALSE)
Data[] <- lapply(Data, ordered)
model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
moments <- lavH1(model, data = Data, output = "lavMoments")
moments
fit <- cfa(model, data = moments) # identical to cfa(model, data = Data)
# two-stage ML for incomplete (continuous) data: the EM saturated moments
# plus the stage-1 nacov allow a moments-only refit to reproduce the exact
# two-stage estimates, standard errors and (scaled) test statistics
HS.incomplete <- HolzingerSwineford1939[, paste0("x", 1:9)]
HS.incomplete$x1[1:20] <- HS.incomplete$x5[15:40] <- NA
model2 <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6 '
moments2 <- lavH1(model2, data = HS.incomplete, missing = "two.stage",
output = "lavMoments")
fit2 <- cfa(model2, data = moments2)
# same as: cfa(model2, data = HS.incomplete, missing = "two.stage")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.