juanitorduz.github.io icon indicating copy to clipboard operation
juanitorduz.github.io copied to clipboard

Error bars incorrect for Gamma-Gamma model

Open Dekermanjian opened this issue 1 year ago • 3 comments

Hello, first let me say I really appreciate the quality of work you put into your blog. I was going through your post on the Gamma-Gamma model (https://juanitorduz.github.io/gamma_gamma_pymc/) and noticed something was weird with the error bars. Then I found out that Mattplotlib handles the error bars in a weird manner. They are actually +/- relative to the data. This was making your error bars much wider than they are supposed to be. Here is a quick and simple fix to get the proper width.

fig, ax = plt.subplots(figsize=(8, 8))
y = pymc_ceap.mean(axis=0)
err = az.hdi(ary=pymc_ceap, hdi_prob=0.8).T
offsets = np.abs(err - y[None, :])
ax.errorbar(
    x=ggf_ceap,
    y=y,
    yerr=offsets,
    fmt="o",
    ecolor="C6",
    markeredgecolor="C1",
    markerfacecolor="C1",
    markersize=5,
    alpha=0.5,
    capsize=2,
)
ax.axline(
    xy1=(0, 0),
    slope=1,
    color="black",
    linestyle="--",
    label="diagonal"
)
ax.legend(loc="upper left")
ax.set(title="Model Comparison", xlabel="lifetimes", ylabel="pymc");

Dekermanjian avatar Jan 06 '24 21:01 Dekermanjian

Hey @Dekermanjian ! Apologies for the late reply! I somehow missed this issue 🙈 ! (as the other issue!) I will take a look into this soon!

juanitorduz avatar Aug 02 '24 09:08 juanitorduz

Hey! Despite the fact I used ax.errorbars. I actually want to show the hdi estimation of the pymc model (not the errors). By passing yerr=az.hdi(ary=pymc_ceap).T, to the ax.errorbars functions I am plotting

shape(2, N): Separate - and + values for each bar. First row contains the lower errors, the second row contains the upper errors.

as described in https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.errorbar.html So I am plotting what I wanted. I had to be more careful about it.

Does this make sense for your?

juanitorduz avatar Aug 16 '24 20:08 juanitorduz

Hey @juanitorduz thank you for responding to this!! I think maybe I am misunderstanding what you are saying but first can you take a look at your values for az.hdi(ary=pymc_ceap) and then look at the plot you have generated I will paste it here straight from your notebook. Notice that most the hdi lower boundaries start at 0, but in az.hdi(ary=pymc_ceap) that is not the case. Also look at your max value for the upper boundary of your hdi. I am getting 296.80311269166964 as the max value but clearly in the graph you go above that value.

image

Dekermanjian avatar Aug 16 '24 21:08 Dekermanjian