Path: blob/master/notebooks/misc/gaussian_param_inf_1d_numpyro.ipynb
1192 views
Inference for the parameters of a 1d Gaussian using a non-conjugate prior
We illustrate various inference methods using the example in sec 4.3 ("Gaussian model of height") of Statistical Rethinking ed 2. This requires computing using a Gaussian likelihood but a non-conjugate prior. The numpyro code is from Du Phan's site.
Data
We use the "Howell" dataset, which consists of measurements of height, weight, age and sex, of a certain foraging tribe, collected by Nancy Howell.
Empirical mean and std.
Model
We use the following model for the heights (in cm):
The prior for has a mean 178cm, since that is the height of Richard McElreath, the author of the "Statisical Rethinking" book. The standard deviation is 20, so that 90% of people lie in the range 138--218.
The prior for has a lower bound of 0 (since it must be positive), and an upper bound of 50, so that the interval has width 100cm, which seems sufficiently large to capture human heights.
Note that this is not a conjugate prior, so we will just approximate the posterior. But since there are just 2 unknowns, this will be easy.
Grid posterior
Posterior samples.
posterior marginals.
Laplace approximation
Optimization
Posterior samples.
Extract 2d joint posterior
The Gaussian approximation is over transformed parameters.
We can sample from the posterior, which return results in the original parameterization.
Variational inference
We use