bambinos / bambi

BAyesian Model-Building Interface (Bambi) in Python.
https://bambinos.github.io/bambi/
MIT License
1.08k stars 124 forks source link

Implement censored families #697

Closed tomicapretto closed 1 year ago

tomicapretto commented 1 year ago

This PR implements censored families. For example

model = bmb.Model(
    "censored(time, status) ~ 1 + sex + age", 
    df_kidney, 
    family="gamma",
    link="log"
)

where time is a survival time and status is either "right" or "none" indicating right-censoring and no censoring, repsectively.


But there's an additional feature I discuss below

In addition, bmb.Model gains an extra argument called center_predictors. By default, when there's an intercept, Bambi centers all the predictors in the design matrix. This usually results in better sampling speed because (if I'm correct) mitigates some correlation in the posterior.

However, while I was testing the new censored models I was having lots of sampling initialization problems. I think it was due to a combination of the prior choice and the scale of the predictor variable, that when centered, caused the issue. So by doing bmb.Model(..., center_predictors=False) we get rid of the centering and the problem disappears.

Notice the center_predictors=False may also be usefu.l to people that just want to make sure the intercept they select for the prior has the natural interpretation they expect. With automatic centering, the interpretation of the intercept is not what you think it is (unless all your predictors are centered around zero)

codecov-commenter commented 1 year ago

Codecov Report

Attention: Patch coverage is 87.50000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 88.87%. Comparing base (6268ccf) to head (3f85e4f). Report is 72 commits behind head on main.

Files with missing lines Patch % Lines
bambi/families/univariate.py 77.77% 6 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #697 +/- ## ========================================== - Coverage 89.52% 88.87% -0.66% ========================================== Files 40 43 +3 Lines 2951 3362 +411 ========================================== + Hits 2642 2988 +346 - Misses 309 374 +65 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

review-notebook-app[bot] commented 1 year ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB