I'm using MCMC to fit a linear regression model with the end goal of making predictions for new observations. See reproducible example below:
library(ggplot2) library(MCMCpack) library(dplyr) data(mpg) attach(mpg) # Variance of hwy for each trans category # Some categories e.g. auto(s5) have a bigger variance # How can I make the distribution for a new prediction reflect this? vars <- mpg %>% group_by(trans) %>% summarise(hwy_var=var(hwy)) %>% ungroup() # Fit model bm <- MCMCregress(hwy ~ year + cyl + trans + cty) # Want to find distribution of hwy for new data point new_obs <- data.frame(year=1999, cyl=4, trans="auto(l6)", cty=16)
What I want to capture in predicting
hwy for the
new_obs is a predictive distribution, taking into account its predictor values. For example,
auto(l6) is a category with a larger
hwy variance (as seen in
vars) so I'd like the predictive distribution for this point to be wider. Is this possible with Bayesian statistics? Or any other method?