An extention to the bayes_R2 function
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by reading R/bayes_R2.R, the linked paper, and the attached BayesRsquared.pdf to compare the proposed extension with the current function. The issue does not define an agreed scope or acceptance criteria; done would require maintainers to decide whether the broader model support belongs in this package and specify the implementation and validation expectations.
Written by the indexing model from the issue text.
Description
Hi,
This work shows that we can extend the use of the Bayesian R-square in the bayes_R2 function to a wider range of models. I've suggested some changes to the bayes_R2 function, which you can find below and in the attached file. It is not an issue, but I wanted to know whether to create an issue or submit a direct pull request.
BayesRsquared.pdf
Thank you for considering this.
Best regards,
Abdollah
bayes_R2_new <- function(fit)
{
fam <- family(fit) # family dist. of the response
eta <- posterior_linpred(fit) # linear predictor: eta
mu <- fam$linkinv(eta) # conditional mean
varfit <- apply(mu, 1, var)
varres <- switch(fam$family, gaussian={
as.matrix(fit, pars="sigma")^2
}, binomial={
v <- fam$variance(mu)
apply(v, 1, mean)
}, poisson={
v <- fam$variance(mu)
apply(v, 1, mean)
}, Gamma={
v <- fam$variance(mu)
apply(v, 1, mean) / as.matrix(fit, pars="shape")
}, beta={
v <- fam$variance(mu)
apply(v, 1, mean)
}, neg_binomial_2={
size <- as.matrix(fit, pars="reciprocal_dispersion")
v <- fam$variance(mu, theta=c(size))
apply(v, 1, mean)
}, inverse.gaussian={
v <- family(fit)$variance(mu)
apply(v, 1, mean) / as.matrix(fit, pars="lambda")
}, stop("the speciefied family is not implemented"))
R2 <- varfit / (varres + varfit) # Bayesian R-squared
attributes(R2) <- list(varfit=varfit, varres=varres)
return(R2)
}
- Dominant language
- R
- Stars
- 49
- Forks
- 24
- Avg merge
- 23h 46m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stan-dev/rstantools
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
stan-dev/rstantools#131 · 2 comments ·
-
Use testthat 3eMay be free again @VisruthSK claimed this 75 days ago, and no pull request is open. Open
stan-dev/rstantools#159 · 1 reaction · 1 assignee ·
-
Cleanup VignetteMay be free again @VisruthSK claimed this 79 days ago, and no pull request is open. Open
stan-dev/rstantools#157 · 1 comment · 1 assignee ·
-
Difficulty 1/5 Under an hour Newbie friendliness 45/100
stan-dev/rstantools#134 · 6 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
stan-dev/rstantools#127 ·
All issues in stan-dev/rstantools
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
bug code cleaning
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
furrer-lab/abn#272 ·
-
R CMD check red on main: load_* loader tests fail (2026-season release assets not published yet)Open
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
sportsdataverse/hoopR#227 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
philchalmers/SimDesign#106 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 64/100