Skip to content

Commit

Permalink
add use="pairwise.complete.obs" in cov() when computing unbiased Gamma
Browse files Browse the repository at this point in the history
  • Loading branch information
yrosseel committed Jun 28, 2024
1 parent 73ecb27 commit 3da5327
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: lavaan
Title: Latent Variable Analysis
Version: 0.6-19.2150
Version: 0.6-19.2168
Authors@R: c(person(given = "Yves", family = "Rosseel",
role = c("aut", "cre"),
email = "Yves.Rosseel@UGent.be",
Expand Down
3 changes: 2 additions & 1 deletion R/lav_samplestats_gamma.R
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ lav_samplestats_Gamma <- function(Y, # Y+X if cond!
gettext("unbiased Gamma only available for the simple
(not conditional.x or fixed.x or model-based or clustered) setting."))
} else {
COV <- COV.unbiased <- cov(Y)
# data really should be complete
COV <- COV.unbiased <- stats::cov(Y, use = "pairwise.complete.obs")
COV <- COV * (N - 1) / N
cov.vech <- lav_matrix_vech(COV)
}
Expand Down
12 changes: 6 additions & 6 deletions R/lav_test_LRT.R
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ lav_test_lrt_single_model <- function(object, method = "default",
aic <- c(NA, AIC(object))
bic <- c(NA, BIC(object))
}

## determine which @test element
tn <- names(object@test)
if (length(tn) == 1L) {
TEST <- 1L # only choice

## More than 1. Cycle through possible user specifications:
} else if (method[1] == "standard") {
TEST <- 1L
Expand Down Expand Up @@ -521,14 +521,14 @@ lav_test_lrt_single_model <- function(object, method = "default",
if (!is.null(object@test[[TEST]]$shift.parameter)) {
attr(val, "shift") <- c(NA, object@test[[TEST]]$shift.parameter)
}

## heading
if (grepl(pattern = "browne", x = TEST)) {
attr(val, "heading") <- object@test[[TEST]]$label

} else if (TEST == 1L) {
attr(val, "heading") <- "Chi-Squared Test Statistic (unscaled)\n"

} else {
LABEL <- object@test[[TEST]]$label
attr(val, "heading") <- paste0("Chi-Squared Test Statistic (scaled",
Expand All @@ -538,7 +538,7 @@ lav_test_lrt_single_model <- function(object, method = "default",
yes = "\n", no = paste("\n ", LABEL)),
"\n")
}

class(val) <- c("anova", class(val))

val
Expand Down
4 changes: 2 additions & 2 deletions R/lav_test_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ lav_test_diff_SatorraBentler2001 <- function(m1, m0, test = 2) {
T1 <- m1@test[[1]]$stat
r1 <- m1@test[[1]]$df
c1 <- m1@test[[test]]$scaling.factor

## check for situations when scaling.factor would be NA
if (r1 == 0) {
## saturated model
c1 <- 1 # canceled out by 0 when calculating "cd"

} else if (r1 > 0 && isTRUE(all.equal(T1, 0))) {
## perfect fit
c1 <- 0 # cancels out r1 when calculating "cd"
Expand Down

0 comments on commit 3da5327

Please sign in to comment.