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 lavaan::parameterEstimates(), lavaan::standardizedSolution(), or a lavaan.data.frame object. May also work on an est_table-class object returned by functions like group_by_dvs() but there is no guarantee.

by

A character vector of the columns for filtering. Default is c("op", "lhs", "rhs").

op_priority

How rows are sorted by op. Default is c("=~", "~", "~~", ":=", "~1", "|", "~*~"). Can set only a few of the operators, e.g., c("~", "~~"). Other operators will be placed to the end with orders not changed.

number_rows

Whether the row names will be set to row numbers after sorting if the row names of object is equal to row numbers. Default is TRUE.

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"))



[Package semhelpinghands version 0.1.11 Index]