epinowcast
hazard.stan
Go to the documentation of this file.
1
15vector prob_to_hazard(vector p) {
16 int l = num_elements(p);
17 int i = l - 1;
18 vector[l] h;
19 vector[i] cum_p;
20 cum_p[1] = 0;
21 cum_p[2:i] = cumulative_sum(p[1:(i-1)]);
22 h[1:i] = p[1:i] .* inv(1 - cum_p);
23 h[l] = 1;
24 return(h);
25}
26
44vector cumulative_converse_log_hazard(vector h, int l) {
45 vector[l] h_shifted;
46 vector[l] ch;
47 h_shifted[1] = 0;
48 if (l > 1) {
49 h_shifted[2:l] = h[1:(l-1)];
50 }
51 ch = log1m(h_shifted);
52 ch = cumulative_sum(ch);
53 return(ch);
54}
55
78vector hazard_to_log_prob(vector h, int l) {
79 return(log(h) + cumulative_converse_log_hazard(h, l));
80}
vector prob_to_hazard(vector p)
Definition: hazard.stan:15
vector cumulative_converse_log_hazard(vector h, int l)
Definition: hazard.stan:44
vector hazard_to_log_prob(vector h, int l)
Definition: hazard.stan:78