Skip to content

Commit

Permalink
fixing overflow in inclusion Bayes factors
Browse files Browse the repository at this point in the history
  • Loading branch information
FBartos committed Apr 29, 2022
1 parent f66716e commit 0e4d674
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: BayesTools
Title: Tools for Bayesian Analyses
Version: 0.2.8
Version: 0.2.9
Description: Provides tools for conducting Bayesian analyses. The package contains
functions for creating a wide range of prior distribution objects, mixing posterior
samples from 'JAGS' and 'Stan' models, plotting posterior distributions, and etc...
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## version 0.2.9
### Fixes
- dealing with NaNs due to overflow with very large marginal likelihoods

## version 0.2.8
### Fixes
- dealing with point prior distributions in `JAGS_marglik_parameters_formula` function
Expand Down
4 changes: 2 additions & 2 deletions R/model-averaging.R
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ inclusion_BF <- function(prior_probs, post_probs, margliks, is_null){
check_real(prior_probs, "prior_probs", lower = 0, upper = 1, check_length = 0)
check_real(margliks, "margliks", check_length = length(prior_probs))

# center the margliks around the mean for higher precision
margliks <- margliks - mean(margliks)
# substract the max marglikto remove problems with overflow
margliks <- margliks - max(margliks)

return(
(sum(exp(margliks[!is_null]) * prior_probs[!is_null]) / sum(exp(margliks[is_null]) * prior_probs[is_null])) /
Expand Down

0 comments on commit 0e4d674

Please sign in to comment.