# Unpooled Accelerated Failure Time Model

**URL:** <https://discourse.pymc.io/t/unpooled-accelerated-failure-time-model/16135>\
**Category:** version agnostic\
**Created:** [November 19, 2024, 4:46am UTC](https://discourse.pymc.io/t/unpooled-accelerated-failure-time-model/16135 "2024-11-19T04:46:37Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![buckeye17](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/buckeye17/32/8206_2.png) [@buckeye17](https://discourse.pymc.io/u/buckeye17)\
**Post date:** [November 20, 2024, 3:12am UTC](https://discourse.pymc.io/t/unpooled-accelerated-failure-time-model/16135/2 "2024-11-20T03:12:35Z")

</div>

In trying to resolve this issue myself, I found [this](https://discourse.pymc.io/t/understanding-dimensions-shapes-of-variables/12821/4) forum discussion very helpful. It helped me see a couple problems with my original best guess. However, I still haven’t gotten it to work. Below is my current best guess. The error I get now comes from prior predictive sampling. The Error message is: `IndexError: shape mismatch: indexing arrays could not be broadcast together with (X,) (Y,)`. In this this case X corresponds to the length of the uncensored data and Y corresponds to the length of all observations (censored and uncensored).

```py
idx = pd.Categorical(group_values, categories=unique_groups).codes
coords = {
    "intervals": intervals,
    "group": unique_groups,
    "group_flat": group_values,
    "preds": [
        "sentiment",
        "intention",
        "Male",
        "Low",
        "Medium",
        "Finance",
        "Health",
        "Law",
        "Public/Government",
        "Sales/Marketing",
    ],
}

X = retention_df[
    [
        "sentiment",
        "intention",
        "Male",
        "Low",
        "Medium",
        "Finance",
        "Health",
        "Law",
        "Public/Government",
        "Sales/Marketing",
    ]
].copy()
y = retention_df["month"].values
cens = retention_df.left.values == 0.0

def weibull_lccdf(x, alpha, beta):
    """Log complementary cdf of Weibull distribution."""
    return -((x / beta) ** alpha)

with pm.Model(coords=coords, check_bounds=False) as aft_model:
    X_data = pm.MutableData("X_data_obs", X)
    beta = pm.Normal("beta", 0.0, 1, dims="preds")
    mu = pm.Normal("mu", 0, 1, dims="groups")
    s = pm.HalfNormal("s", 5.0, dims="groups")
    eta = pm.Deterministic("eta", pm.math.dot(beta, X_data.T))
    reg = pm.Deterministic("reg", pt.exp(-(mu[None, :] + eta[:, None]) / s))
    y_obs = pm.Weibull("y_obs", beta=reg[~cens, idx], alpha=s[idx], observed=y[~cens], dims="groups_flat")
    y_cens = pm.Potential("y_cens", weibull_lccdf(y[cens], alpha=s[idx], beta=reg[cens, idx]), dims="groups_flat")

```

---

_[View the full topic](https://discourse.pymc.io/t/unpooled-accelerated-failure-time-model/16135)._
