17 int wl = num_elements(effect);
18 vector[wl] scaled_effect = wl * effect;
19 return reports .* scaled_effect[day_of_week];
34vector
scale_obs(vector reports, real fraction_observed) {
35 int t = num_elements(reports);
36 vector[t] scaled_reports;
37 scaled_reports = reports * fraction_observed;
38 return(scaled_reports);
57vector
truncate_obs(vector reports, vector trunc_rev_cmf,
int reconstruct) {
58 int t = num_elements(reports);
59 int trunc_max = num_elements(trunc_rev_cmf);
60 vector[t] trunc_reports = reports;
62 int joint_max = min(t, trunc_max);
63 int first_t = t - joint_max + 1;
64 int first_trunc = trunc_max - joint_max + 1;
68 trunc_reports[first_t:t] ./= trunc_rev_cmf[first_trunc:trunc_max];
70 trunc_reports[first_t:t] .*= trunc_rev_cmf[first_trunc:trunc_max];
72 return(trunc_reports);
93void truncation_lp(array[] real truncation_mean, array[] real truncation_sd,
94 array[] real trunc_mean_mean, array[] real trunc_mean_sd,
95 array[] real trunc_sd_mean, array[] real trunc_sd_sd) {
96 int truncation = num_elements(truncation_mean);
98 if (trunc_mean_sd[1] > 0) {
100 truncation_mean ~ normal(trunc_mean_mean, trunc_mean_sd);
102 if (trunc_sd_sd[1] > 0) {
104 truncation_sd ~ normal(trunc_sd_mean, trunc_sd_sd);
125 return model_type ? inv_square(reporting_overdispersion) : 1e5;
144void report_lp(array[]
int cases, array[]
int case_times, vector reports,
145 real reporting_overdispersion,
int model_type, real weight) {
146 int n = num_elements(case_times);
147 vector[n] obs_reports = reports[case_times];
149 real phi =
reporting_phi(reporting_overdispersion, model_type);
151 cases ~ neg_binomial_2(obs_reports, phi);
153 target += neg_binomial_2_lpmf(
154 cases | obs_reports, phi
159 cases ~ poisson(obs_reports);
161 target += poisson_lpmf(cases | obs_reports) * weight;
181 int ot_h = num_elements(reports);
182 vector[ot_h] accumulated_reports = reports;
183 for (i in 1:(ot_h - 1)) {
185 accumulated_reports[i + 1] += accumulated_reports[i];
188 return accumulated_reports;
209 real reporting_overdispersion,
int model_type, real weight) {
210 int t = num_elements(reports);
214 if (model_type == 0) {
216 log_lik[i] = poisson_lpmf(cases[i] | reports[i]) * weight;
219 real phi =
reporting_phi(reporting_overdispersion, model_type);
221 log_lik[i] = neg_binomial_2_lpmf(
222 cases[i] | reports[i], phi
253 }
else if (phi > 1e4) {
254 return(poisson_rng(mu > 1e8 ? 1e8 : mu));
256 real gamma_rate = gamma_rng(phi, phi / mu);
257 return(poisson_rng(gamma_rate > 1e8 ? 1e8 : gamma_rate));
276array[]
int report_rng(vector reports, real reporting_overdispersion,
int model_type) {
277 int t = num_elements(reports);
278 array[t]
int sampled_reports;
279 real phi =
reporting_phi(reporting_overdispersion, model_type);
284 return(sampled_reports);
int neg_binomial_2_safe_rng(real mu, real phi)
vector truncate_obs(vector reports, vector trunc_rev_cmf, int reconstruct)
vector report_log_lik(array[] int cases, vector reports, real reporting_overdispersion, int model_type, real weight)
void truncation_lp(array[] real truncation_mean, array[] real truncation_sd, array[] real trunc_mean_mean, array[] real trunc_mean_sd, array[] real trunc_sd_mean, array[] real trunc_sd_sd)
real reporting_phi(real reporting_overdispersion, int model_type)
void report_lp(array[] int cases, array[] int case_times, vector reports, real reporting_overdispersion, int model_type, real weight)
vector accumulate_reports(vector reports, array[] int accumulate)
array[] int report_rng(vector reports, real reporting_overdispersion, int model_type)
vector day_of_week_effect(vector reports, array[] int day_of_week, vector effect)
vector scale_obs(vector reports, real fraction_observed)