From a54bd290bc3884d0000c52c1b29bc557825d9eae Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 15 Dec 2022 14:50:28 +0100 Subject: List random effects correlations in output if any Update docs --- R/intervals.R | 8 ++++++-- R/summary.saem.mmkin.R | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'R') diff --git a/R/intervals.R b/R/intervals.R index 705ef6eb..fcdbaea9 100644 --- a/R/intervals.R +++ b/R/intervals.R @@ -78,8 +78,12 @@ intervals.saem.mmkin <- function(object, level = 0.95, backtransform = TRUE, ... # Random effects sdnames <- intersect(rownames(conf.int), paste("SD", pnames, sep = ".")) - ranef_ret <- as.matrix(conf.int[sdnames, c("lower", "est.", "upper")]) - rownames(ranef_ret) <- paste0(gsub("SD\\.", "sd(", sdnames), ")") + corrnames <- grep("^Corr.", rownames(conf.int), value = TRUE) + ranef_ret <- as.matrix(conf.int[c(sdnames, corrnames), c("lower", "est.", "upper")]) + sdnames_ret <- paste0(gsub("SD\\.", "sd(", sdnames), ")") + corrnames_ret <- gsub("Corr\\.(.*)\\.(.*)", "corr(\\1,\\2)", corrnames) + rownames(ranef_ret) <- c(sdnames_ret, corrnames_ret) + attr(ranef_ret, "label") <- "Random effects:" diff --git a/R/summary.saem.mmkin.R b/R/summary.saem.mmkin.R index 46ab548b..49b02a50 100644 --- a/R/summary.saem.mmkin.R +++ b/R/summary.saem.mmkin.R @@ -75,10 +75,21 @@ #' f_saem_dfop_sfo <- saem(f_mmkin_dfop_sfo) #' print(f_saem_dfop_sfo) #' illparms(f_saem_dfop_sfo) -#' f_saem_dfop_sfo_2 <- update(f_saem_dfop_sfo, covariance.model = diag(c(0, 0, 1, 1, 1, 0))) +#' f_saem_dfop_sfo_2 <- update(f_saem_dfop_sfo, +#' no_random_effect = c("parent_0", "log_k_m1")) #' illparms(f_saem_dfop_sfo_2) #' intervals(f_saem_dfop_sfo_2) #' summary(f_saem_dfop_sfo_2, data = TRUE) +#' # Add a correlation between random effects of g and k2 +#' cov_model_3 <- f_saem_dfop_sfo_2$so@model@covariance.model +#' cov_model_3["log_k2", "g_qlogis"] <- 1 +#' cov_model_3["g_qlogis", "log_k2"] <- 1 +#' f_saem_dfop_sfo_3 <- update(f_saem_dfop_sfo, +#' covariance.model = cov_model_3) +#' intervals(f_saem_dfop_sfo_3) +#' # The correlation does not improve the fit judged by AIC and BIC, although +#' # the likelihood is higher with the additional parameter +#' anova(f_saem_dfop_sfo, f_saem_dfop_sfo_2, f_saem_dfop_sfo_3) #' } #' #' @export @@ -150,7 +161,8 @@ summary.saem.mmkin <- function(object, data = FALSE, verbose = FALSE, distimes = # Random effects sdnames <- intersect(rownames(conf.int), paste0("SD.", pnames)) - confint_ranef <- as.matrix(conf.int[sdnames, c("estimate", "lower", "upper")]) + corrnames <- grep("^Corr.", rownames(conf.int), value = TRUE) + confint_ranef <- as.matrix(conf.int[c(sdnames, corrnames), c("estimate", "lower", "upper")]) colnames(confint_ranef)[1] <- "est." # Error model -- cgit v1.2.1