# Python Bayesian invgamma.rvs - joint posterior of normal distribution sampling

(My question is inspired by this blog post: The Bayesian analysis of normal distributions with Python. If you read it, you will get a good background on what I am asking.)

I am trying to model the joint distribution and according to German et al., you can simulate the variance parameter of the normal prior using an inverse Gamma distribution. Likewise, according to Wikipedia:

Perhaps the chief use of the inverse Gamma distribution is in Bayesian statistics, where the distribution arises as the marginal posterior distribution for the unknown variance of a normal distribution if an uninformative prior is used; and as an analytically tractable conjugate prior if an informative prior is required.

I want to know how the unknown variance parameter is derived analytically based on the article referenced. This subject matter to anyone who is new to Bayesian statistics is useful for inferring information from prior data (prior distribution) and likelihood (distribution representing probability of the data given parameter).

I have been doing this for two weeks and have a decent beginner's understanding. If you don't know anything about conjugate priors it may appear the question is hard. It should be a piece of cake if you understand priors and specifically conjugate priors.

References: Gelman et al, Bayesian Data Analysis, Third Edition, Section 3.3. (Please note I am using Inverse Gamma although Gelman uses inverse-chi-squared and you can reparameterize it as inverse Gamma.)

• I thought of what your saying but it's a bit of both but more relevant on the statistics side. The code would be clear cut if someone could better explain how to sample the inv gamma distribution and get the variance. Basically I will welcome a statistical methodology it just happens that alot of statistics guys now use Python and r. I would be content on an answer that would clarify the code. I just felt that no expert in stack overflow will be able to answer this question related to a stats library and a complex joint posterior problem. – samman Jun 25 '16 at 10:28
• Again to elaborate on my comment if someone wants to answer how to obtain a norm variance by using inv gamma I would be happy. No Python necessary. R or any methodology is welcome. Just felt that providing the code was more intuitive for someone who has used Python for statistics. – samman Jun 25 '16 at 10:31
• Please explain what you mean by "obtain a norm variance." – whuber Jun 25 '16 at 14:05
• engineering.richrelevance.com/… you will get a good background of what I am asking? – samman Jun 25 '16 at 21:15
• I have edited your post (& nominated it for re-opening) to emphasize the statistical question I think you are asking. If I haven't captured the statistical question well, or have missed something, please edit again to correct it. There is no need for defensiveness or justification. 'How to derive the relationship between the inverse Gamma & the variance of a normal' is a perfectly on-topic question for this site. – gung Jun 25 '16 at 23:51