-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bifactor analysis #73
base: master
Are you sure you want to change the base?
Conversation
…, resolved discrepancy with resultsfrom psych omegaFromSem
What a nice idea! I would make one top-down suggestion at this point, before getting into the details of the code, and that is to try to follow the Smaller notes:
|
I have removed
The syntax to add a cross-loading is a mistake-prone for an end-user because the defaults of bf %>% add_paths("a =~ c_2", "", std.lv = T,
auto.fix.single = T,
auto.fix.first = F,
orthogonal = T,
int.ov.free = F,
int.lv.free = F,
meanstructure = F) %>% run_lavaan() -> bf_fit2
|
…egative loadings and cross_loading elimination logic
bf %>% add_paths("a =~ c_2", "", std.lv = T, Not sure what the problem is... are you trying to prevent model non-identification by fixing variances of indicators that load on too many factors? |
Lines 63 to 75 in 9ada1d7
The issue is that without any parameters to add_paths, it makes the cross-loading fixed at value 1, and estimates an intercept. I don't want either: latent variables have fixed variance 1, and no intercepts should be estimated (fixed to 0). tidy_sem(c("a_1", "a_2", "a_3", "b_1", "b_2", "b_3", "c_1", "c_2", "c_3", "c_4")) %>%
bifactor() %>%
# This adds a cross-loading
add_paths("a =~ c_4") %>%
as_lavaan() %>%
filter(lhs == "c_4" | rhs == "c_4")
# lhs op rhs block group free label ustart plabel
# 1 G =~ c_4 1 1 1 NA .p10.
# 2 c =~ c_4 1 1 1 NA .p20.
# 3 c_4 ~~ c_4 1 1 1 NA .p30.
# 4 c_4 ~1 1 1 0 0 .p50.
# 5 a =~ c_4 1 1 0 1 .p55. The options to add_paths.tidy_sem_bifactor <- function() {
cl <- match.call()
cl["int.ov.free"] <- FALSE
cl["auto.fix.first"] <- FALSE
# Copy pasted from add_paths.tidy_sem
cl["model"] <- list(model$syntax)
# I have to comment this line though otherwise R complains
# about a missing implementation for group_var for the tidy_sem_bifactor class.
# I don't need it anyways.
# if(!is.null(group_var(model))) cl[["ngroups"]] <- group_var(model, "ngroups")
cl[[1L]] <- quote(add_paths)
#Args <- c(list(model = model$syntax), as.list(match.call()[-c(1:2)]))
model$syntax <- eval.parent(cl)
return(model)
} |
Maybe I am using Should I maybe change Semi-related point: I can tweak tidy_sem$syntax to include an equality constraint by specifying |
As per standard lavaan syntax, to specify equality constraints you could use:
I need to plan in some time to look into the issue you're experiencing with add_paths, can't speak to that now. The risk of implicit defaults (as in your add_paths.tidy_sem_bifactor solution) is that, as soon as someone has a different use case than you had in mind, they break down (ironically, this might be happening to you; I have to investigate to see). I agree that manually specifying these arguments to add_paths is awkward, but at least it's explicit! |
PS The .p1. labels are, to my understanding, intended as lavaan internals. |
Haha yes it is happening to me. Yea so reimplementing some of the logic in Regarding equality constraints. Thanks for the quick reply, I was trying to do it all manually by adding rows to the syntax data.frame. I understand now that I can do: add_paths(tidy_sem(x), "F=~a*x_1; F=~a*x_2; F=~a*x_3") And that runs with mx and lavaan. Nice! That helps. I was trying to do There is no need right now for you to invest time in reading this all. I will redesign the bifactor a little based on code you wrote for Tests already work, I can reproduce results from the So after this is done and I factor out tidyverse usage, I will press the request review button :) |
That sounds good, thank you for being proactive and understanding! Don't forget to add yourself as "ctb" to the authors@R field in the DESCRIPTION file too. |
I see you're making a commit here as well.. would you like me to incorporate this into 0.2.7 as well? If so: it still needs tests for the new functions, and I see that it's failing (for some reason) the integration tests. Would you please make sure that these functions align as closely as possible to the interface of functions like |
The implementation is not entirely complete because I ran into this unsolved issue #74 The mentioned issue is preventing me from imposing equality constraints in the case when a latent variable has only two indicators. |
I can't get into this until after end March due to time constraints! |
No problem! |
This PR is a Proof of Concept. I would like to receive feedback on how to better integrate this with the tidySEM framework.
EDIT: finished