From d0525df8e1c15f4ce20b63d0cddd9182b681181d Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 13 Nov 2023 13:22:25 +0000 Subject: [PATCH] only generate samples if any params aren't natural --- R/dist.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/R/dist.R b/R/dist.R index 7530ae480..9cb27cb6c 100644 --- a/R/dist.R +++ b/R/dist.R @@ -1597,17 +1597,24 @@ process_dist <- function(params, lower_bounds, distribution) { stop("Parameter ", x, " must be numeric or normally distributed.") } }) + unnatural_params <- setdiff(names(params), natural_params(distribution)) + if (length(unnatural_params) > 0) { + ## sample parameters if they are uncertain samples <- lapply(names(params), function(x) { rtruncnorm( n = 2000, a = lower_bounds[x], mean = mean(params[[x]]), sd = sd(params[[x]]) ) }) + names(samples) <- names(params) + ## generate natural parameters + converted_params <- convert_to_natural(samples, distribution) + } else { + converted_params <- list( + params_mean = vapply(params, mean, numeric(1), USE.NAMES = FALSE), + params_sd = vapply(params, sd, numeric(1), USE.NAMES = FALSE) ) - }) - names(samples) <- names(params) - ## generate natural parameters - converted_params <- convert_to_natural(samples, distribution) + } dist <- dist_spec( distribution = distribution,