Schmid-Leiman Transformation

107 views
Skip to first unread message

Pierre-Charles Soulié

unread,
Sep 26, 2024, 5:38:24 AM9/26/24
to lavaan
Hello everyone,

I am trying to run a Schmid-Leiman Transformation on lavaan. I used the hereunder syntax. I got an error message in which: (a) variables are labelled "V" and not "X" as I specified and (b) 18 variables are mentioned contrary to my syntax and dataset where there are 9 variables. Can anyone help me with these problems ? Thanks in advance.

> mod <- 'F1 =~ x1 + x2 + x3 

+         F2 =~ x4 + x5 + x6

+         F3 =~ x7 + x8 + x9

+         g =~ F1 + F2 + F3'

> fit <- lavaan::cfa(mod, sample.cov = test_models$baseline$cormat,

+                    sample.nobs = 500, estimator = "ml")


found:  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 

expected:  x1 x2 x3 x4 x5 x6 x7 x8 x9 

Error: lavaan->lav_samplestats_from_moments(): 

   rownames of covariance matrix do not match the model! found: ("V1", "V2", "V3", "V4", "V5", "V6", 

   "V7", "V8", "V9", "V10", "V11", "V12", "V13", "V14", "V15", "V16", "V17", "V18") expected: ("x1",

   "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9")

Edward Rigdon

unread,
Sep 26, 2024, 6:01:06 AM9/26/24
to lav...@googlegroups.com
The error message is saying that variable names in your data do not match those in your model syntax. Take a look at your data.

--
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/a58df4cc-90a5-477b-8b67-37edb175a7adn%40googlegroups.com.

Pierre-Charles Soulié

unread,
Sep 26, 2024, 3:01:33 PM9/26/24
to lavaan
Hello, 

Thank you for your reply but there is something that is not clear for me.

For simplicity I took the holzinger and swineford example as I have the same number of observed variables but I used my data with 9 observed variables called "x1" to "x9" and read from excel.

There is something that I do not understand : before trying to run an SL transformation I ran a model fit on the same model and everything went well. Then with SL I got the following message. How is it possible ?

model_sec<-'

visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9
ho =~ 1*visual+textual+speed    
visual+textual ~~ 0*speed
visual ~~ 0*textual
'

## Fit the second-order model
fit_second_order <- cfa(model_sec, data = BFAC)
summary(fit_second_order, fit.measures =TRUE, standardized = TRUE)

fit <- lavaan::cfa(model_sec, sample.cov = test_models$baseline$cormat,

                   sample.nobs = 500, estimator = "ml")

SL_lav <- SL(fit, g_name = "ho")


Found:  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 

expected:  x1 x2 x3 x4 x5 x6 x7 x8 x9 

Error: lavaan->lav_samplestats_from_moments(): 

   rownames of covariance matrix do not match the model! found: ("V1", "V2", "V3", "V4", "V5", "V6", 

   "V7", "V8", "V9", "V10", "V11", "V12", "V13", "V14", "V15", "V16", "V17", "V18") expected: ("x1",

   "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9")

Edward Rigdon

unread,
Sep 26, 2024, 3:06:37 PM9/26/24
to lav...@googlegroups.com
The two CFA() function calls are not reading the same data frame. Focus on what is happening, not what should have happened. Apply str() or summary() to what you are reading in each case.

Pierre-Charles Soulié

unread,
Oct 13, 2024, 3:41:03 AM10/13/24
to lavaan

Dear Professor Rigdon, 

 

Thank you very much for helpful reply.

 

Unfortunately, there is something that I still do not understand.

 

If I understand properly, one can’t specify the model in the same way given one do not use the same data frame.

 

More precisely one can’t specify 9 observed variables (in this case, one got an error message (below)) but one need to specify 18 observed variables for a model with 9 observed variables given that it does not read the same data frame. 

 

In this case, however, I do not understand how to interpret the results given I have twice more observed variables.

 

Could you please, give further explanations?

 

Thank you very much.

 

Pierre-Charles 


> # Create and fit model in lavaan (assume all variables have SDs of 1)

> mod <- 'F1 =~ V1 + V2 + V3 

+         F2 =~ V4 + V5 + V6

+         F3 =~ V7 + V8 + V9 

+         g =~ F1 + F2 + F3'

> fit <- lavaan::cfa(mod, sample.cov = test_models$baseline$cormat,

+                    sample.nobs = 500, estimator = "ml")

Warning message:

lavaan->lav_object_post_check():  

   some estimated lv variances are negative 

> SL_lav <- SL(fit, g_name = "g")

Warning message:

In sqrt(std_sol$psi[col_names, col_names]) : NaNs produced

Edward Rigdon

unread,
Oct 13, 2024, 10:17:32 AM10/13/24
to lav...@googlegroups.com
You can certainly select 9 variables out of an 18 variable data set--lavaan does this very well, ignoring variables in your dataset that are not named in model syntax.
You could also add the additional 9 variables to your model--you just need to include them in your model syntax.
The warning message you received about negative latent variable variances might be partly due to a data reading error, oir it might just indicate that the factor model is a poor fit to your data.
I am not familiar with the SL() function. Is that part of the lavaan package?


Christian Arnold

unread,
Oct 13, 2024, 3:07:31 PM10/13/24
to lav...@googlegroups.com
Sorry if I'm interfering here. Isn't it simply that 
 test_models$baseline$cormat is not the correct covariance matrix?

From: lav...@googlegroups.com <lav...@googlegroups.com> on behalf of Edward Rigdon <edward...@gmail.com>
Sent: Sunday, October 13, 2024 4:17:18 PM
To: lav...@googlegroups.com <lav...@googlegroups.com>
Subject: Re: Schmid-Leiman Transformation
 

Pierre-Charles Soulié

unread,
Oct 15, 2024, 7:32:32 AM10/15/24
to lavaan
Dear all,

Reply to Professor Rigdon:

The SL is a part of EFA TOOLs package. With the same package and with one common part of the syntax you can compute Omegas.

mod <- 'F1 =~ V1 + V2 + V3 + V4 + V5 + V6 F2 =~ V7 + V8 + V9 + V10 + V11 + V12 F3 =~ V13 + V14 + V15 + V16 + V17 + V18 g =~ F1 + F2 + F3' fit_ho <- lavaan::cfa(mod, sample.cov = test_models$baseline$cormat, sample.nobs = 500, estimator = "ml") # Compute omegas and additional indices for second-order solution OMEGA(fit_ho, g_name = "g")

The problem is that I have only 9 observed variables in my dataset and when I specify 9 observed variables I have the the error message presented before whereas when I specify 18 observed variables I have no error message.

Reply to Christian Arnold :

What do you mean by not the correct covariance matrix ?


Christian Arnold

unread,
Oct 15, 2024, 9:38:28 AM10/15/24
to lavaan
Taken from your very first post:

'found:  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18

expected:  x1 x2 x3 x4 x5 x6 x7 x8 x9
Error: lavaan->lav_samplestats_from_moments():

rownames of covariance matrix do not match the model! found: ("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", "V12", "V13", "V14", "V15", "V16", "V17", "V18") expected: ("x1",   "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9")'


That means test_models$baseline$cormat is a covariance matrix containing V1 to V18 and not x1 to x9.

lavaan has no problem with variables that are present in the covariance matrix but not specified in the model. Specified variables that are not present in the covariance matrix are (of course) a problem:


pop.model <- "
F1 =~ 1 * x1 + 1 * x2 + 1 * x3
F2 =~ 1 * x4 + 1 * x5 + 1 * x6
F3 =~ 1 * x7 + 1 * x8 + 1 * x9
g =~  0.6 * F1 + 0.6 * F2 + 0.6 * F3
F4 =~ 1 * V1 + 1 * V2 + 1 * V3 + 1 * V4 + 1 * V5 + 1 * V6 + 1 * V7 + 1 * V8 + 1 * V9 +
      1 * V10 + 1 * V11 + 1 * V12 + 1 * V13 + 1 * V14 + 1 * V15 + 1 * V16 + 1 * V17 + 1 * V18
"

data <- simulateData(pop.model, sample.nobs = 500)

model <- "

F1 =~ x1 + x2 + x3
F2 =~ x4 + x5 + x6
F3 =~ x7 + x8 + x9
g =~ F1 + F2 + F3
"

# Too many variables
fit <- sem(model, sample.cov = cov(data), sample.nobs = 500)


# Exactly the required variables
data.x.var <- data[, paste0("x", seq(1 : 9))]
fit <- sem(model, sample.cov = cov(data.x.var), sample.nobs = 500)


# Wrong variables
data.V.var <- data[, paste0("V", seq(1 : 18))]
fit <- sem(model, sample.cov = cov(data.V.var), sample.nobs = 500)

The last variant reproduces your error message:

found:  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
expected:  x1 x2 x3 x4 x5 x6 x7 x8 x9
Error in lav_samplestats_from_moments(sample.cov = sample.cov, sample.mean = sample.mean,  :
  lavaan ERROR: rownames of covariance matrix do not match the model!
  found: V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18

  expected: x1 x2 x3 x4 x5 x6 x7 x8 x9
Reply all
Reply to author
Forward
0 new messages