This function takes in delay data and prepares it for use with the primarycensored Stan model.
Usage
pcd_as_stan_data(
data,
delay = "delay",
delay_upper = "delay_upper",
n = "n",
pwindow = "pwindow",
start_relative_obs_time = "start_relative_obs_time",
relative_obs_time = "relative_obs_time",
dist_id,
primary_id,
param_bounds,
primary_param_bounds,
priors,
primary_priors,
compute_log_lik = FALSE,
use_reduce_sum = FALSE,
truncation_check_multiplier = 2,
dist_options = NULL
)Arguments
- data
A data frame containing the delay data.
- delay
Column name for observed delays (default: "delay")
- delay_upper
Column name for upper bound of delays (default: "delay_upper")
- n
Column name for count of observations (default: "n")
- pwindow
Column name for primary window (default: "pwindow")
- start_relative_obs_time
Column name for start of relative observation time, used as the lower truncation point L. Values may be any finite real number (including negatives) or
-Infto indicate no lower truncation. If the column is not present in data, L =-Infis assumed for all observations. (default: "start_relative_obs_time")- relative_obs_time
Column name for relative observation time, used as the upper truncation point D. Values may be any finite real number (including negatives, paired with a smaller
start_relative_obs_time) or+Infto indicate no upper truncation. (default: "relative_obs_time")- dist_id
Integer identifying the delay distribution: You can use
pcd_stan_dist_id()to get the dist ID for a distribution or look at the pcd_distributions data set.- primary_id
Integer identifying the primary distribution: You can use
pcd_stan_dist_id()to get the primary dist ID for a distribution (make sure to select the "primary" type) or look at the pcd_primary_distributions data set.- param_bounds
A list with elements
lowerandupper, each a numeric vector specifying bounds for the delay distribution parameters.- primary_param_bounds
A list with elements
lowerandupper, each a numeric vector specifying bounds for the primary distribution parameters.- priors
A list with elements
locationandscale, each a numeric vector specifying priors for the delay distribution parameters.- primary_priors
A list with elements
locationandscale, each a numeric vector specifying priors for the primary distribution parameters.- compute_log_lik
Logical; compute log likelihood? (default: FALSE)
- use_reduce_sum
Logical; use reduce_sum for performance? (default: FALSE)
- truncation_check_multiplier
Numeric multiplier to use for checking if the truncation time D is appropriate relative to the maximum delay for each unique D value. Set to NULL to skip the check. Default is 2.
- dist_options
Optional list carrying the shape of a non-parametric delay. When
dist_idis one of26(step CDF, Dirichlet prior on the PMF),27(step CDF, random walk on the logit hazards) or28(step CDF, IID logit random effects on the hazards), this list must be supplied and must contain:K: integer, the number of bins.boundaries: numeric vector of lengthK + 1.
Priors and
param_boundsfollow the same channel as the parametric path: pass them throughpriorsandparam_bounds. The semantics ofpriorsdepend ondist_id:dist_id = 26:priors$scaleis the length-KDirichlet concentration vector;priors$locationis unused.dist_id = 27or28:priors$location = c(alpha_mean, log_sigma_mean)andpriors$scale = c(alpha_sd, log_sigma_sd).
param_boundsis unused for the non-parametric paths; passlist(lower = numeric(0), upper = numeric(0)). Ifpriorsis empty when a non-parametricdist_idis given, sensible defaults are applied (Dirichlet(1, ..., 1)fordist_id = 26;N(0, 5)onalphaandN(0, 1)onlog_sigmafor 27 and 28).
Value
A list containing the data formatted for use with
pcd_cmdstan_model()
See also
Modelling wrappers for external fitting packages
fitdistdoublecens(),
pcd_cmdstan_model()
Examples
data <- data.frame(
delay = c(1, 2, 3),
delay_upper = c(2, 3, 4),
n = c(10, 20, 15),
pwindow = c(1, 1, 2),
relative_obs_time = c(10, 10, 10)
)
stan_data <- pcd_as_stan_data(
data,
dist_id = 1,
primary_id = 1,
param_bounds = list(lower = c(0, 0), upper = c(10, 10)),
primary_param_bounds = list(lower = numeric(0), upper = numeric(0)),
priors = list(location = c(1, 1), scale = c(1, 1)),
primary_priors = list(location = numeric(0), scale = numeric(0))
)
#> The truncation time D (10) is larger than 2 times the maximum observed delay (3). Consider setting D to Inf for better efficiency with minimal accuracy cost for this case.
