diff --git a/DESCRIPTION b/DESCRIPTION index 6d5ce162..1a59d135 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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... diff --git a/NEWS.md b/NEWS.md index 59f2aa8c..847f95e9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/model-averaging.R b/R/model-averaging.R index 114a7f60..a1847e58 100644 --- a/R/model-averaging.R +++ b/R/model-averaging.R @@ -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])) /