sort_by {semhelpinghands} | R Documentation |
Sort a Parameter Estimates Table
Description
Sort a parameter
estimates table or a similar table
inlavaan
by common fields such as
op
(operator) and lhs
(left-
hand side).
Usage
sort_by(
object,
by = c("op", "lhs", "rhs"),
op_priority = c("=~", "~", "~~", ":=", "~1", "|", "~*~"),
number_rows = TRUE
)
Arguments
object |
The output of
|
by |
A character vector of the
columns for filtering. Default
is |
op_priority |
How rows are
sorted by |
number_rows |
Whether the row
names will be set to row numbers
after sorting if the row names
of |
Details
This functions accepts the
output of
lavaan::parameterEstimates()
and
lavaan::standardizedSolution()
and
filter the rows by commonly used
field.
Value
The sorted version of the input object.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
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)
out <- group_by_models(list(no_direct = fit1,
direct = fit2),
col_names = c("est", "pvalue"))
out
sort_by(out)
sort_by(out, op_priority = c("~", ":="))
sort_by(out, by = c("op", "rhs"))