Skip to content

Commit

Permalink
Fix truncation slicing when t < truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs authored Aug 7, 2024
1 parent a3a06df commit c7aa214
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions inst/stan/functions/observation_model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ vector scale_obs(vector reports, real frac_obs) {
// Truncate observed data by some truncation distribution
vector truncate(vector reports, vector trunc_rev_cmf, int reconstruct) {
int t = num_elements(reports);
int trunc_max = num_elements(trunc_rev_cmf);
vector[t] trunc_reports = reports;
// Calculate cmf of truncation delay
int trunc_max = min(t, num_elements(trunc_rev_cmf));
int first_t = t - trunc_max + 1;
int joint_max = min(t, trunc_max);
int first_t = t - joint_max + 1;
int first_trunc = trunc_max - joint_max + 1;

// Apply cdf of truncation delay to truncation max last entries in reports
if (reconstruct) {
trunc_reports[first_t:t] ./= trunc_rev_cmf[1:trunc_max];
trunc_reports[first_t:t] ./= trunc_rev_cmf[first_trunc:trunc_max];
} else {
trunc_reports[first_t:t] .*= trunc_rev_cmf[1:trunc_max];
trunc_reports[first_t:t] .*= trunc_rev_cmf[first_trunc:trunc_max];
}
return(trunc_reports);
}
Expand Down

0 comments on commit c7aa214

Please sign in to comment.