summary(fit, rsq = TRUE) results in error in some model
Suppanut opened this issue · 1 comments
I came across an error message when I tried to get the R-squared for a single-outcome regression model.
See the r code:
# > data(attitude)
# > fit <- sem('rating ~ complaints + privileges', attitude)
# > summary(fit, rsquare = TRUE)
# Error in data.frame(lhs = NAMES, op = rep("r2", nel), rhs = NAMES, block = block, :
# row names contain missing values
I think this might be due to the lavTech()
function used to calculate R-squared when using the summary()
function.
# > lavTech(fit, "rsquare", add.labels = TRUE)
# $<NA>
# rating
# 0.6830639
# > lavInspect(fit, "rsquare", add.labels = TRUE)
# rating
# 0.683
It did not work on lavaan_0.6-16 and lavaan_0.6-17. However, the code excecuted propoerly on lavaan_0.6-15.
This problem only occurs in summary()
because that calls parameterEstimates()
, which yields the same error message. But the lavTech()
issue is indeed the problem. I didn't search the previous source code, but the current version tries to name a single-block (group/level) model's list, which is when it shows up as having a missing name (<NA>
). When there are multiple outcomes, unlist()
ing these results in a vector with names (e.g., "NA1","NA2", ...
), whereas unlist()
ing a length-1 vector for a single outcome yields an actual missing value (NA
) for the names, rather than a character vector. I made a little fix in one of my fork's branches, and I'll send a pull request.