Skip to content

Commit

Permalink
Re #35 Add default output parameters to rstan::sampling to prevent ot…
Browse files Browse the repository at this point in the history
…her outputs being included in posterior sample.
  • Loading branch information
sempwn committed Mar 12, 2024
1 parent 889978e commit c6706b8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# define package wide environment
the <- new.env(parent = emptyenv())
16 changes: 16 additions & 0 deletions R/est_naloxone.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# default outputs of model to save
the$default_outputs <- c(
"sim_p", "sim_used", "sim_reported_used", "c", "ct",
"sigma", "zeta", "mu0", "Distributed"
)



#' Run Bayesian estimation of naloxone number under-reporting
#'
Expand Down Expand Up @@ -27,6 +34,7 @@
#' @param seed Seed for random number generation
#' @param adapt_delta (double, between 0 and 1, defaults to 0.8)
#' @param ... other parameters to pass to [rstan::sampling]
#' @inheritParams rstan::sampling
#' @family inference
#' @return An S4 [rstan::stanfit] class object containing the fitted model
#' @export
Expand All @@ -44,6 +52,8 @@ est_naloxone_vec <- function(N_region, N_t, N_distributed, regions,
iter = 2000,
seed = 42,
adapt_delta = 0.85,
pars = the$default_outputs,
include = TRUE,
...) {
Orders <- as.vector(t(Orders2D))

Expand Down Expand Up @@ -107,6 +117,8 @@ est_naloxone_vec <- function(N_region, N_t, N_distributed, regions,
seed = seed, # fix seed to recreate results
control = list(adapt_delta = adapt_delta),
chains = chains,
pars = pars,
include = include,
...
)
return(fit)
Expand Down Expand Up @@ -156,6 +168,8 @@ est_naloxone <- function(d,
iter = 2000,
seed = 42,
adapt_delta = 0.85,
pars = the$default_outputs,
include = TRUE,
...) {
Orders <- NULL

Expand Down Expand Up @@ -211,6 +225,8 @@ est_naloxone <- function(d,
iter = iter,
seed = seed,
adapt_delta = adapt_delta,
pars = pars,
include = include,
...
)

Expand Down
14 changes: 14 additions & 0 deletions man/est_naloxone.Rd

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

14 changes: 14 additions & 0 deletions man/est_naloxone_vec.Rd

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

0 comments on commit c6706b8

Please sign in to comment.