library(corrplot)M <-cor(ds)corrplot(M, method ='ellipse', order ='AOE', type ='upper')
Linear Regression
We will fit a linear regression to the scaled wine dataset
The priors come from (sensible) defaults in rstanarm
Linear regression can be specified in the following way, where \(X\) is the design matrix with one or more scaled predictors and \(y\) is the scaled quality score
Vehtari, A., Gelman, A., and Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing. 27(5), 1413–1432. :10.1007/s11222-016-9696-4. Links: published | arXiv preprint.
Can We Still Improve the Model
Quality variable is an ordinal scale variable, so a more appropriate likelihood would also be ordinal
A similar model can fit with frequentist methods using MASS::polr() function
Fitting Ordered Logistic
ds$quality <- d$quality -2# quality vector is now 1:6ds$quality <-as.factor(ds$quality) # it has to be treated as factor (category)fit3 <-stan_polr(quality ~ ., prior =R2(0.25), # the prior is on explained varianceprior_counts =dirichlet(1), data = ds, iter =1000, refresh =0)yrep3 <-posterior_predict(fit3)yrep3[1:5, 1:5]