Skip to content

Commit

Permalink
separate inits for blocks of psi and for individual entries of psi
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmerkle committed Jan 1, 2024
1 parent 5b71179 commit 76222f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 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.1208
Version: 0.5-2.1209
Authors@R: c(person(given = "Edgar", family = "Merkle",
role = c("aut", "cre"),
email = "[email protected]",
Expand Down
30 changes: 11 additions & 19 deletions R/lav_export_stanmarg.R
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,23 @@ lav2stanmarg <- function(lavobject, dp, n.chains, inits, wiggle=NULL, wiggle.sd=
frnums <- sapply(frnoblock, function(x) as.numeric(x[x != 0]))
twsel <- lavpartable$free %in% frnums
tmpwig <- lavpartable[twsel,'free'][which(lavpartable[twsel, 'plabel'] %in% wig)]

res <- matattr(frnoblock, es, constrain, mat = "Psi_r", Ng, opts$std.lv, tmpwig,
free1 = free2$lambda, free2 = lyfree2, sign = dat$lam_y_sign,
dest = dest)

dat$Psi_r_skeleton <- res$matskel
dat$w10skel <- res$wskel
dat$psi_r_sign <- res$sign
#free2 <- c(free2, list(rpsi = res$free))
#ptrows <- with(lavpartable, which(mat == "psi" & free > 0 & row != col))
#veclen <- length(ptrows)
#if (veclen > 0) {
# fpars <- res$wskel[1:veclen,1] == 0 | res$wskel[1:veclen,3] == 1
# nfree <- c(nfree, list(sum(fpars)))
# names(nfree)[length(nfree)] <- 'lvrho'
# freeparnums[ptrows[fpars]] <- 1:sum(fpars)
#}
free2 <- c(free2, list(rpsi = res$free))
ptrows <- with(lavpartable[twsel, , drop = FALSE], which(mat == "psi" & free > 0 & row != col))
veclen <- length(ptrows)
if (veclen > 0) {
fpars <- res$wskel[1:veclen,1] == 0 | res$wskel[1:veclen,3] == 1
nfree <- c(nfree, list(sum(fpars)))
names(nfree)[length(nfree)] <- 'lvrho'
freeparnums[ptrows[fpars]] <- 1:sum(fpars)
}

## repeated for all free cov entries including blocks
frnums <- sapply(fr, function(x) as.numeric(x[x != 0]))
Expand All @@ -639,15 +639,6 @@ lav2stanmarg <- function(lavobject, dp, n.chains, inits, wiggle=NULL, wiggle.sd=
dat$Psi_r_skeleton_f <- res$matskel
dat$w11skel <- res$wskel
dat$psi_r_sign_f <- res$sign
free2 <- c(free2, list(rpsi = res$free))
ptrows <- with(lavpartable, which(mat == "psi" & free > 0 & row != col))
veclen <- length(ptrows)
if (veclen > 0) {
fpars <- res$wskel[1:veclen,1] == 0 | res$wskel[1:veclen,3] == 1
nfree <- c(nfree, list(sum(fpars)))
names(nfree)[length(nfree)] <- 'lvrho'
freeparnums[ptrows[fpars]] <- 1:sum(fpars)
}
} else {
blkpsi <- TRUE
dat$Psi_r_skeleton <- array(0, dim = c(Ng, 0, 0))
Expand Down Expand Up @@ -818,6 +809,7 @@ lav2stanmarg <- function(lavobject, dp, n.chains, inits, wiggle=NULL, wiggle.sd=
}

## add inits (manipulate partable to re-use set_inits_stan)
## TODO inits for blocks
lavpartable$freeparnums <- freeparnums

## FIXME theta_x, cov.x not handled
Expand Down

0 comments on commit 76222f6

Please sign in to comment.