epinowcast
Loading...
Searching...
No Matches
hazard.stan
Go to the documentation of this file.
1
15vector prob_to_hazard(vector p) {
16 int l = num_elements(p);
17 // h[i] = p[i] / (1 - sum(p[1:(i-1)])), with h[l] = 1 by definition
18 return append_row(
19 p[1:(l-1)] .* inv(1 - append_row(0.0, cumulative_sum(p[1:(l-2)]))),
20 1.0
21 );
22}
23
41vector cumulative_converse_log_hazard(vector h, int l) {
42 // Shift hazards by one time unit: [0, h[1], h[2], ..., h[l-1]]
43 // Then compute cumulative sum of log(1 - h_shifted) for survival probability
44 return cumulative_sum(log1m(append_row(0.0, h[1:(l-1)])));
45}
46
69vector hazard_to_log_prob(vector h, int l) {
70 return(log(h) + cumulative_converse_log_hazard(h, l));
71}
vector prob_to_hazard(vector p)
Definition hazard.stan:15
vector cumulative_converse_log_hazard(vector h, int l)
Definition hazard.stan:41
vector hazard_to_log_prob(vector h, int l)
Definition hazard.stan:69