group_by_groups {semhelpinghands} | R Documentation |
Group Estimates By Groups
Description
Groups parameter estimates or other information such as p-values into a table with groups as columns and parameters as rows.
Usage
group_by_groups(
object,
...,
col_names = "est",
group_first = TRUE,
group_labels = NULL,
fit = NULL,
use_standardizedSolution = FALSE
)
Arguments
object |
A lavaan object
or the output of
|
... |
Optional arguments to be
passed to
|
col_names |
A vector of the
column names in the parameter
estimate tables to be included.
Default is |
group_first |
If |
group_labels |
A character
vector of group labels. Will be
assigned to group id = 1, 2, 3, etc.
If not provided. will try to be
retrieved from |
fit |
Optional. A
lavaan::lavaan object.
If |
use_standardizedSolution |
If |
Value
A data-frame-like object of
the class est_table
.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Examples
library(lavaan)
set.seed(5478374)
n <- 100
x <- runif(n) - .5
m <- .40 * x + rnorm(n, 0, sqrt(1 - .40))
y <- .30 * m + rnorm(n, 0, sqrt(1 - .30))
city <- sample(c("City Alpha", "City Beta"), 100,
replace = TRUE)
dat <- data.frame(x = x, y = y, m = m, city = city)
model <-
'
m ~ c(a1, a2)*x
y ~ c(b1, b2)*m
a1b1 := a1*b1
a2b2 := a2*b2
'
fit <- sem(model, data = dat, fixed.x = FALSE,
group = "city")
(est <- parameterEstimates(fit))
# Group them by groups
group_by_groups(fit)
# Can also work on a parameter estimates table
# To have group labels, need to supply the fit object
group_by_groups(est, fit = fit)
# Can be used with some other functions in semhelpinghands
# when used on a parameter estimates table
group_by_groups(filter_by(est, op = "~"), fit = fit)
# Also support piping
est |> filter_by(op = "~") |>
group_by_groups(fit = fit)