Skip to content

Commit c74a3c4

Browse files
committed
recycling seed from brm call for initialisation purposes
1 parent b73ba18 commit c74a3c4

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: bayesnec
22
Title: A Bayesian No-Effect- Concentration (NEC) Algorithm
3-
Version: 2.1.0.0
3+
Version: 2.1.0.1
44
Authors@R: c(person("Rebecca", "Fisher", email = "r.fisher@aims.gov.au", role = c("aut", "cre")), person("Diego","Barneche",role="aut"), person("Gerard","Ricardo",role="aut"), person("David","Fox",role="aut"))
55
Description: Implementation of No-Effect-Concentration estimation that uses 'brms' (see Burkner (2017)<doi:10.18637/jss.v080.i01>; Burkner (2018)<doi:10.32614/RJ-2018-017>; Carpenter 'et al.' (2017)<doi:10.18637/jss.v076.i01> to fit concentration(dose)-response data using Bayesian methods for the purpose of estimating 'ECX' values, but more particularly 'NEC' (see Fox (2010)<doi:10.1016/j.ecoenv.2009.09.012>. This package expands and supersedes an original version implemented in R2jags, see Fisher, Ricardo and Fox (2020)<doi:10.5281/ZENODO.3966864>.
66
Depends:

R/helpers.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,13 @@ add_brm_defaults <- function(brm_args, model, family, predictor, response,
483483
" fitted using a ", model, " model and a ", msg_tag,
484484
" distribution."))
485485
response_link <- response_link_scale(response, family)
486+
init_seed <- NULL
487+
if ("seed" %in% names(brm_args)) {
488+
init_seed <- brm_args$seed
489+
}
486490
inits <- make_good_inits(model, predictor, response_link,
487-
priors = brm_args$prior, chains = brm_args$chains)
491+
priors = brm_args$prior, chains = brm_args$chains,
492+
seed = init_seed)
488493
if (length(inits) == 1 && "random" %in% names(inits)) {
489494
inits <- inits$random
490495
}

R/inits_functions.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,26 @@ make_inits <- function(model, fct_args, priors, chains) {
9090
#' @param y A \code{\link[base]{numeric}} vector containing the y response.
9191
#' @param n_trials A \code{\link[base]{numeric}} vector indicating
9292
#' how many attempts the function should run before giving up.
93+
#' @param seed seed number for reproducible random number generation. Defaults
94+
#' to \code{NULL}.
9395
#' @param ... Additional arguments to \code{\link{make_inits}}.
9496
#'
9597
#' @seealso \code{\link{make_inits}}
9698
#' @return A \code{\link[base]{list}} containing the initialisation values.
9799
#'
98100
#' @noRd
99-
make_good_inits <- function(model, x, y, n_trials = 1e5, ...) {
101+
make_good_inits <- function(model, x, y, n_trials = 1e5, seed = NULL, ...) {
100102
limits <- range(y, na.rm = TRUE)
101103
pred_fct <- get(paste0("pred_", model))
102104
fct_args <- names(unlist(as.list(args(pred_fct))))
103105
fct_args <- setdiff(fct_args, "x")
106+
set.seed(seed)
104107
inits <- make_inits(model, fct_args, ...)
105108
init_ranges <- lapply(inits, get_init_ranges, x, pred_fct, fct_args)
106109
are_good <- all(sapply(init_ranges, check_limits, limits))
107110
n_t <- 1
108111
while (!are_good && n_t <= n_trials) {
112+
set.seed(seed + n_t)
109113
inits <- make_inits(model, fct_args, ...)
110114
init_ranges <- lapply(inits, get_init_ranges, x, pred_fct, fct_args)
111115
are_good <- all(sapply(init_ranges, check_limits, limits))

0 commit comments

Comments
 (0)