From 66a5e6c9915bbb6f1bfd3773ecf0971b00349d35 Mon Sep 17 00:00:00 2001 From: Haziq Jamil Date: Thu, 30 May 2024 16:38:24 +0300 Subject: [PATCH] A better way of doing things --- R/21-rgeneric_cached.R | 24 ++++++++++++------------ R/30-inlavaan.R | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/R/21-rgeneric_cached.R b/R/21-rgeneric_cached.R index aca1ff5..960d803 100644 --- a/R/21-rgeneric_cached.R +++ b/R/21-rgeneric_cached.R @@ -111,24 +111,24 @@ inla_sem_cached <- function( # Theta matrix diag(Theta) <- params$sd_e ^ 2 if (length(idx_rho) > 0) { - for (k in seq_len(nrow(RHO_IDX))) { - i <- RHO_IDX[k, 1] - j <- RHO_IDX[k, 2] - Theta[i, j] <- Theta[j, i] <- - params$rho[k] * params$sd_e[i] * params$sd_e[j] - } + I <- RHO_IDX[, 1] + J <- RHO_IDX[, 2] + values <- params$rho * params$sd_e[I] * params$sd_e[J] + Theta[cbind(I, J)] <- values + Theta[cbind(J, I)] <- values + Theta <- force_pd(Theta) # force pd } # Psi matrix diag(Psi) <- params$sd_z ^ 2 if (length(idx_lvrho) > 0) { - for (k in seq_len(nrow(LVRHO_IDX))) { - i <- LVRHO_IDX[k, 1] - j <- LVRHO_IDX[k, 2] - Psi[i, j] <- Psi[j, i] <- - params$lvrho[k] * params$sd_z[i] * params$sd_z[j] - } + I <- LVRHO_IDX[, 1] + J <- LVRHO_IDX[, 2] + values <- params$lvrho * params$sd_z[I] * params$sd_z[J] + Psi[cbind(I, J)] <- values + Psi[cbind(J, I)] <- values + Psi <- force_pd(Psi) # force pd } diff --git a/R/30-inlavaan.R b/R/30-inlavaan.R index 6fcc749..4c06cab 100644 --- a/R/30-inlavaan.R +++ b/R/30-inlavaan.R @@ -1271,7 +1271,6 @@ inlavaan <- function( out } - #' Title #' #' @param ... TBC