Skip to content

Commit

Permalink
fix blavCompare() for meanstructure = FALSE
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmerkle committed Oct 6, 2023
1 parent b801cc8 commit 9bf1257
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 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-2
Version: 0.5-2.1183
Authors@R: c(person(given = "Edgar", family = "Merkle",
role = c("aut", "cre"),
email = "[email protected]",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
## New features
* This is a maintenance release, primarily adding the new array declaration syntax in Stan models (syntax that became available in the new version of rstan).

## Bugs/glitches discovered after the release:
* blavCompare() does not work with models that have meanstructure = FALSE (reported by Pedro Ribeiro).

# Version 0.5-1
## New features
* Two-level models are now supported (for complete, continuous data) via the cluster argument.
Expand Down
23 changes: 17 additions & 6 deletions R/blav_compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ blavCompare <- function(object1, object2, ...) {
res <- c(bf, object1@test[[1]]$stat, object2@test[[1]]$stat)
names(res) <- c("bf", "mll1", "mll2")

## FIXME? We already get case_lls in blav_fit_measures and should really
## only do it once. But, if we store it in the blavaan object, the size
## of that object can get much larger.
if(targ1 == "stan"){
if(targ1 == "stan" && blavInspect(object1, "meanstructure")){
ll1 <- loo::extract_log_lik(object1@external$mcmcout)
} else if(blavInspect(object1, "categorical") && lavopt1$test != "none"){
if("llnsamp" %in% names(lavopt)){
cat("blavaan NOTE: These criteria involve likelihood approximations that may be imprecise.\n",
"You could try running the model again to see how much the criteria fluctuate.\n",
"You can also manually set llnsamp for greater accuracy (but also greater runtime).\n\n")
}
ll1 <- object1@external$casells
} else {
lavopt1$estimator <- "ML"
ll1 <- case_lls(object1@external$mcmcout, make_mcmc(object1@external$mcmcout),
Expand All @@ -29,13 +33,20 @@ blavCompare <- function(object1, object2, ...) {
cid1 <- rep(1:nchain1, each=niter1)
ref1 <- relative_eff(exp(ll1), chain_id = cid1)

if(targ2 == "stan"){
if(targ2 == "stan" && blavInspect(object2, "meanstructure")){
ll2 <- loo::extract_log_lik(object2@external$mcmcout)
} else if(blavInspect(object2, "categorical") && lavopt2$test != "none"){
if("llnsamp" %in% names(lavopt)){
cat("blavaan NOTE: These criteria involve likelihood approximations that may be imprecise.\n",
"You could try running the model again to see how much the criteria fluctuate.\n",
"You can also manually set llnsamp for greater accuracy (but also greater runtime).\n\n")
}
ll2 <- object2@external$casells
} else {
lavopt2$estimator <- "ML"
ll2 <- case_lls(object2@external$mcmcout, make_mcmc(object2@external$mcmcout),
object2)
}
}
nchain2 <- blavInspect(object1, "n.chains")
niter2 <- nrow(ll2)/nchain2
cid2 <- rep(1:nchain2, each=niter2)
Expand Down

0 comments on commit 9bf1257

Please sign in to comment.