Skip to content

Commit

Permalink
updating "inits"-->"init" argument to allow for brms and cmdstanr com…
Browse files Browse the repository at this point in the history
…patibility
  • Loading branch information
dbarneche committed Sep 2, 2022
1 parent 2e0b7a3 commit 30eb8e6
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/amend.R
Expand Up @@ -95,7 +95,7 @@ amend.default <- function(object, drop, add, loo_controls, x_range = NA,
if (!inherits(mod_m, "prebayesnecfit")) {
brm_args <- list(
family = family, iter = simdat$iter, thin = simdat$thin,
warmup = simdat$warmup, inits = simdat$inits, chains = simdat$chains,
warmup = simdat$warmup, init = simdat$init, chains = simdat$chains,
sample_prior = simdat$sample_prior
)
if (missing(priors)) {
Expand Down
2 changes: 1 addition & 1 deletion R/bayesnecfit-class.R
Expand Up @@ -17,7 +17,7 @@
#' @slot fit The fitted Bayesian model of class \code{\link[brms]{brmsfit}}.
#' @slot model A \code{\link[base]{character}} string indicating the name of
#' the fitted model.
#' @slot inits A \code{\link[base]{list}} containing the initialisation values
#' @slot init A \code{\link[base]{list}} containing the initialisation values
#' for to fit the model.
#' @slot bayesnecformula An object of class \code{\link{bayesnecformula}} and
#' \code{\link[stats]{formula}}.
Expand Down
4 changes: 2 additions & 2 deletions R/extract_simdat.R
Expand Up @@ -6,14 +6,14 @@
#' by \code{\link{fit_bayesnec}}.
#'
#' @return A \code{\link[base]{list}} of model simulation statistics including
#' iter, thin, warmup, chains, inits and nsamples.
#' iter, thin, warmup, chains, init and nsamples.
#'
#' @noRd
extract_simdat <- function(modfit) {
x <- modfit$fit$fit@sim
sample_prior <- attr(modfit$fit$prior, "sample_prior")
list(iter = x$iter, thin = x$thin, warmup = x$warmup, chains = x$chains,
inits = modfit$fit$fit@inits, sample_prior = sample_prior,
init = modfit$fit$fit@inits, sample_prior = sample_prior,
n_samples = ceiling((x$iter - x$warmup) /
x$thin * x$chains))
}
2 changes: 1 addition & 1 deletion R/fit_bayesnec.R
Expand Up @@ -69,7 +69,7 @@ fit_bayesnec <- function(formula, data, model = NA, brm_args,
msg_tag <- ifelse(family$family == "custom", custom_name, family$family)
message(paste0("Response variable modelled as a ", model, " model using a ",
msg_tag, " distribution."))
out <- list(fit = fit, model = model, inits = all_args$inits,
out <- list(fit = fit, model = model, init = all_args$init,
bayesnecformula = formula)
allot_class(out, "prebayesnecfit")
}
4 changes: 2 additions & 2 deletions R/helpers.R
Expand Up @@ -478,7 +478,7 @@ add_brm_defaults <- function(brm_args, model, family, predictor, response,
} else {
brm_args$prior <- priors
}
if (!("inits" %in% names(brm_args)) || skip_check) {
if (!("init" %in% names(brm_args)) || skip_check) {
msg_tag <- ifelse(family$family == "custom", custom_name, family$family)
message(paste0("Finding initial values which allow the response to be",
" fitted using a ", model, " model and a ", msg_tag,
Expand All @@ -489,7 +489,7 @@ add_brm_defaults <- function(brm_args, model, family, predictor, response,
if (length(inits) == 1 && "random" %in% names(inits)) {
inits <- inits$random
}
brm_args$inits <- inits
brm_args$init <- inits
}
brm_args
}
Expand Down
4 changes: 2 additions & 2 deletions R/prebayesnecfit-class.R
Expand Up @@ -17,7 +17,7 @@
#' @slot fit The fitted Bayesian model of class \code{\link[brms]{brmsfit}}.
#' @slot model A \code{\link[base]{character}} string indicating the name of
#' the fitted model.
#' @slot inits A \code{\link[base]{list}} containing the initialisation values
#' @slot init A \code{\link[base]{list}} containing the initialisation values
#' for to fit the model.
#' @slot bayesnecformula An object of class \code{\link{bayesnecformula}} and
#' \code{\link[stats]{formula}}.
Expand Down Expand Up @@ -50,7 +50,7 @@ is_prebayesnecfit <- function(x) {
#' @noRd
recover_prebayesnecfit <- function(x) {
if (is_bayesnecfit(x)) {
out <- allot_class(x[c("fit", "model", "inits", "bayesnecformula")],
out <- allot_class(x[c("fit", "model", "init", "bayesnecformula")],
"prebayesnecfit")
out <- list(out = out)
names(out) <- out$out$model
Expand Down
Binary file modified data/manec_example.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/bayesnecfit-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/prebayesnecfit-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/test-expand_classes.R
Expand Up @@ -7,7 +7,7 @@ fit2 <- manec_example$mod_fits[["ecx4param"]]
test_that("expand_nec defaults work for nec model", {
nec_fit <- expand_nec(fit1, fit1$bayesnecformula, model = "nec4param") %>%
suppressWarnings
expect_equal(names(nec_fit), c("fit", "model", "inits", "bayesnecformula",
expect_equal(names(nec_fit), c("fit", "model", "init", "bayesnecformula",
"pred_vals", "top",
"beta", "nec", "f", "bot", "d",
"slope", "ec50", "dispersion", "predicted_y",
Expand All @@ -23,7 +23,7 @@ test_that("expand_nec arguments work for nec model", {
nec_fit <- expand_nec(fit1, fit1$bayesnecformula, model = "nec4param",
x_range = c(0.01, 4), precision = 20) %>%
suppressWarnings
expect_equal(names(nec_fit), c("fit", "model", "inits", "bayesnecformula",
expect_equal(names(nec_fit), c("fit", "model", "init", "bayesnecformula",
"pred_vals", "top",
"beta", "nec", "f", "bot", "d",
"slope", "ec50", "dispersion", "predicted_y",
Expand All @@ -38,7 +38,7 @@ test_that("expand_nec arguments work for nec model", {
test_that("expand_ecx defaults work for ecx model", {
ecx_fit <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param") %>%
suppressWarnings
expect_equal(names(ecx_fit), c("fit", "model", "inits", "bayesnecformula",
expect_equal(names(ecx_fit), c("fit", "model", "init", "bayesnecformula",
"pred_vals", "top",
"beta", "nec", "f", "bot", "d",
"slope", "ec50", "dispersion", "predicted_y",
Expand All @@ -54,7 +54,7 @@ test_that("expand_ecx arguments work for ecx model", {
ecx_fit <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param",
x_range = c(0.01, 4), precision = 20) %>%
suppressWarnings
expect_equal(names(ecx_fit), c("fit", "model", "inits", "bayesnecformula",
expect_equal(names(ecx_fit), c("fit", "model", "init", "bayesnecformula",
"pred_vals", "top",
"beta", "nec", "f", "bot", "d", "slope",
"ec50", "dispersion", "predicted_y",
Expand Down

0 comments on commit 30eb8e6

Please sign in to comment.