pymc-experimental icon indicating copy to clipboard operation
pymc-experimental copied to clipboard

PC prior distribution for Student T dof

Open bwengals opened this issue 1 year ago • 5 comments

Moving this over from here.

What is this PR about?

Adding penalized complexity prior for the Student-T degrees of freedom parameter. Useful in models where the likelihood was normal, but you'd need some robustness so you switch to a Student T likelihood. It's implemented already in INLA.

The reason this is useful for modeling is you can "robustify" your Gaussian likelihood by making it a student t in a more principled way. You can use this prior to express in a meaningful way "I think there is a 50% or 20% or whatever chance that the degrees of freedom is over 30 (~normal likelihood)", whereas if you use a Gamma(2, 0.1) or worse fix the degrees of freedom to some value, you risk watering down the information coming from the data via the likelihood.

Outstanding issues

  • Still need to add tests but I think it'll be good enough for now to compare the logp to INLA.
  • Might be better to use BoundedContiuous instead of PositiveContinuous? Went down that rabbit hole some already, might need some help here. Seems to work fine now for normal use, but I haven't tested too many weird edge cases.

bwengals avatar Oct 12 '23 18:10 bwengals

To update where this is at, tests were passing except for windows and I couldn't figure out why. Not sure what here would depend on windows so maybe need to dig into that in a VM or something to figure that out. Definitely some room to improve how some of this is structured, but was working well enough I was comfortable using it.

bwengals avatar Dec 08 '23 03:12 bwengals

@bwengals the biggest difference with Windows generally is that they sometimes default to int32 dtypes where linux defaults to int64 IIRC. Maybe something in the np.linspace overflows in windows? (I didn't look at which test was even failing, so apologies if this is completely off the target)

ricardoV94 avatar Dec 08 '23 15:12 ricardoV94

overflows in windows?

Ah I bet that's it! The test produces inf and it shouldn't. Well thanks for giving me a starting place

bwengals avatar Dec 11 '23 18:12 bwengals

In case that's the reason: https://stackoverflow.com/questions/36278590/numpy-array-dtype-is-coming-as-int32-by-default-in-a-windows-10-64-bit-machine

ricardoV94 avatar Dec 11 '23 18:12 ricardoV94

@bwengals interested in updating this one?

ricardoV94 avatar Feb 06 '24 09:02 ricardoV94