# 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)
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 negative3: In lav_object_post_check(object) : lavaan WARNING: some estimated lv variances are negative4: 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
- 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?
I have a feeling 2 and 3 are somehow related
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 <- ' 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")
Warning message:
In lavaan::lavaan(model = model, data = data, cluster = "country_sample", :
lavaan WARNING: the optimizer warns that a solution has NOT been found!
The first level of model 2 is the same as model 1.