greta-dev / greta-dev/greta

Bayesian R square for greta model

Open
#345 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
607
Forks
67
Avg merge
3d 8h
Merged PRs (30d)
1

Description

Inspired by the work from Gelman and others on [Bayesian R-square](https://stat.columbia.edu/~gelman/research/published/bayes_R2_v3.pdf), I was wondering if it would make sense to include such a function in greta or in an associated packages to run model checks on greta model fits.

In essence one needs two things:

- the vector of response values (y)
- the posterior draws from the linear predictor (which we could get from _calculate_) on the response scale (let's call this ypred)

Then in R code we have:

```r
# posterior residuals
e <- -1 * sweep(as.matrix(ypred), 2, y)
# variance in linear predictors
var_ypred <- apply(as.matrix(ypred), 1, var)
# variance in residuals
var_e <- apply(e, 1, var)
# R2 values
post_r2 <- var_ypred / (var_ypred + var_e)
```

The trick is basically to get the posterior draws from the linear predictors.

Any ideas?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.