Plateau data: Initial evaluation of model at starting point failed!

Hi,

I’ve a simple model that fails in a situation where the measured data does not change. Here is the code:

import bambi as bmb
import pymc as pm 
import pandas as pd

df = pd.DataFrame({ 
        "x": [739159, 739190, 739220, 739251],
        "y": [43, 43, 43, 43],
        })

# Create the glm using the Bambi model syntax
model = bmb.Model("y ~ x", df, family="t")
model.set_priors({"nu": bmb.Prior("Gamma", alpha=3, beta=1)})

# Fit the model using a NUTS (No-U-Turn Sampler) 
trace = model.fit(
    draws=10000,
    tune=1000,
    discard_tuned_samples=True,
    chains=4, 
    progressbar=True)

The error I get is

SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'sigma_log__': array(-inf), 'nu_log__': array(0.5193919), 'Intercept': array(43.14749544), 'x': array(0.48053908)}

Logp initial evaluation results:
{'sigma': -inf, 'nu': -0.82, 'Intercept': -inf, 'x': -inf, 'y': -inf}
You can call `model.debug()` for more details.

What do I need to change to make it more robust?

Best,
Thorsten

1 Like

CC @tcapretto?

I suspect thr automatic priors from the data may do something wrong here?

This data is only a subset of the complete dataset. I guess I could use the estimates for mu and sigma from the complete dataset as priors? But I’m not entirely sure how to do that with bambi

There’s in fact a problem with automatic priors. See the model summary

import bambi as bmb
import pandas as pd

df = pd.DataFrame({ 
    "x": [739159, 739190, 739220, 739251],
    "y": [43, 43, 43, 43],
})

# Create the glm using the Bambi model syntax
model = bmb.Model("y ~ x", df, family="t")
model.set_priors({"nu": bmb.Prior("Gamma", alpha=3, beta=1)})

model
Formula: y ~ x
        Family: t
          Link: mu = identity
  Observations: 4
        Priors: 
    target = mu
        Common-level effects
            Intercept ~ Normal(mu: 43.0, sigma: 0.0)
            x ~ Normal(mu: 0.0, sigma: 0.0) 
        
        Auxiliary parameters
            sigma ~ HalfStudentT(nu: 4.0, sigma: 0.0)
            nu ~ Gamma(alpha: 3.0, beta: 1.0)

Have a look at the sigma value for the prior for Intercept, x, and sigma. That is because there is a bug with automatic priors when the response is constant (all the values of y are equal in the provided dataset).

I think we should at least raise a warning in those scenarios.

Sidenote: you may want to standardize your predictor. You can do it before creating the model, making sure you transform appropriately when computing predictions, or you can do something like

bmb.Model("y ~ scale(x)", ...)

which will standardize x for you and automatically handle transformations in future predictions.

1 Like