Vuong Test with Lavaan Object

81 views
Skip to first unread message

drsco...@gmail.com

unread,
Apr 4, 2022, 2:36:28 AM4/4/22
to lavaan
Good morning,

Is anyone familiar with the package nonnest2? I'm trying to compare two sem() models using the vuongtest(fit.1, fit.2) and am getting the following error. Does anyone know what that means?

> vuongtest(fit.1, fit.2)

Error in Score.mat[wi, ] <- -scores.H1 %*% Delta :
  number of items to replace is not a multiple of replacement length

CODE:

model.1 <-  ' Y ~ x1 + x2 + x3 + x4 + x5 + x6'

model.2 <-  ' Y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7'

fit.1 <- sem(model.1, df, missing = "fiml")

fit.2 <- sem(model.2, df, missing = "fiml")

Mauricio Garnier-Villarreal

unread,
Apr 4, 2022, 5:15:52 AM4/4/22
to lavaan
Both models have to have the same items. Cant test adding x7

could do

model.1 <-  ' Y ~ x1 + x2 + x3 + x4 + x5 + x6 + 0*x7 '

model.2 <-  ' Y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7'

drsco...@gmail.com

unread,
Apr 4, 2022, 11:05:09 AM4/4/22
to lavaan
Good morning.

I tried 

model.1 <-  ' Y ~ x1 + x2 + x3 + x4 + x5 + x6 + 0*x7 '

model.2 <-  ' Y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7'

but am still getting the error

Error in Score.mat[wi, ] <- -scores.H1 %*% Delta :
  number of items to replace is not a multiple of replacement length

Christian Arnold

unread,
Apr 6, 2022, 8:02:20 AM4/6/22
to lav...@googlegroups.com
The problem is probably related to missing data:

library(lavaan)
library(nonnest2)

# Simulate data
m.pop <- "Y ~ 1 * x1 + 0.9 * x2 + 0.9 * x3 + 0.8 * x4 + 0.9 * x5 + 0.8 * x6 + 0.9 * x7"

set.seed(1)
df <- simulateData(m.pop, sample.nobs = 1000)

m1 <- "Y ~ x1 + x2 + x3 + x4 + x5 + x6"
m2 <- "Y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7"

fit1 <- sem(m1, df)
fit2 <- sem(m2, df)

# Run Vuong test ---- works fine
vuongtest(fit1, fit2)


# Quick and dirty delete some data
deleteData <- function(df, missings, rows, cols) {
  del <- list(
    rows = floor(runif(missings, min = 1, max = rows)),
    cols = floor(runif(missings, min = 1, max = cols))
  )
  for(m in 1 : missings) df[del$rows[m], del$cols[m]] <- NA
  return(df)
}
df <- deleteData(df, 200, nrow(df), ncol(df))

fit1 <- sem(m1, df, missing = "fiml")
fit2 <- sem(m2, df, missing = "fiml")

# Run xuong test ---- Error in Score.mat[wi, ]
vuongtest(fit1, fit2)

As you can see, the Vuong test works fine without missing data (apart from the warning message). You could try to delete all rows with missing data from your data frame.



--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/1585a0d5-1ff5-4881-93c8-e19f9f217bc4n%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages