I need some help with predicting values from my multigroup model. Sadly, the official lavaan tutorial (https://lavaan.ugent.be/tutorial/cov.html) isn't helpful in that regard.
My "problem" is as followed. I have data with a lot of missing values. Therefore I can't calculate a model with the dataframe itself (since lavaan would exclude most cases) and I don't want to use imputation (since the values are missing systematically). My approach was to calculate covariance matrices with the argument use = "pairwise.complete.obs"
and continue with these.
I think I used the correct procedure (passing a list with covariance matrices and a list with sample observations to the cfa
function) and fitting the model. I can then inspect the model and have a look at the coefficients etc..
However, when it comes to predicting factor scores for individual participants (with a complete dataset), I cannot simply input the raw dataframe in the newdata
argument of lavPredict
, because lavaan then has no information as to which case belongs to which group.
Is there a way to provide lavaan with the necessary group information? I tried to have a look at the source code and using lavData
or lav_data_full
might be a solution. However, how that solution looks like, I can't tell…
Thank you in advance!
Daniel
Best Answer
You mean planned missing data, using random assignment? That would make the data missing completely at random. Instead of calculating summary data yourself, just pass the
data.frame
tocfa()
and setmissing = "pairwise"
to use pairwise deletion. Then,lavPredict()
will provide factor scores for any rows with complete data.