After fitting the model the R2 for test data is negative

This gets very subtle and trips up a lot of new Bayesians trying to plug in the classical R^2 calculations. Here’s a nice overview from Gelman et al.

R-squared for Bayesian regression models. Andrew Gelman, Ben Goodrich, Jonah Gabry, Aki Vehtari. 2018. https://sites.stat.columbia.edu/gelman/research/unpublished/bayes_R2_v3.pdf

As warmup, the Wikipedia article on R^2 is nice: