Title: | Bayesian Estimation of Naloxone Kit Number Under-Reporting |
---|---|
Description: | Bayesian model and associated tools for generating estimates of total naloxone kit numbers distributed and used from naloxone kit orders data. Provides functions for generating simulated data of naloxone kit use and functions for generating samples from the posterior. |
Authors: | Mike Irvine [aut, cre, cph] , Samantha Bardwell [ctb], Andrew Johnson [ctb] |
Maintainer: | Mike Irvine <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0.9000 |
Built: | 2024-10-26 04:43:18 UTC |
Source: | https://github.com/sempwn/bennu |
Bayesian Estimation of Naloxone use Number Under-reporting
Stan Development Team (2020). RStan: the R interface to Stan. R package version 2.21.2. https://mc-stan.org
Samples from Bayesian model using input from data frame
est_naloxone( d, psi_vec = c(0.7, 0.2, 0.1), max_delays = 3, delay_alpha = 2, delay_beta = 1, priors = the$default_priors, run_estimation = TRUE, rw_type = 1, chains = 4, iter = 2000, seed = 42, adapt_delta = 0.85, pars = the$default_outputs, include = TRUE, ... )
est_naloxone( d, psi_vec = c(0.7, 0.2, 0.1), max_delays = 3, delay_alpha = 2, delay_beta = 1, priors = the$default_priors, run_estimation = TRUE, rw_type = 1, chains = 4, iter = 2000, seed = 42, adapt_delta = 0.85, pars = the$default_outputs, include = TRUE, ... )
d |
data frame with format
|
psi_vec |
reporting delay distribution |
max_delays |
maximum delay from kit ordered to kit distributed |
delay_alpha |
shape parameter for order to distributed delay distribution |
delay_beta |
shape parameter for order to distributed delay distribution |
priors |
list of prior values including their mean (mu) and standard deviation (sigma) |
run_estimation |
if |
rw_type |
|
chains |
A positive integer specifying the number of Markov chains. The default is 4. |
iter |
A positive integer specifying the number of iterations for each chain (including warmup). The default is 2000. |
seed |
Seed for random number generation |
adapt_delta |
(double, between 0 and 1, defaults to 0.8) |
pars |
A vector of character strings specifying parameters of interest.
The default is |
include |
Logical scalar defaulting to |
... |
other parameters to pass to rstan::sampling |
An S4 rstan::stanfit class object containing the fitted model
Other inference:
est_naloxone_vec()
## Not run: library(rstan) library(bayesplot) rstan_options(auto_write = TRUE) options(mc.cores = parallel::detectCores(logical = FALSE)) d <- generate_model_data() priors <- list( c = list(mu = 0, sigma = 1), ct0 = list(mu = 0, sigma = 1), zeta = list(mu = 0, sigma = 1), mu0 = list(mu = 0, sigma = 1), sigma = list(mu = 0, sigma = 1) ) fit <- est_naloxone(d, priors = priors, iter = 100, chains = 1) mcmc_pairs(fit, pars = c("sigma", "mu0"), off_diag_args = list(size = 1, alpha = 0.5) ) ## End(Not run)
## Not run: library(rstan) library(bayesplot) rstan_options(auto_write = TRUE) options(mc.cores = parallel::detectCores(logical = FALSE)) d <- generate_model_data() priors <- list( c = list(mu = 0, sigma = 1), ct0 = list(mu = 0, sigma = 1), zeta = list(mu = 0, sigma = 1), mu0 = list(mu = 0, sigma = 1), sigma = list(mu = 0, sigma = 1) ) fit <- est_naloxone(d, priors = priors, iter = 100, chains = 1) mcmc_pairs(fit, pars = c("sigma", "mu0"), off_diag_args = list(size = 1, alpha = 0.5) ) ## End(Not run)
Samples from Bayesian model
est_naloxone_vec( N_region, N_t, N_distributed, regions, times, Orders2D, Reported_Distributed, Reported_Used, region_name, psi_vec = c(0.7, 0.2, 0.1), max_delays = 3, delay_alpha = 2, delay_beta = 1, priors = the$default_priors, run_estimation = TRUE, rw_type = 1, chains = 4, iter = 2000, seed = 42, adapt_delta = 0.85, pars = the$default_outputs, include = TRUE, ... )
est_naloxone_vec( N_region, N_t, N_distributed, regions, times, Orders2D, Reported_Distributed, Reported_Used, region_name, psi_vec = c(0.7, 0.2, 0.1), max_delays = 3, delay_alpha = 2, delay_beta = 1, priors = the$default_priors, run_estimation = TRUE, rw_type = 1, chains = 4, iter = 2000, seed = 42, adapt_delta = 0.85, pars = the$default_outputs, include = TRUE, ... )
N_region |
Number of regions |
N_t |
number of time steps |
N_distributed |
Number of samples of reporting for distribution of kits |
regions |
vector (time, region) of regions (coded 1 to N_region) |
times |
vector (time, region) of regions (coded 1 to N_t) |
Orders2D |
vector (time, region) of orders |
Reported_Distributed |
vector (time, region) reported as distributed |
Reported_Used |
vector (time, region) reported as used |
region_name |
bring in region names |
psi_vec |
reporting delay distribution |
max_delays |
maximum delay from kit ordered to kit distributed |
delay_alpha |
shape parameter for order to distributed delay distribution |
delay_beta |
shape parameter for order to distributed delay distribution |
priors |
list of prior values including their mean (mu) and standard deviation (sigma) |
run_estimation |
if |
rw_type |
|
chains |
A positive integer specifying the number of Markov chains. The default is 4. |
iter |
A positive integer specifying the number of iterations for each chain (including warmup). The default is 2000. |
seed |
Seed for random number generation |
adapt_delta |
(double, between 0 and 1, defaults to 0.8) |
pars |
A vector of character strings specifying parameters of interest.
The default is |
include |
Logical scalar defaulting to |
... |
other parameters to pass to rstan::sampling |
An S4 rstan::stanfit class object containing the fitted model
Other inference:
est_naloxone()
Generated data from validation experiments of simulated data
experimental_validation_data
experimental_validation_data
experimental_validation_data
A data frame with 200 rows and 8 columns:
Model variable
Median of the posterior
2nd and 3rd quartiles of the posterior
1st and 19th ventiles of the posterior
The value used to generate the simulation
Experiment number index
Simulate kits ordered and kits distributed for a set number of regions and time-points.
The kits ordered simulation is a simple square-term multiplied by region_coeffs
.
For example if region_coeffs = c(1,2)
then the number of kits ordered at
month 12 are c(1,2) * 12^2 = c(144,288)
.
The probability of kit use in time is assumed to increase linearly in inverse
logit space at a constant rate 0.1
.
The probability of reporting for each month and region is iid distributed
which produces a mean reporting rate
of approximately 88%
generate_model_data( N_t = 24, region_coeffs = c(5, 0.5), c_region = c(-1, 2), reporting_freq = NULL )
generate_model_data( N_t = 24, region_coeffs = c(5, 0.5), c_region = c(-1, 2), reporting_freq = NULL )
N_t |
number of time-points |
region_coeffs |
vector of coefficients for regions determining kit orders |
c_region |
logit probability of kit use per region |
reporting_freq |
The frequency that distribution data is provided.
If |
A tibble
Kit orders per time and region
Numeric index indicating region of orders and distributions
Number of kits reported as used
Number of kits reported as distributed
Probability that a kit was used
Probability that a distributed kit was reported
Index for time
String index for the region
Other data generation:
model_random_walk_data()
Provides a summary of:
Estimated kits distributed
Percentage of kits distributed that are reported
Estimated kits used
percentage of kits used that are reported
percentage of kits orders that are used
probability kit used if distributed
kit_summary_table( fit, ..., data = NULL, accuracy = 0.01, cri_range = 0.95, ndraws = NULL )
kit_summary_table( fit, ..., data = NULL, accuracy = 0.01, cri_range = 0.95, ndraws = NULL )
fit |
stanfit object |
... |
variables to group by in estimate |
data |
data used for model fitting. Can also include |
accuracy |
A number to round to. Use (e.g.) 0.01 to show 2 decimal places of precision. If NULL, the default, uses a heuristic that should ensure breaks have the minimum number of digits needed to show the difference between adjacent values. |
cri_range |
The range of the credible interval e.g. 0.95 |
ndraws |
Number of draws to use in estimate |
Probability of kit use if distributed
Estimated as distributed
Proportion kits distributed that are reported
Estimated kits used
Proportion kits used that are reported
Proportion kits ordered that are used
Other plots:
plot_kit_use()
## Not run: fit <- est_naloxone(d) kit_summary_table(fit,regions,data = d) ## End(Not run)
## Not run: fit <- est_naloxone(d) kit_summary_table(fit,regions,data = d) ## End(Not run)
Generated data from validation experiments of simulated data
missing_data_validation
missing_data_validation
missing_data_validation
A data frame with 10 rows and 6 columns:
Median of the posterior
2nd and 3rd quartiles of the posterior
1st and 19th ventiles of the posterior
The reporting frequency in months
Model generating process using random walk to match data generating model in Bayesian framework
model_random_walk_data( N_t = 24, region_coeffs = c(5, 0.5), c_region = c(-1, 2), sigma = 2, zeta = 0.5, mu0 = -1, Orders = NULL, reporting_freq = NULL )
model_random_walk_data( N_t = 24, region_coeffs = c(5, 0.5), c_region = c(-1, 2), sigma = 2, zeta = 0.5, mu0 = -1, Orders = NULL, reporting_freq = NULL )
N_t |
number of time-points |
region_coeffs |
vector of coefficients for regions determining kit orders |
c_region |
logit probability of kit use per region |
sigma |
standard deviation of error in logit probability of kit use |
zeta |
standard deviation of random walk in logit space |
mu0 |
initial condition of random walk in logit space |
Orders |
A 2D matrix of shape |
reporting_freq |
The frequency that distribution data is provided.
If |
A tibble
Kit orders per time and region
Numeric index indicating region of orders and distributions
Number of kits reported as used
Number of kits reported as distributed
Probability that a kit was used
Probability that a distributed kit was reported
Index for time
String index for the region
Other data generation:
generate_model_data()
plot can compare between two different model fits or a single
model fit by region. If data are simulated then can also include in plot.
For more details see the introduction vignette:
vignette("Introduction", package = "bennu")
plot_kit_use(..., data = NULL, reported = FALSE, regions_to_plot = NULL)
plot_kit_use(..., data = NULL, reported = FALSE, regions_to_plot = NULL)
... |
named list of stanfit objects |
data |
data used for model fitting. Can also include |
reported |
if |
regions_to_plot |
Optional list to filter which regions are plotted |
ggplot2 object
Other plots:
kit_summary_table()