group_by_models {semhelpinghands}R Documentation

Group Estimates By Models

Description

Groups parameter estimates or other information such as p-values into a table with models as columns.

Usage

group_by_models(
  object_list,
  ...,
  col_names = "est",
  group_first = FALSE,
  model_first = TRUE,
  use_standardizedSolution = FALSE
)

Arguments

object_list

A named list of lavaan objects, a named list of the output of lavaan::parameterEstimates(), or a named list of the output of lavaan::standardizedSolution().

...

Optional arguments to be passed to lavaan::parameterEstimates(). Ignored if the elements in object_list are the results of lavaan::parameterEstimates() or lavaan::standardizedSolution().

col_names

A vector of the column names in the parameter estimate tables to be included. Default is "est", or "est.std" if use_standardizedSolution is TRUE.

group_first

If TRUE, the rows will be grouped by groups first and then by parameters. Ignored if the model has only one group. Default is FALSE.

model_first

If TRUE, the columns will be grouped by models first and then by columns in the parameter estimates tables. Default is TRUE.

use_standardizedSolution

If TRUE and object_list is not a list of estimates tables, then lavaan::standardizedSolution() will be used to generate the table. If FALSE, the default, then lavaan::parameterEstimates() will be used if necessary.

Value

A data-frame-like object of the class est_table.

Author(s)

Shu Fai Cheung https://orcid.org/0000-0002-9871-9448 Inspired by the proposal Rönkkö posted in a GitHub https://github.com/simsem/semTools/issues/24#issue-235172313 for semTools. I want something simple for a quick overview and so I wrote this function.

Examples


library(lavaan)
set.seed(5478374)
n <- 50
x <- runif(n) - .5
m <- .40 * x + rnorm(n, 0, sqrt(1 - .40))
y <- .30 * m + rnorm(n, 0, sqrt(1 - .30))
dat <- data.frame(x = x, y = y, m = m)
model1 <-
'
m ~ a*x
y ~ b*m
ab := a*b
'
fit1 <- sem(model1, data = dat, fixed.x = FALSE)
model2 <-
'
m ~ a*x
y ~ b*m + x
ab := a*b
'
fit2 <- sem(model2, data = dat, fixed.x = FALSE)
parameterEstimates(fit1)
parameterEstimates(fit2)
group_by_models(list(no_direct = fit1,
                     direct = fit2),
                col_names = c("est", "pvalue"))
# Can also be used with some other functions in
# semhelpinghands
group_by_models(list(no_direct = fit1,
                     direct = fit2),
                col_names = c("est", "pvalue")) |>
                filter_by(op = "~")



[Package semhelpinghands version 0.1.11 Index]