Predict the values of latent variables (and their indicators).
The main purpose of the lavPredict()
function is to compute (or
‘predict’) estimated values for the latent variables in the model
(‘factor scores’). NOTE: the goal of this
function is NOT to predict future values of dependent variables as in the
regression framework!
lavPredict(object, newdata = NULL, type = "lv", method = "EBM", se = "none", acov = "none", label = TRUE, fsm = FALSE, append.data = FALSE, assemble = FALSE, level = 1L, optim.method = "bfgs", ETA = NULL)
object |
An object of class |
newdata |
An optional data.frame, containing the same variables as the data.frame used when fitting the model in object. |
type |
A character string. If |
method |
A character string. In the linear case (when the indicators are
continuous), the possible options are |
se |
Character. If |
acov |
Similar to the |
label |
Logical. If TRUE, the columns are labeled. |
fsm |
Logical. If TRUE, return the factor score matrix as an attribute. Only for numeric data. |
append.data |
Logical. Only used when |
assemble |
Logical. If TRUE, the separate multiple groups as reassembled again to form a single data.frame with a group column, having the same dimensions are the original dataset. |
level |
Integer. Only used in a multilevel SEM.
If |
optim.method |
Character string. Only used in the categorical case.
If |
ETA |
An optional matrix or list, containing latent variable values
for each observation. Used for computations when |
The predict()
function calls the lavPredict()
function
with its default options.
If there are no latent variables in the model, type = "ov"
will
simply return the values of the observed variables. Note that this function
can not be used to ‘predict’ values of dependent variables, given the
values of independent values (in the regression sense). In other words,
the structural component is completely ignored (for now).
data(HolzingerSwineford1939) ## fit model HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- cfa(HS.model, data = HolzingerSwineford1939) head(lavPredict(fit)) head(lavPredict(fit, type = "ov")) ## ------------------------------------------ ## merge factor scores to original data.frame ## ------------------------------------------ idx <- lavInspect(fit, "case.idx") fscores <- lavPredict(fit) ## loop over factors for (fs in colnames(fscores)) { HolzingerSwineford1939[idx, fs] <- fscores[ , fs] } head(HolzingerSwineford1939) ## multigroup models return a list of factor scores (one per group) data(HolzingerSwineford1939) mgfit <- update(fit, group = "school", group.equal = c("loadings","intercepts")) idx <- lavInspect(mgfit, "case.idx") # list: 1 vector per group fscores <- lavPredict(mgfit) # list: 1 matrix per group ## loop over groups and factors for (g in seq_along(fscores)) { for (fs in colnames(fscores[[g]])) { HolzingerSwineford1939[ idx[[g]], fs] <- fscores[[g]][ , fs] } } head(HolzingerSwineford1939) ## ------------------------------------- ## Use factor scores in susequent models ## ------------------------------------- ## see Examples in semTools package: ?plausibleValues
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.