stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
743 stars 187 forks source link

censored weibull function #57

Open syclik opened 9 years ago

syclik commented 9 years ago

From @bob-carpenter on December 4, 2014 2:48

Aki Vehtari suggested building in a function that behaves like some R survival analysis packages:

real weibull_right_censored_log(real y, real sigma, real alpha, int z) {
  if (z == 0) return weibull_log(y,alpha,sigma);
  else return weibull_ccdf_log(y,alpha,sigma);
}

The int value z is used as an indicator as to whether the event was right censored at y or whether it was an ordinary outcome.

Aki also mentioned that it's common to have a vector of censored outcomes, all censored at the same place.

Copied from original issue: stan-dev/stan#1153

syclik commented 9 years ago

From @bob-carpenter on December 4, 2014 2:52

I have to add right away that I'm not a huge fan of this kind of function that overloads y as either a censoring bound or an outcome. I'd prefer

y_obs ~ weibull(alpha,sigma);
y_cens ~ weibull_ccdf(alpha,sigma);

with two different variables, y_obs for the ordinary observations and y_cens for right censored. If we need to do left censoring, it's just the CDF instead of the CCDF. If we need to do both, we need a new notation; see #1154