Bayesian linear regression with a categorical variable
When the predictor is categorical, such as a binary feature, we would set one parameter for each corresponding category. The following exercise demonstrates such an example.
Exercise 14.5 – Performing Bayesian inference with a categorical variable
In this exercise, we will examine the relationship between am
(automatic or manual transmission, a categorical variable) and mpg
(miles per gallon, a continuous variable). We will define the mean of the normal likelihood for mpg
as a function of am
, with a different mean mu[i]
for each level of am
. We’ll also give mu
a normal prior and standard deviation s
a uniform prior. Follow the next steps:
- Specify the aforementioned model architecture, as follows:
# define the model model = "model{ # Define model for data Y[i] for(i in 1:length(Y)) { Y[i] ~ dnorm(mu[am[i]+1], s^(-2...