Skip to content

Commit 74786f6

Browse files
committed
fix .TOTAL. reliability for MG-CFA
1 parent 81879ef commit 74786f6

3 files changed

Lines changed: 23 additions & 24 deletions

File tree

semTools/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ LazyData: yes
4545
LazyLoad: yes
4646
URL: https://github.com/simsem/semTools/wiki
4747
BugReports: https://github.com/simsem/semTools/issues
48-
Date: 2026-02-09
48+
Date: 2026-02-10
4949
RoxygenNote: 7.3.3
5050
Roxygen: list(old_usage=TRUE, markdown=TRUE)

semTools/R/reliability.R

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Terrence D. Jorgensen
22
### - omegaCat() and deprecated functionality: Sunthud Pornprasertmanit
3-
### Last updated: 6 February 2026
3+
### Last updated: 10 February 2026
44

55

66

@@ -475,12 +475,6 @@ AVE <- function(object, obs.var = TRUE, omit.imps = c("no.conv","no.se"),
475475
##'
476476
##' **Multilevel Measurement Models**:
477477
##'
478-
#TODO: incorporate `W=` details:
479-
## multilevel SEMs, the syntax should include level-specific blocks,
480-
## where the same composite name can be specified at both levels to calculate
481-
## Lai's (2021) indices for observed-variable composites; otherwise, Geldhof
482-
## et al.'s (2014) indices for level-specific latent composites
483-
484478
##' How to define reliability coefficients for scales employed in nested designs
485479
##' is an ongoing topic of methodological development, with some ongoing
486480
##' controversies about best practice when the target of measurement is the
@@ -583,13 +577,13 @@ AVE <- function(object, obs.var = TRUE, omit.imps = c("no.conv","no.se"),
583577
##' (any indicator without a numeric `weight` is given a unit weight = 1).
584578
##' See **Details** and **Examples** about complicated CFAs (e.g., multilevel,
585579
##' higher-order, or bifactor).
586-
##' @param return.total Only relevant for multidimensional CFAs, this `logical`
580+
##' @param return.total For multidimensional CFAs, this `logical` value
587581
##' indicates whether to return a final index for the reliability of a
588582
##' composite of all modeled indicators (labeled `.TOTAL.`). This is redundant
589583
##' whenever there is already a common factor indicated by all items (e.g.,
590584
##' the general factor in a bifactor model). This argument is ignored when
591585
##' using the `W=` argument to specify composites (optionally with weights).
592-
##' Setting a negative value (e.g., `-1` returns **only** the `.TOTAL.`
586+
##' Setting a negative value (e.g., `-1`) returns **only** the `.TOTAL.`
593587
##' composite reliability (i.e., excluding coefficients per factor).
594588
##' @param obs.var `logical` indicating whether to compute reliability
595589
##' using observed (co)variances to compute the denominator. Setting `FALSE`
@@ -934,7 +928,6 @@ compRelSEM <- function(object, W = NULL,
934928
ngroups <- lavInspect(object, "ngroups")
935929
nLevels <- lavInspect(object, "nlevels")
936930
nblocks <- ngroups*nLevels #FIXME: always true?
937-
#FIXME: necessary in rewrite? return.total <- rep(return.total, nblocks)
938931

939932
## extract parameter table
940933
PT <- parTable(object)
@@ -975,19 +968,25 @@ compRelSEM <- function(object, W = NULL,
975968
if (return.total) {
976969
## loop over blocks to add a total score
977970
for (b in 1:nblocks) {
978-
ov.names <- lavNames(object, type = "ov.ind", block = b)
979-
ind.idx <- unique(match(wPT$rhs, table = ov.names))
980-
totalPT <- wPT[ind.idx, ]
981-
totalPT$lhs <- ".TOTAL."
982-
if (return.total < 0L) {
983-
## only for the total composite
984-
wPT <- totalPT
985-
986-
## add the total composite
987-
} else wPT <- rbind(wPT, totalPT)
988-
971+
wPTb <- wPT[wPT$block == b, ]
972+
ov.names <- lavNames(object, type = "ov.ind", block = b)
973+
ind.idx <- unique(match(wPTb$rhs, table = ov.names))
974+
totalPTb <- wPTb[ind.idx, ]
975+
totalPTb$lhs <- ".TOTAL."
976+
977+
if (b == 1L) {
978+
totalPT <- totalPTb
979+
} else totalPT <- rbind(totalPT, totalPTb)
989980
## end loop over blocks
990981
}
982+
983+
if (return.total < 0L) {
984+
## only the total composite
985+
wPT <- totalPT
986+
987+
## add the total composite
988+
} else wPT <- rbind(wPT, totalPT)
989+
991990
}
992991
## replace default integers with labels for groups
993992
if (length(group.label) && is.integer(wPT$group)) {

semTools/man/compRelSEM.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)