| record_history {semhelpinghands} | R Documentation |
Record the Minimization History
Description
Record the minimization
history when a model is fitted by
lavaan::lavaan() or its wrappers
(e.g., lavaan::sem() or
lavaan::cfa()).
Usage
record_history(object)
## S3 method for class 'fit_history'
plot(x, params, last_n = -1, orientation = c("horizontal", "vertical"), ...)
## S3 method for class 'fit_history'
print(x, n_iterations = 10, digits = 3, ...)
Arguments
object |
A lavaan object. |
x |
A |
params |
A character vector of
the names of parameters to be
plotted. Must be the names of one or
more columns in |
last_n |
The lass |
orientation |
The orientation of
the plot. Either |
... |
Optional arguments. To be passed to the print method of data frame. |
n_iterations |
The number of iterations to print. Default is 10, printing the first 10 iterations (or all iterations, if the number of iterations is less than 10). |
digits |
The number of digits to be displayed. Default is 3. |
Details
It records the minimization
history when a model is fitted by
lavaan::lavaan() or its wrappers
(e.g., lavaan::sem() or
lavaan::cfa()). The recorded
history can then be plotted or
displayed, for visualizing how the
estimates of free parameters is
found.
It will refit the model by the
update method of
lavaan::lavaan, setting se = "none" and test = "standard"
because they have no impact on the
minimization process.
This and related functions are
adapted from the package semunpack.
The version in this package will be
revised to be an advanced version
intended for diagnostic purpose in
real studies.
Value
A fit_history-class object
with a plot method
(plot.fit_history()).
Functions
-
plot(fit_history): The plot method for the output ofrecord_history(). -
print(fit_history): The print method for the output ofrecord_history().
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Examples
# Adapted from the example for CFA in lavaan::cfa().
# Using only two of the factors
library(lavaan)
HS.model <-
'
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
'
fit <- cfa(HS.model, data = HolzingerSwineford1939)
# Refit the model with the history recorded
fit_h <- record_history(fit)
fit_h
# Plot the history for selected parameters
plot(fit_h, params = c("visual=~x2", "visual=~x3",
"visual~~textual"),
last_n = 10)
plot(fit_h, params = c("visual=~x2", "visual=~x3",
"visual~~textual"),
last_n = 10,
orientation = "vertical")