I have two distributions of which I'd like to compare the 95% confidence interval of:
from scipy.stats import lognorm
from scipy.stats import uniform
import numpy as np
prior_fb = uniform(loc=0, scale=0.1)
post_fb = lognorm(s=np.log(1.15), scale=0.0076)
I can get the 95% confidence intervals, and mean of both distributions:
prior_mean = prior_fb.mean()
prior_interval = prior_fb.interval(0.95)
post_mean = post_fb.mean()
post_interval = post_fb.interval(0.95)
I tried generating random variates and plotting those using the "interval plot" function of Origin, but I think Origin assumes a normal distribution for the data, so the "interval plot" does not really represent the 95% interval:
The interval for the prior should go from 0.0025 to 0.0975, as given by prior_fb.interval(0.95)
.
How can I plot and compare the intervals (and the mean) for the prior and the posterior using matplotlib?
I would use box plot from matplotlib, you can pass mean values instead of median and you can pass confidence interval:
from matplotlib import pyplot
fig, ax = pyplot.subplots()
ax.boxplot([prior_fb.rvs(size=1000),post_fb.rvs(size=1000)],conf_intervals=[prior_interval,post_interval],usermedians=[prior_mean,post_mean],labels=['Prior','Post'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.