Multi level SEM - not sure what I'm doing!

95 views
Skip to first unread message

Robert Udale

unread,
Jun 29, 2019, 11:51:05 AM6/29/19
to lavaan
Hello,

I have some data from an online questionnaire.  The participants are from 31 different countries. 

I would like to fit a multi-level model with two levels: subject responses (level 1) and subject country (level 2).  

"country_sample" is the column in the data which tells us which country the participant is from (coded 1-31). 

The code is: 


# Define a multi level model. 
model <- '

Level: 1

        # Latent variables (=~)

        injunctive_norm_general =~    Q36_1 + Q37_1
        descriptive_norm_general =~   Q38_1 + Q39_1
        personal_norm_general =~      Q53_1 + Q54_1

        # Regressions (~)

        Q63_1 ~ injunctive_norm_general + descriptive_norm_general + personal_norm_general
        personal_norm_general ~ injunctive_norm_general + descriptive_norm_general
        injunctive_norm_general ~ Q35_1
        descriptive_norm_general ~ Q35_1

        # Residual correlations (~~)

        Q36_1 ~ Q38_1
        Q36_1 ~ Q39_1
        Q37_1 ~ Q38_1
        Q37_1 ~ Q39_1

Level: 2

      # Latent variables (=~)

        injunctive_norm_general =~    Q36_1 + Q37_1
        descriptive_norm_general =~   Q38_1 + Q39_1
        personal_norm_general =~      Q53_1 + Q54_1

        # Regressions (~)

        Q63_1 ~ injunctive_norm_general + descriptive_norm_general + personal_norm_general
        personal_norm_general ~ injunctive_norm_general + descriptive_norm_general
        injunctive_norm_general ~ Q35_1
        descriptive_norm_general ~ Q35_1

        # Residual correlations (~~)

        Q36_1 ~ Q38_1
        Q36_1 ~ Q39_1
        Q37_1 ~ Q38_1
        Q37_1 ~ Q39_1

'

# Fit the model.
fit = sem(model = model, data = data, cluster = "country_sample")

# View the results of the model.
summary(fit)

  1. When looking at demos and tutorials online, there is usually a different model in level 1 than level 2.  Here I have the same model in each level.  Is this the right thing to do?
  2. The script is able to run completely, but I get a number of warning messages (see below).  
  3. When looking at the by typing summary(fit) all of the Std error values are replaced with 'NA'.  

I have a feeling 2 and 3 are somehow related, but because I am very new to this type of analysis, I can't see the wood for the trees!

The warning messages are: 

Warning messages:
1: In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  :
  lavaan WARNING:
    Could not compute standard errors! The information matrix could
    not be inverted. This may be a symptom that the model is not
    identified.
2: In lav_object_post_check(object) :
  lavaan WARNING: some estimated ov variances are negative
3: In lav_object_post_check(object) :
  lavaan WARNING: some estimated lv variances are negative
4: In lavaan::lavaan(model = model, data = data, cluster = "country_sample",  :
  lavaan WARNING: not all elements of the gradient are (near) zero;
                  the optimizer may not have found a local solution;
                  use lavInspect(fit, "optim.gradient") to investigate







Terrence Jorgensen

unread,
Jun 29, 2019, 2:54:45 PM6/29/19
to lavaan
  1. When looking at demos and tutorials online, there is usually a different model in level 1 than level 2.  Here I have the same model in each level.  Is this the right thing to do?
That's fine, if that's your theory.

I have a feeling 2 and 3 are somehow related

They are.  Your factors all have 2 indicators, so your model will only be empirically identified if factor correlations are substantially nonzero.  They are involved in regressions, so this is not straight-forward to check, but if you have some near-zero (even negative) lv variances, then the covariances are probably also close to zero.  Try fixing both loadings to 1 for 2-indicator factors so that the model is more likely to be empirically identified.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Robert Udale

unread,
Jul 1, 2019, 9:57:24 AM7/1/19
to lavaan
Hi Terrence, 

Thanks for your help here.  After talking to collaborators, I realised that having the same model at both levels didn't in fact make any sense. 

Instead, I have been asked to impliment these two models:

Model 1: A 'simple' model with only one level, with factor loadings fixed to one for all two-indicator factors. This model defines some latent variables and regressions. 
 
Model 2: A slightly more complex multi-level version of model 1.  The first level of model 2 is the same as model 1.  Level 2 defines one factor (comprised of two indicators), and a regression between that factor and another observed variable. The second level clustering is the participant's country. 

The code for the two models is : 

Model 1: 

model <- '

        # Latent variables (=~)

        injunctive_norm_general =~    1 * Q36_1 + 1 * Q37_1
        descriptive_norm_general =~   1 * Q38_1 + 1 * Q39_1
        personal_norm_general =~      1 * Q53_1 + 1 * Q54_1

        # Regressions (~)

        Q63_1 ~ injunctive_norm_general + descriptive_norm_general + personal_norm_general
        personal_norm_general ~ injunctive_norm_general + descriptive_norm_general
        injunctive_norm_general ~ Q35_1
        descriptive_norm_general ~ Q35_1

'

Model 2: 

model <- '
        level: 1
        
        # Latent variables (=~)

        injunctive_norm_general =~    1 * Q36_1 + 1 * Q37_1
        descriptive_norm_general =~   1 * Q38_1 + 1 * Q39_1
        personal_norm_general =~      1 * Q53_1 + 1 * Q54_1

        # Regressions (~)

        Q63_1 ~ injunctive_norm_general + descriptive_norm_general + personal_norm_general
        personal_norm_general ~ injunctive_norm_general + descriptive_norm_general
        injunctive_norm_general ~ Q35_1
        descriptive_norm_general ~ Q35_1

        level: 2
        
        # Latent variable
        personal_norm_general =~     1 *  Q53_1 + 1 * Q54_1
        
        # Regression
        personal_norm_general ~ Q63_1
        
'

# Fit the model.
fit = sem(model = model, data = data, cluster = "country_sample")


Model 1 works.  However, model 2 doesn't seem to be able to coverge on a solution: 

Warning message:
In lavaan::lavaan(model = model, data = data, cluster = "country_sample",  :
  lavaan WARNING: the optimizer warns that a solution has NOT been found!

What could be some likely causes of this problem?

Terrence Jorgensen

unread,
Jul 2, 2019, 4:20:55 AM7/2/19
to lavaan
The first level of model 2 is the same as model 1. 

No, Q63_1 has switch from being an outcome at the individual level to being a predictor at the aggregate/country level (seems strange, is that based on theory?).  Also, you have left out 4 indicators of 2 other factors that were in the level-1 model (those still have level-2 components, you need to do something with them, even if the 4 indicator's cluster means just correlate with the other level-2 components).
Reply all
Reply to author
Forward
0 new messages