it is highly impornat that I link the factor scores back to the the correct 'participant-IDs'. I utilized the following code to predict the factor scores.
#FactorScores <- predict(fit_Model)
However lavaan calculates 1218 facor scores and I have 1403 participants in my data set.
modelVarNames <- fit_Model@pta$vnames$ovallAreMissing <- apply(originalData[ , modelVarNames], 1, function(x) all(is.na(x)) )myData <- originalData[ !allAreMissing , ]
myData <- myData[ order(myData$groupVariable) , ]fit_Model <- lavaan(...)FactorScores <- do.call(rbind, predict(fit_Model, newdata = myData))myData <- cbind(myData, FactorScores)
allAreMissing <- apply(originalData[ , modelVarNames], 1, function(x) all(is.na(x)))
Error in .subset(x, j) : invalid subscript type 'list'I unfortunately get the following error message:
allAreMissing <- apply(originalData[ , modelVarNames], 1, function(x) all(is.na(x))) Error in .subset(x, j) : invalid subscript type 'list'
By the way I fortunately do not have multiple groups. But I think that I cannot use FIML because I need to use WLSMV and for na.rm = fiml you need a ML estimation approach (as far as I know), is that correct?
Everything in the pta$vnames slot can be extracted using the lavNames() function.
Yves.
There were 50 or more warnings (use warnings() to see the first 501: In pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method = optim.method, ... : lavaan WARNING: empty cell(s) in bivariate table of B_data.t3_friend_i2c x B_data.t3_friend_i1c
Could you please help me check the codes? What can I do to improve them?
mydata <- HolzingerSwineford1939[ , paste0("x", 1:9)]
mydata$situation <- HolzingerSwineford1939$school
set.seed(12345)
mydata$x5 <- ifelse(mydata$x5 <= quantile(mydata$x5, .3), NA, mydata$x5)
age <- HolzingerSwineford1939$ageyr + HolzingerSwineford1939$agemo/12
mydata$x9 <- ifelse(age <= quantile(age, .3), NA, mydata$x9)
## specify CFA model from lavaan's ?cfa help page
q1.model <- '
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9
'
q1model.fit <- sem(q1.model, data=mydata,missing='fiml', group = "situation")
factorm <- lavNames(q1model.fit, "ov")
allaremissing <- apply(mydata[ , factorm], 1, function(x) all (is.na(x)))
ndata <- mydata[ !allaremissing , ]
ndata <- ndata[ order(ndata$situation) , ]
q1model.fit <- sem(q1.model, data = ndata, missing = 'fiml', group = "situation")
factorscores <- do.call(rbind, predict(q1model.fit, newdata = ndata))
newdata <- cbind(ndata, factorscores)
dim(ndata)
dim(factorscores)
head(ndata)
head(factorscores)--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/E4NPoUiKsks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+unsubscribe@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.