Skip to content

Commit

Permalink
update_test_custom_h1() sets scaled.shifted=FALSE when test="mean.var…
Browse files Browse the repository at this point in the history
….adjusted"
  • Loading branch information
TDJorgensen committed Jun 19, 2024
1 parent 936bb23 commit b3a961e
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions R/lav_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ lav_update_test_custom_h1 <- function(lav_obj_h0, lav_obj_h1) {
testNames1 <- names(lav_obj_h1@test)
testNames <- intersect(testNames0, testNames1)

copyScaled <- FALSE # in case scaled test is NA (when standard == 0)
# copyScaled <- FALSE # in case scaled test is NA (when standard == 0)

## loop over those tests
for (tn in testNames) {
Expand All @@ -736,20 +736,21 @@ lav_update_test_custom_h1 <- function(lav_obj_h0, lav_obj_h1) {
lrtCall$method <- "mean.var.adjusted.PLRT"
} else {
lrtCall$method <- "satorra.2000"
if (tn == "mean.var.adjusted") lrtCall$scaled.shifted <- FALSE
}
lrtCall$scaled.shifted <- tn == "scaled.shifted"
} else if (tn %in% c("satorra.bentler",
"yuan.bentler","yuan.bentler.mplus")) {
lrtCall$test <- tn

## is LRT even necessary?
noScaledStat <- is.na(lav_obj_h1@test[[tn]]$stat)
noScalingFactor <- is.na(lav_obj_h1@test[[tn]]$scaling.factor)
perfectFit <- isTRUE( all.equal(lav_obj_h1@test$standard$stat, 0) )

if (perfectFit && (noScaledStat || noScalingFactor)) {
copyScaled <- TRUE
}
# noScaledStat <- is.na(lav_obj_h0@test[[tn]]$stat)
# noScalingFactor <- is.na(lav_obj_h0@test[[tn]]$scaling.factor)
# perfectFit <- isTRUE( all.equal(lav_obj_h0@test$standard$stat, 0) )
#
# if (perfectFit && (noScaledStat || noScalingFactor)) {
# copyScaled <- TRUE
# }

} else if (grepl(pattern = "browne", x = tn)) {
lrtCall$type <- tn
Expand All @@ -760,17 +761,18 @@ lav_update_test_custom_h1 <- function(lav_obj_h0, lav_obj_h1) {
}

## get new test
if (tn %in% c("satorra.bentler", "yuan.bentler", "yuan.bentler.mplus")
&& copyScaled) {
## Don't run lavTestLRT(). Keep existing H0 test stat to avoid error.
## But adjust df
newTEST[[tn]]$df <- newTEST[[tn]]$df - lav_obj_h1@test[[tn]]$df
## for RMSEA, reverse-engineer $trace.UGamma from $scaling.factor & new df
newTEST[[tn]]$trace.UGamma <- newTEST[[tn]]$df * newTEST[[tn]]$scaling.factor
## skip the rest of this loop
next

} else if (lav_obj_h0@test[[1]]$df == lav_obj_h1@test[[1]]$df) {
# if (tn %in% c("satorra.bentler", "yuan.bentler", "yuan.bentler.mplus")
# && copyScaled) {
# ## Don't run lavTestLRT(). Keep existing H0 test stat to avoid error.
# ## But adjust df
# newTEST[[tn]]$df <- lav_obj_h0@test[[tn]]$df - lav_obj_h1@test[[tn]]$df
# ## for RMSEA, reverse-engineer $trace.UGamma from $scaling.factor & new df
# newTEST[[tn]]$trace.UGamma <- newTEST[[tn]]$df * newTEST[[tn]]$scaling.factor
# ## skip the rest of this loop
# next
#
# } else
if (lav_obj_h0@test[[1]]$df == lav_obj_h1@test[[1]]$df) {
## suppress warning about == df
ANOVA <- suppressWarnings(eval(as.call(lrtCall)))
} else {
Expand Down

0 comments on commit b3a961e

Please sign in to comment.