Minor stan simplifications

This commit is contained in:
Ben Letham 2018-05-25 13:57:45 -07:00
parent aa37fb48ac
commit 663214393e
2 changed files with 6 additions and 12 deletions

View file

@ -29,10 +29,7 @@ functions {
real m_pr; real m_pr;
// Compute the rate in each segment // Compute the rate in each segment
k_s[1] = k; k_s = append_row(k, k + cumulative_sum(delta));
for (i in 1:S) {
k_s[i + 1] = k_s[i] + delta[i];
}
// Piecewise offsets // Piecewise offsets
m_pr = m; // The offset in the previous segment m_pr = m; // The offset in the previous segment
@ -42,7 +39,7 @@ functions {
} }
return gamma; return gamma;
} }
vector logistic_trend( vector logistic_trend(
real k, real k,
real m, real m,
@ -56,7 +53,7 @@ functions {
vector[S] gamma; vector[S] gamma;
gamma = logistic_gamma(k, m, delta, t_change, S); gamma = logistic_gamma(k, m, delta, t_change, S);
return cap ./ (1 + exp(-(k + A * delta) .* (t - (m + A * gamma)))); return cap .* inv_logit((k + A * delta) .* (t - (m + A * gamma)));
} }
// Linear trend function // Linear trend function

View file

@ -29,10 +29,7 @@ functions {
real m_pr; real m_pr;
// Compute the rate in each segment // Compute the rate in each segment
k_s[1] = k; k_s = append_row(k, k + cumulative_sum(delta));
for (i in 1:S) {
k_s[i + 1] = k_s[i] + delta[i];
}
// Piecewise offsets // Piecewise offsets
m_pr = m; // The offset in the previous segment m_pr = m; // The offset in the previous segment
@ -42,7 +39,7 @@ functions {
} }
return gamma; return gamma;
} }
vector logistic_trend( vector logistic_trend(
real k, real k,
real m, real m,
@ -56,7 +53,7 @@ functions {
vector[S] gamma; vector[S] gamma;
gamma = logistic_gamma(k, m, delta, t_change, S); gamma = logistic_gamma(k, m, delta, t_change, S);
return cap ./ (1 + exp(-(k + A * delta) .* (t - (m + A * gamma)))); return cap .* inv_logit((k + A * delta) .* (t - (m + A * gamma)));
} }
// Linear trend function // Linear trend function