Dear All,
Good morning.
May I ask a question about 'how to compute factor scores using Lavaan package'?
I tried lavPredict() which supports a model with numeric and ordinal items, but I got an error message.
When I dropped "ordered", with treating all items numeric, I did not get any error message (from lavPredict) but this is not a correct model...
# data and code
# There are 12 items, x1-x3, x10-x12 are count items, x4-x9 are ordinal.
# This is a part of my code:
model.choi <- ' # freely estimate loading of the first item
# measurement model
F =~ NA*x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12
F ~~ 1*F
# fit the model
# THEMATRIX is a data.frame which is of a dimension 1600 x 12.
mod.free.seme = sem(model.choi , data=THEMATRIX, ordered=colnames(THEMATRIX)[4:9], missing = "pairwise")
# compuate factor scores
lavPredict(mod.free.sem)
# end of code
I got the warnings as I run sem(): (I put warnings and errors in color for convenience of reading)
Warning messages:
1: In lav_data_full(data = data, group = group, cluster = cluster, :
lavaan WARNING: some cases are empty and will be ignored:
1494
2: In lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, :
lavaan WARNING: 5 bivariate tables have empty cells; to see them, use:
lavInspect(fit, "zero.cell.tables")
and I ended up with an error message when I tried lavPredict.
Error in EETAx[[g]][i, , drop = FALSE] : subscript out of bounds
I used traceback() to follow the error lines, and found that the error(s) was(were) caused from internal function(s).
> traceback()
3: lav_predict_eta_ebm(lavobject = lavobject, lavmodel = lavmodel,
lavdata = lavdata, lavsamplestats = lavsamplestats, data.obs = data.obs,
eXo = eXo, optim.method = optim.method)
2: lav_predict_eta(lavobject = NULL, lavmodel = lavmodel, lavdata = lavdata,
lavsamplestats = lavsamplestats, lavimplied = lavimplied,
data.obs = data.obs, eXo = eXo, method = method, fsm = fsm,
optim.method = optim.method)
1: lavPredict(mod.free.sem)
May these errors be coming from the situation of sparseness and/or skewness of ordinal items?
I appreciate your comment/help/advice!!
Sincerely,
Seo-Eun