0

[I ][1] I can not figure out why the glm posterior predictive is not plotting over the entire data, but only over a fraction of it. And there seem to be no parameters which can alter these. This is the code which generates the following problematic plot.

    plt.figure(figsize=(7, 7))
    x = np.linspace(0,10,30)
    y = x + np.random.normal(2,0.6,len(x))
    plt.scatter(x,y)
    data = dict(x=x, y=y)

    with pm.Model() as model:
        pm.glm.GLM.from_formula('y ~ x', data)
        trace = pm.sample(1000)
    plt.plot(x, y, 'x', label='data')
    pm.plot_posterior_predictive_glm(trace, samples=100,label='posterior predictive 
    regression lines')
    plt.plot(x, trace['Intercept'].mean() + trace['x'].mean()*x, label='true regression 
    line', lw=3., c='y')

    plt.title('Posterior predictive regression lines')
    plt.legend(loc=0)
    plt.xlabel('x')
    plt.ylabel('y');

https://i.stack.imgur.com/2NLtP.png

Ayush Sahu
  • 43
  • 3

1 Answers1

2

Looking at the source code plot_posterior_predictive_glm default x-axis values are between 0 and 1. You can change that by calling the function as follows:

pm.plot_posterior_predictive_glm(trace,samples=100,eval=x,
                                 label='posterior predictive regression lines')

Running your code with the above modification I get the following plot:

enter image description here

LeoC
  • 912
  • 1
  • 8
  • 22