simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

reliabilityL2() cannot handle multilevel model in lavaan #74

Closed AndreasGratz closed 4 years ago

AndreasGratz commented 4 years ago

While the function reliability() can deal with a multilevel lavaan model, reliabilityL2() cannot, which, unfortunately, leaves me unable to calculate the omega-values for my second-order-latent variables.

Running reliabilityL2(model_1, "second_order_latent") in the context of the following example-model returns the error: 'Error in ve[[i]][secondFactor, secondFactor, drop = FALSE] : subscript out of bounds'

model_1 <- " level: 1 first_order_latent_A =~ item1 + item2 + item3 + item4 first_order_latent_B =~ item5 + item6 + item7 + item8 second_order_latent =~ first_order_latent_A + first_order_latent_B

level: 2 first_order_latent_A =~ ag_item1 + ag_item2 + ag_item3 + ag_item4 first_order_latent_B =~ ag_item5 + ag_item6 + ag_item7 + ag_item8 second_order_latent =~ first_order_latent_A + first_order_latent_B "

I would be very grateful indeed if this issue could be fixed so that I may conclude my research. Thank you and my best regards.

TDJorgensen commented 4 years ago

While the function reliability() can deal with a multilevel lavaan model, reliabilityL2() cannot

Are you sure? It works for me (using the latest development version: 0.5-2.922):

model <- '
    level: 1
        f1 =~ y1 + y2 + y3
        f2 =~ y4 + y5 + y6
        hi =~ 1*f1 + 1*f2
    level: 2
        f1 =~ y1 + y2 + y3
        f2 =~ y4 + y5 + y6
        hi =~ 1*f1 + 1*f2
'
fit <- sem(model, data = Demo.twolevel, cluster = "cluster")
reliability(fit)
reliabilityL2(fit, secondFactor = "hi")

Make sure your model is identified. With only 2 indicators of the higher-order factor, loadings must be equal (unless it covaries substantially with other variables in the model). If your model is identified and you still get this error with the latest version of the software (check your sessionInfo() output for the version number), please email me enough data with your script so I can see what the problem is.

AndreasGratz commented 4 years ago

This is very embarrassing indeed. I think the problem was that I named the second-order-latent at level 2 differently (agleadership instead of leadership), this did not raise any other issues in my models. My apologies for raising an issue that does not exist. If I may add one thing: I checked out the semTools documentation and the source-code and as far as I can see there is no explanation regarding the background or difference of omegaL1 and omegaL2 (and the literature they rely on).

TDJorgensen commented 4 years ago

My apologies

No worries!

there is no explanation regarding the background or difference of omegaL1 and omegaL2 (and the literature they rely on).

They are explained in the Details section of the ?reliabilityL2 help page. I do not know where Sunthud got the inspiration for designing that function, but I will try to track down some References to add to the help page (if I find any). From the descriptions in the help page, I only think L1 is meangingful, since that describes the amount of variance in a composite from the observed variables that is attributable to the higher-order factor. The other 2 indices just seem like mathematically interesting thought experiments -- my 2 cents.

TDJorgensen commented 4 years ago

FYI, I updated the documentation to be a little easier to understand, hopefully: https://github.com/simsem/semTools/commit/5af863a704b0ccca588d07048f82470cc1873180

AndreasGratz commented 4 years ago

Many thanks, this was very helpful!

TDJorgensen commented 4 years ago

For posterity, Sunthud told to me that he did not remember where he got those formulas, but that he probably came up with the ideas himself. Grad school is a tumultuous time :-)