Skip to content

Commit

Permalink
improve decision about when to compute mll, fixing #81
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmerkle committed Jul 25, 2024
1 parent b420569 commit eb9c76c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: blavaan
Title: Bayesian Latent Variable Analysis
Version: 0.5-5.1290
Version: 0.5-5.1291
Authors@R: c(person(given = "Edgar", family = "Merkle",
role = c("aut", "cre"),
email = "[email protected]",
Expand Down
26 changes: 25 additions & 1 deletion R/blav_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,21 @@ checkcovs <- function(lavobject){
psinums <- sapply(psis, function(x) x[lower.tri(x)])
diagpsi <- all(unlist(psinums) == 0L, na.rm = TRUE)
fullpsi <- all(unlist(psinums) > 0L, na.rm = TRUE) & (anyDuplicated(unlist(psinums), MARGIN = 0) == 0L)
## check for blocks of free covariances that have no impact on each other
psiblk <- sapply(psis, function(x) {
x[!lower.tri(x)] <- 0
frnums <- which(x > 0, arr.ind = TRUE)
if (nrow(frnums) > 0) {
blk <- !duplicated(as.numeric(frnums))
} else {
blk <- TRUE
}
blk} )
blkp <- all(psiblk)
} else {
diagpsi <- FALSE
fullpsi <- TRUE
blkp <- TRUE
}

if (nrow(free[[1]]$theta) > 0) {
Expand All @@ -420,12 +432,24 @@ checkcovs <- function(lavobject){
diagthet <- all(unlist(thetnums) == 0L, na.rm = TRUE)
## surprising if this happens:
fullthet <- all(unlist(thetnums) > 0L, na.rm = TRUE) & (anyDuplicated(unlist(thetnums), MARGIN = 0) == 0L)
## check for blocks of free covariances that have no impact on each other
thetblk <- sapply(thets, function(x) {
x[!lower.tri(x)] <- 0
frnums <- which(x > 0, arr.ind = TRUE)
if (nrow(frnums) > 0) {
blk <- !duplicated(as.numeric(frnums))
} else {
blk <- TRUE
}
blk} )
blkt <- all(thetblk)
} else {
diagthet <- FALSE
fullthet <- TRUE
blkt <- TRUE
}

list(diagpsi = diagpsi, fullpsi = fullpsi, diagthet = diagthet, fullthet = fullthet)
list(diagpsi = diagpsi, fullpsi = fullpsi, diagthet = diagthet, fullthet = fullthet, dobf = (blkp && blkt))
}

## check whether model cov matrix is block diagonal
Expand Down
21 changes: 18 additions & 3 deletions R/blavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -1037,9 +1037,24 @@ blavaan <- function(..., # default lavaan arguments
domll <- TRUE
covres <- checkcovs(LAV)
## in these cases, we cannot reliably evaluate the priors
if(ordmod | !(covres$diagthet | covres$fullthet)) domll <- FALSE
if(target == "stan" && !l2s$blkpsi) domll <- FALSE
if(target != "stan" && !(covres$diagpsi | covres$fullpsi)) domll <- FALSE
if(ordmod) domll <- FALSE
if(target == "stan") {
if(covres$dobf) {
domll <- TRUE
} else if((covres$diagthet | covres$fullthet) & l2s$blkpsi) {
domll <- TRUE
} else {
domll <- FALSE
}
} else {
if(covres$dobf) {
domll <- TRUE
} else if((covres$diagpsi | covres$fullpsi) & covres$diagthet) {
domll <- TRUE
} else {
domll <- FALSE
}
}

if(lavoptions$test != "none") { # && attr(x, "converged")) {
TEST <- blav_model_test(lavmodel = lavmodel,
Expand Down

0 comments on commit eb9c76c

Please sign in to comment.