Skip to content

Commit

Permalink
Try choleski inverse
Browse files Browse the repository at this point in the history
  • Loading branch information
haziqj committed May 29, 2024
1 parent 1e3ed8c commit 7198854
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions R/20-rgeneric.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ inla_sem <- function(
lambda <- theta[idx_lam]
beta <- theta[idx_beta]
sd_e <- sqrt(exp(theta[idx_theta])) # sd_e = sd_e ^ 2 (item sd)
rho <- INLAvaan:::theta_to_rho(theta[idx_rho])
rho <- theta_to_rho(theta[idx_rho])
sd_z <- sqrt(exp(theta[idx_psi])) # sd_z = sd_z ^ 2 (latent sd)
lvrho <- INLAvaan:::theta_to_rho(theta[idx_lvrho])
lvrho <- theta_to_rho(theta[idx_lvrho])

list(
lambda = lambda,
Expand Down Expand Up @@ -130,8 +130,9 @@ inla_sem <- function(
front <- Lambda %*% solve(IminB)
}
Sigma <- front %*% tcrossprod(Psi, front) + Theta
# Sigma <- Sigma + diag(1e-7, nrow(Sigma)) # for stability
MASS::ginv(Sigma)
Sigma <- Sigma + diag(1e-10, nrow(Sigma)) # for stability
chol2inv(chol(Sigma))
# MASS::ginv(Sigma)
}

mu <- function() { numeric(0) }
Expand Down
3 changes: 2 additions & 1 deletion R/40-lav_export_INLA.R
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,8 @@ lav2inla <- function(
p = pta$nvar[[1]],
q = pta$nfac[[1]],
init = inlastart,
partable = partable
partable = partable,
theta_to_rho = theta_to_rho # utility function, see 10-utilities.R
# optimize = TRUE
)

Expand Down

0 comments on commit 7198854

Please sign in to comment.