Issues sampling linear models

New user here, teething problems are everywhere.

The main issue is when I run a model with NUTS, it crashes the notebook kernel I am running. Under Metropolis, the sampling function runs, but there is no output to examine. The code doesn’t seem to be faulty, nothing out of the ordinary from the tutorial notebooks I’ve seen.

Not really sure why this is happening, code below if anyone would have a look. Any help appreciated

with pm.Model() as linear:
# Priors
alpha = pm.Uniform(‘alpha’, lower=-10, upper=10)
beta = pm.Uniform(‘beta’, lower=-10, upper=10)

# Likelihood
phat = alpha + beta * distance

logitp = pm.Binomial('logitp', p=phat, n=len(distance), observed= logit)

where distance = array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20], dtype=int64)

and logit = array([ 2.63018153, 1.59566833, 1.04939831, 0.36080434, 0.19176195,
0.12516314, -0.1502822 , -0.76310577, -0.68565651, -0.77010822,
-1.05939158, -1.15496523, -0.7985077 , -1.60226942, -1.86321843,
-1.66587922, -1.56608747, -1.84845481, -1.67397643])

Hi,
I think there are several issues here, but the main ones seem to be:

  • Your observed data are not binomial – they seem to be on the real line.
  • p_hat is not between [0, 1] but on the real line – you need pm.math.invlogit to transform it into a probability.

Hope this helps :vulcan_salute:

Hi,

Thanks for the help.

You were correct, changing the observed data and transforming p_hat to a probability solved it.

Much obliged