You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
replaced all pymc potential with pymc censored (pymc-devs#750)
* replaced all pymc potential with pymc censored
* removed gumbel_sf function that is not being used
* added rng to samplers
* put back seeds for sampling data observations
---------
Co-authored-by: Jonathan Dekermanjian <[email protected]>
We have an unique problem when modelling censored data. Strictly speaking, we don't have any _data_ for censored values: we only know the _number_ of values that were censored. How can we include this information in our model?
73
87
74
-
One way do this is by making use of `pm.Potential`. The [PyMC2 docs](https://pymc-devs.github.io/pymc/modelbuilding.html#the-potential-class) explain its usage very well. Essentially, declaring `pm.Potential('x', logp)` will add `logp` to the log-likelihood of the model.
88
+
One way do this is by making use of `pm.Potential`. The [PyMC2 docs](https://pymc-devs.github.io/pymc/modelbuilding.html#the-potential-class) explain its usage very well. Essentially, declaring `pm.Potential('x', logp)` will add `logp` to the log-likelihood of the model.
89
+
90
+
However, `pm.Potential` only effect probability based sampling this excludes using `pm.sample_prior_predictice` and `pm.sample_posterior_predictive`. We can overcome these limitations by using `pm.Censored` instead. We can model our right-censored data by defining the `upper` argument of `pm.Censored`.
75
91
76
92
+++
77
93
@@ -80,36 +96,40 @@ One way do this is by making use of `pm.Potential`. The [PyMC2 docs](https://pym
80
96
This parameterization is an intuitive, straightforward parameterization of the Weibull survival function. This is probably the first parameterization to come to one's mind.
81
97
82
98
```{code-cell} ipython3
83
-
def weibull_lccdf(x, alpha, beta):
84
-
"""Log complementary cdf of Weibull distribution."""
85
-
return -((x / beta) ** alpha)
99
+
# normalize the event time between 0 and 1
100
+
y_norm = y / np.max(y)
101
+
```
102
+
103
+
```{code-cell} ipython3
104
+
# If censored then observed event time else maximum time
105
+
right_censored = [x if x > 0 else np.max(y_norm) for x in y_norm * censored]
- Originally collated by [Junpeng Lao](https://junpenglao.xyz/) on Apr 21, 2018. See original code [here](https://github.com/junpenglao/Planet_Sakaar_Data_Science/blob/65447fdb431c78b15fbeaef51b8c059f46c9e8d6/PyMC3QnA/discourse_1107.ipynb).
184
203
- Authored and ported to Jupyter notebook by [George Ho](https://eigenfoo.xyz/) on Jul 15, 2018.
185
204
- Updated for compatibility with PyMC v5 by Chris Fonnesbeck on Jan 16, 2023.
205
+
- Updated to replace `pm.Potential` with `pm.Censored` by Jonathan Dekermanjian on Nov 25, 2024.
0 commit comments