-
Notifications
You must be signed in to change notification settings - Fork 303
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
lavaan update breaks glance.lavaan #835
Comments
Wonderful, thank you, will make these updates! |
@yrosseel Would you be willing to export |
Hm. No. Because I want to avoid adding additional package dependencies (eg tibble, dplyr, ...). |
Hello! Working through this update right now. It looks like the results from library(lavaan)
#> This is lavaan 0.6-6
#> lavaan is BETA software! Please report any bugs.
library(broom)
library(tidyverse)
cfa.fit <- cfa(
'F =~ x1 + x2 + x3 + x4 + x5',
data = HolzingerSwineford1939, group = "school"
)
# version with purrr
glance.lavaan <- function(x, ...) {
x %>%
lavaan::fitmeasures(
fit.measures =
c(
"npar",
"chisq",
"rmsea",
"rmsea.ci.upper",
"srmr",
"aic",
"bic",
"tli",
"agfi",
"cfi"
)
) %>%
tibble::enframe(name = "term") %>%
pivot_wider(id_cols = term, names_from = term, values_from = value) %>%
select(order(colnames(.))) %>%
map_df(as.numeric) %>%
bind_cols(
tibble(
converged = lavInspect(x, "converged"),
estimator = lavInspect(x, "options")$estimator,
ngroups = lavInspect(x, "ngroups"),
missing_method = lavInspect(x, "options")$missing,
nobs = sum(purrr::accumulate(lavInspect(x, "nobs"), sum)),
norig = sum(purrr::accumulate(lavInspect(x, "norig"), sum)),
nexcluded = norig - nobs
)
) %>%
rename(rmsea.conf.high = rmsea.ci.upper, AIC = aic, BIC = bic)
}
old <- glance(cfa.fit)
# version with only sum
glance.lavaan <- function(x, ...) {
x %>%
lavaan::fitmeasures(
fit.measures =
c(
"npar",
"chisq",
"rmsea",
"rmsea.ci.upper",
"srmr",
"aic",
"bic",
"tli",
"agfi",
"cfi"
)
) %>%
tibble::enframe(name = "term") %>%
pivot_wider(id_cols = term, names_from = term, values_from = value) %>%
select(order(colnames(.))) %>%
map_df(as.numeric) %>%
bind_cols(
tibble(
converged = lavInspect(x, "converged"),
estimator = lavInspect(x, "options")$estimator,
ngroups = lavInspect(x, "ngroups"),
missing_method = lavInspect(x, "options")$missing,
nobs = sum(lavInspect(x, "nobs")),
norig = sum(lavInspect(x, "norig")),
nexcluded = norig - nobs
)
) %>%
rename(rmsea.conf.high = rmsea.ci.upper, AIC = aic, BIC = bic)
}
new <- glance(cfa.fit)
old$nobs == new$nobs
#> [1] FALSE
old$norig == new$norig
#> [1] FALSE Created on 2020-05-25 by the reprex package (v0.3.0.9001) Will be pushing some changes and referencing this issue here soon.🙂 |
Thanks! The purrr::accumulate() version was always wrong. So the 'new' version is correct! |
@benwhalley, any thoughts on |
I don't think I did implement that, but it's been a while if I did. No strong views on it now! |
Gotcha! Making the switch now, thanks. |
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
The glance.lavaan() function (in R/lavaan-tidiers.R) is accessing internal slots of a fitted lavaan object to extract some information, instead of using the extractor functions. As the internal slots will change in the next update, this breaks the glance.lavaan() function.
The urgent issue is line 136
which should be replaced by
as the 'Fit' slot is going to be removed.
But I would suggest changing the whole tibble section to this:
avoiding any access to internal slots.
Finally, I don't understand why the purrr::accumulate() function is needed. I believe that what is intended is simply:
taking the sum over the (possibly multiple) groups.
Yves.
The text was updated successfully, but these errors were encountered: