Skip to content

Commit 30eb8e6

Browse files
committed
updating "inits"-->"init" argument to allow for brms and cmdstanr compatibility
1 parent 2e0b7a3 commit 30eb8e6

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

R/amend.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ amend.default <- function(object, drop, add, loo_controls, x_range = NA,
9595
if (!inherits(mod_m, "prebayesnecfit")) {
9696
brm_args <- list(
9797
family = family, iter = simdat$iter, thin = simdat$thin,
98-
warmup = simdat$warmup, inits = simdat$inits, chains = simdat$chains,
98+
warmup = simdat$warmup, init = simdat$init, chains = simdat$chains,
9999
sample_prior = simdat$sample_prior
100100
)
101101
if (missing(priors)) {

R/bayesnecfit-class.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' @slot fit The fitted Bayesian model of class \code{\link[brms]{brmsfit}}.
1818
#' @slot model A \code{\link[base]{character}} string indicating the name of
1919
#' the fitted model.
20-
#' @slot inits A \code{\link[base]{list}} containing the initialisation values
20+
#' @slot init A \code{\link[base]{list}} containing the initialisation values
2121
#' for to fit the model.
2222
#' @slot bayesnecformula An object of class \code{\link{bayesnecformula}} and
2323
#' \code{\link[stats]{formula}}.

R/extract_simdat.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
#' by \code{\link{fit_bayesnec}}.
77
#'
88
#' @return A \code{\link[base]{list}} of model simulation statistics including
9-
#' iter, thin, warmup, chains, inits and nsamples.
9+
#' iter, thin, warmup, chains, init and nsamples.
1010
#'
1111
#' @noRd
1212
extract_simdat <- function(modfit) {
1313
x <- modfit$fit$fit@sim
1414
sample_prior <- attr(modfit$fit$prior, "sample_prior")
1515
list(iter = x$iter, thin = x$thin, warmup = x$warmup, chains = x$chains,
16-
inits = modfit$fit$fit@inits, sample_prior = sample_prior,
16+
init = modfit$fit$fit@inits, sample_prior = sample_prior,
1717
n_samples = ceiling((x$iter - x$warmup) /
1818
x$thin * x$chains))
1919
}

R/fit_bayesnec.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fit_bayesnec <- function(formula, data, model = NA, brm_args,
6969
msg_tag <- ifelse(family$family == "custom", custom_name, family$family)
7070
message(paste0("Response variable modelled as a ", model, " model using a ",
7171
msg_tag, " distribution."))
72-
out <- list(fit = fit, model = model, inits = all_args$inits,
72+
out <- list(fit = fit, model = model, init = all_args$init,
7373
bayesnecformula = formula)
7474
allot_class(out, "prebayesnecfit")
7575
}

R/helpers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ add_brm_defaults <- function(brm_args, model, family, predictor, response,
478478
} else {
479479
brm_args$prior <- priors
480480
}
481-
if (!("inits" %in% names(brm_args)) || skip_check) {
481+
if (!("init" %in% names(brm_args)) || skip_check) {
482482
msg_tag <- ifelse(family$family == "custom", custom_name, family$family)
483483
message(paste0("Finding initial values which allow the response to be",
484484
" fitted using a ", model, " model and a ", msg_tag,
@@ -489,7 +489,7 @@ add_brm_defaults <- function(brm_args, model, family, predictor, response,
489489
if (length(inits) == 1 && "random" %in% names(inits)) {
490490
inits <- inits$random
491491
}
492-
brm_args$inits <- inits
492+
brm_args$init <- inits
493493
}
494494
brm_args
495495
}

R/prebayesnecfit-class.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' @slot fit The fitted Bayesian model of class \code{\link[brms]{brmsfit}}.
1818
#' @slot model A \code{\link[base]{character}} string indicating the name of
1919
#' the fitted model.
20-
#' @slot inits A \code{\link[base]{list}} containing the initialisation values
20+
#' @slot init A \code{\link[base]{list}} containing the initialisation values
2121
#' for to fit the model.
2222
#' @slot bayesnecformula An object of class \code{\link{bayesnecformula}} and
2323
#' \code{\link[stats]{formula}}.
@@ -50,7 +50,7 @@ is_prebayesnecfit <- function(x) {
5050
#' @noRd
5151
recover_prebayesnecfit <- function(x) {
5252
if (is_bayesnecfit(x)) {
53-
out <- allot_class(x[c("fit", "model", "inits", "bayesnecformula")],
53+
out <- allot_class(x[c("fit", "model", "init", "bayesnecformula")],
5454
"prebayesnecfit")
5555
out <- list(out = out)
5656
names(out) <- out$out$model

data/manec_example.rda

20.7 KB
Binary file not shown.

man/bayesnecfit-class.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prebayesnecfit-class.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-expand_classes.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fit2 <- manec_example$mod_fits[["ecx4param"]]
77
test_that("expand_nec defaults work for nec model", {
88
nec_fit <- expand_nec(fit1, fit1$bayesnecformula, model = "nec4param") %>%
99
suppressWarnings
10-
expect_equal(names(nec_fit), c("fit", "model", "inits", "bayesnecformula",
10+
expect_equal(names(nec_fit), c("fit", "model", "init", "bayesnecformula",
1111
"pred_vals", "top",
1212
"beta", "nec", "f", "bot", "d",
1313
"slope", "ec50", "dispersion", "predicted_y",
@@ -23,7 +23,7 @@ test_that("expand_nec arguments work for nec model", {
2323
nec_fit <- expand_nec(fit1, fit1$bayesnecformula, model = "nec4param",
2424
x_range = c(0.01, 4), precision = 20) %>%
2525
suppressWarnings
26-
expect_equal(names(nec_fit), c("fit", "model", "inits", "bayesnecformula",
26+
expect_equal(names(nec_fit), c("fit", "model", "init", "bayesnecformula",
2727
"pred_vals", "top",
2828
"beta", "nec", "f", "bot", "d",
2929
"slope", "ec50", "dispersion", "predicted_y",
@@ -38,7 +38,7 @@ test_that("expand_nec arguments work for nec model", {
3838
test_that("expand_ecx defaults work for ecx model", {
3939
ecx_fit <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param") %>%
4040
suppressWarnings
41-
expect_equal(names(ecx_fit), c("fit", "model", "inits", "bayesnecformula",
41+
expect_equal(names(ecx_fit), c("fit", "model", "init", "bayesnecformula",
4242
"pred_vals", "top",
4343
"beta", "nec", "f", "bot", "d",
4444
"slope", "ec50", "dispersion", "predicted_y",
@@ -54,7 +54,7 @@ test_that("expand_ecx arguments work for ecx model", {
5454
ecx_fit <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param",
5555
x_range = c(0.01, 4), precision = 20) %>%
5656
suppressWarnings
57-
expect_equal(names(ecx_fit), c("fit", "model", "inits", "bayesnecformula",
57+
expect_equal(names(ecx_fit), c("fit", "model", "init", "bayesnecformula",
5858
"pred_vals", "top",
5959
"beta", "nec", "f", "bot", "d", "slope",
6060
"ec50", "dispersion", "predicted_y",

0 commit comments

Comments
 (0)