25vector
update_Rt(
int t, real R0, vector noise, array[]
int bps,
26 vector bp_effects,
int stationary) {
28 int bp_n = num_elements(bp_effects);
29 int gp_n = num_elements(noise);
31 vector[t] logR = rep_vector(log(R0), t);
36 bp0[2:(bp_n + 1)] = cumulative_sum(bp_effects);
37 logR = logR + bp0[bps];
41 vector[t] gp = rep_vector(0, t);
46 gp[(gp_n + 1):t] = rep_vector(noise[gp_n], t - gp_n);
49 gp[2:(gp_n + 1)] = noise;
50 gp = cumulative_sum(gp);
73void rt_lp(array[] real initial_infections_scale, vector bp_effects,
74 array[] real bp_sd,
int bp_n, array[]
int cases,
75 real initial_infections_guess) {
78 bp_sd[1] ~ normal(0, 0.1) T[0,];
79 bp_effects ~ normal(0, bp_sd[1]);
81 initial_infections_scale ~ normal(initial_infections_guess, 2);
102 int len = num_elements(pmf);
103 vector[len] zero_series = linspaced_vector(len, 0, len - 1);
104 vector[len] exp_r = exp(-r * zero_series);
105 real ret = (R * dot_product(pmf, exp_r) - 1) /
106 (- R * dot_product(pmf .* zero_series, exp_r));
128real
R_to_r(real R, vector gt_rev_pmf, real abs_tol) {
129 int gt_len = num_elements(gt_rev_pmf);
130 vector[gt_len] gt_pmf = reverse(gt_rev_pmf);
131 real mean_gt = dot_product(gt_pmf, linspaced_vector(gt_len, 0, gt_len - 1));
132 real r = fmax((R - 1) / (R * mean_gt), -1);
133 real step = abs_tol + 1;
134 while (abs(step) > abs_tol) {
vector update_Rt(int t, real R0, vector noise, array[] int bps, vector bp_effects, int stationary)
Update a vector of effective reproduction numbers (Rt) based on an intercept, breakpoints (i....
real R_to_r_newton_step(real R, real r, vector pmf)
real R_to_r(real R, vector gt_rev_pmf, real abs_tol)
void rt_lp(array[] real initial_infections_scale, vector bp_effects, array[] real bp_sd, int bp_n, array[] int cases, real initial_infections_guess)