How to merge Predicted individual factor scores with data frame when predicted scores are less than total observations in the original data frame?
My data frame has 10077 observations, when I run sem(), it takes into account 9745 observations. Hence, when I use lavPredict() to predict individual factor scores, there are 9745 predicted factor scores. Then, I cannot merge such 9745 scores to the 10077 obs data frame.
Here is my code:
> ctrl.labor <- "
control_labor =~ lincome+lwh+njob+skill
lincome ~~lwh
control_labor~ urbanrate+lhincome+spland_hec+owing+poor+manu_mine+uti+construction+lowser+hiser+lm1ac5+ lf_prov14+og_gov+og_busi+og_coop+og_pri+og_fdi
lincome+lwh+njob~m1ac2+major+migrated++ttnt+married+manu_mine+uti+construction+lowser+hiser+og_gov+og_busi+og_coop+og_pri+og_fdi+spland_hec
skill~lm1ac5+m1ac2+major+ttnt+married"
> fit.l <- sem(ctrl.labor, data=x180108_lkh)
> summary(fit.l, fit.measures=TRUE)
lavaan (0.5-23.1097) converged normally after 177 iterations
Used Total
Number of observations 9745 10077
Estimator DWLS Robust
Minimum Function Test Statistic 431.108 439.811
Degrees of freedom 19 19
P-value (Chi-square) 0.000 0.000
Scaling correction factor 0.982
Shift parameter 0.605
for simple second-order correction (Mplus variant)
******omitted result*******
I use two ways to merge predicted values:
#This one has this error:
> newData <- cbind(x180108_lkh, lavPredict(fit.l))
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 10077, 9745
# This one has another error:
> factorscores <- do.call(rbind, predict(fit.l, newdata = x180108_lkh))
Error in do.call(rbind, predict(fit.l, newdata = x180108_lkh)) :
second argument must be a list
I think, overall, there is a mismatch between 10077-observations dataframe and 9745-predicted values.
Thank you very much,
Dai