Runing on PyMC v4.4.0
df_penguins=pd.read_csv(r'https://raw.githubusercontent.com/BayesianModelingandComputationInPython/BookCode_Edition1/main/data/penguins.csv')
df=df_penguins.dropna(how = 'any').reset_index(drop=True) #drop if any of the values in a row is missing
data=df_adelie.loc[:,'body_mass_g'].values
with pm.Model() as model_adelie_penguin_mass:
μ = pm.Normal("μ", 4000, 3000)
σ = pm.HalfStudentT("σ", nu=30, sigma=2000)
#σ=pm.Exponential('σ', 1/30)+1
y = pm.Normal("y", mu=μ, sigma=σ, observed=data)
idata = pm.sample(2000,chains=2)
idata.extend(pm.sample_prior_predictive())
idata.extend(pm.sample_posterior_predictive(idata))
az.plot_posterior(idata.prior, var_names=["σ"]) # This plot gives a symmetric approx normal shape around "σ"=2000 for the prior. The shape of the prior from idata.prior["σ"] should be approx. pymc.HalfStudentT shape, instead its approximately symmetric normal centred on 2000. Has the parameterization of the pymc.HalfStudentT in the latest version of PYMC changed in some way.
I tried the following: rv = pm.HalfStudentT.dist(nu=10,sigma=20)
rv = pm.HalfStudentT.dist(nu=30,sigma=3000)
x = np.linspace(-1000, 7000, 50)
pdf = pm.logp(rv,x).exp().eval()
fig,ax=plt.subplots(1,1,figsize=(4 ,3),sharex=True)
plt.plot(x, pdf, label='Half-Student-t', lw=2)
which showed a graph of the correct shape but
rv = pm.HalfStudentT.dist(nu=10,sigma=5)
sns.histplot(pm.draw(rv,10000))
again did not give the pymc.HalfStudentT shape. It would be very helpful if anybody can spot the flaw in the parameterisation or in the way I am attempting to parameterize the HalfStudentT prior. the example is taken from ‘Bayesian Moddelling and Computation’ in python by Osvaldo Martin page69 but he is using pymc3. I also tried instead setting prior to : σ=pm.Exponential('σ', 1/30)+1
which worked perfectly but would very much like to know why σ = pm.HalfStudentT("σ", nu=30, sigma=2000)
fails to give correct shape when plotted with az.plot_posterior(idata.prior, var_names=["σ"])
. Thanking you in advance. Declan.