Collinearity and Bayesian Regression
A draft response to this question on Reddit.
This notebook is based on Think Bayes 2e, which is available from Bookshop.org and Amazon.
The well-behaved dataset
The problematic dataset, scaled so y is in fA.
Compute the explanatory variables.
The explanatory variables are highly correlated, which is going to be a problem.
Sure enough, ols complains about the collinearity.
And here's what the fitted model looks like.
The up-swoop on the left is non-physical.
Let's see how Bayesian regression handles collinearity.
The sampling process throws some divergences, which makes sense because the high-density part of the probability space is a long, narrow tunnel, so it's easy to spin out.
Nevertheless, the diagnostics look fine.
The r_hat values are fine.
The only notable problem is that the standard deviations are super big, but that's because the model borders on being non-identifiable.
To show what the issue is, let's look at the joint distribution of a and b.
They are highly correlated, which indicates that we can't be confident about the actual values of a and b, but we can be confident about their sum -- and that's all we need.
Here's the posterior distribution of the sum, with a much more reasonable range of values.
Instead of looking at the parameters, let's look at the predictions. The following figure shows the model predictions for 50 of the samples.
None of them have the non-physical upswoop.
We can use the sampled parameters to compute the distribution of the intercept at t=0.
Based on the experimental design and the data, that might be the best estimate we can make.
As an aside, since this model only has three parameters, we could use a grid algorithm to approximate the posterior distribution quickly and deterministically.
Copyright 2024 Allen B. Downey
License: Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)