prettylavaan | R Documentation |
Results from lavaan
get messed up when summary()
is called within a for
loop within an R Markdown chunk with the option results = "asis"
.
This function is an alternative to summary()
that can print out a pretty output in such situations.
prettylavaan(
fitobj,
output_format = "asis",
robust = FALSE,
modindice.nrow = 10,
param.type = c("=~", "~~", "~"),
dp = 3,
align = "c",
multigroup = FALSE,
show.modind = FALSE,
...
)
fitobj |
A lavaan fit object. |
output_format |
Output format, default is "asis" for use with |
robust |
Defaults to |
modindice.nrow |
Defaults to 10. Number of rows to display for modification indices. |
param.type |
Defaults to only show path coefficients (~), factor loadings (=~) and covariances (~~). Use (|) for thresholds if WLS estimators were used. |
dp |
Defaults to 3. Number of decimal points for all numeric values. |
align |
Defaults to "c", which stands for centered. Adjusts the alignment of text within table cells. Works the same way as |
multigroup |
Defaults to FALSE. Set to |
show.modind |
Defaults to FALSE. Set to |
... |
Additional arguments passed onto |
library(lavaan)
# the famous Holzinger and Swineford (1939) example
HS.model <- "visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9"
fit <- cfa(HS.model, data = HolzingerSwineford1939)
prettylavaan(fit, output_format = "datatable")
# using robust estimators
robustfit <- cfa(HS.model, data = HolzingerSwineford1939, estimator = "MLM")
prettylavaan(robustfit, output_format = "datatable")
# request for robust fit indices
prettylavaan(robustfit, output_format = "datatable", robust = TRUE)
# multigroup
mfit <- cfa(HS.model, data = HolzingerSwineford1939, estimator = "MLM", group = "sex")
prettylavaan(mfit, robust = TRUE, multigroup = TRUE)
# for piping to kableExtra for further editing
# note: library(kableExtra) may mess up formatting of normal kable tables in the same Rmd document
# refer to https://github.com/haozhu233/kableExtra/issues/265
# format = "html" is required to work with kableExtra
library(kableExtra)
mylist <- prettylavaan(robustfit, output_format = "kableExtra", format = "html", robust = TRUE)
mylist$Param %>% kable_styling(font_size = 9)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.