From 7198854063f3f16a53bcbe4433441206bd3c740c Mon Sep 17 00:00:00 2001 From: Haziq Jamil Date: Wed, 29 May 2024 12:17:57 +0300 Subject: [PATCH] Try choleski inverse --- R/20-rgeneric.R | 9 +++++---- R/40-lav_export_INLA.R | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/20-rgeneric.R b/R/20-rgeneric.R index 98d19ab..d681a16 100644 --- a/R/20-rgeneric.R +++ b/R/20-rgeneric.R @@ -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, @@ -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) } diff --git a/R/40-lav_export_INLA.R b/R/40-lav_export_INLA.R index 06f0c7f..c2b2f7d 100644 --- a/R/40-lav_export_INLA.R +++ b/R/40-lav_export_INLA.R @@ -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 )