Skip to content

Commit

Permalink
only generate samples if any params aren't natural
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Nov 13, 2023
1 parent 29dc23a commit d0525df
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions R/dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d0525df

Please sign in to comment.