merliseclyde / BAS

BAS R package for Bayesian Model Averaging and Variable Selection
https://merliseclyde.github.io/BAS/
GNU General Public License v3.0
41 stars 16 forks source link

Modify model priors when using include.always #41

Closed vandenman closed 4 years ago

vandenman commented 5 years ago

A possible fix for #40.

At the start of an analyses no_prior_inclusion_is_1(p, probs) counts the number of the initprobs that are 1, denoted noInclusionIs1. This number is passed to all calls to compute_prior_probs which reduces the model space and number of predictors by noInclusionIs1.

For example, this PR will change the prior model probabilities to:

res <- bas.lm(Y ~ ., data = Hald, modelprior = beta.binomial(1, 1), 
              include.always = ~ 1 + X1 + X2)
modeldim <- lengths(res$which)
ord <- order(modeldim)
cbind(modeldim, prior = res$priorprobs[ord])
modeldim  prior
    3     0.333
    4     0.167
    4     0.167
    5     0.333

whereas the current master branch returns:

cbind(modeldim, prior = res$priorprobs[ord])
modeldim  prior
    3     0.033
    4     0.050
    4     0.050
    5     0.200 # <- most prior mass on the most complex model!

I also added a unit test to test-model-priors.R that checks this.

I hope this helps, if anything is unclear please let me know. All comments and/ or feedback are welcome!

codecov[bot] commented 5 years ago

Codecov Report

Merging #41 into master will increase coverage by 0.02%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   91.56%   91.58%   +0.02%     
==========================================
  Files          54       54              
  Lines        5771     5787      +16     
==========================================
+ Hits         5284     5300      +16     
  Misses        487      487
Impacted Files Coverage Δ
src/lm_sampleworep.c 97.57% <100%> (ø) :arrow_up:
src/model_probabilities.c 97.61% <100%> (+0.25%) :arrow_up:
src/glm_sampleworep.c 100% <100%> (ø) :arrow_up:
src/lm_mcmcbas.c 96.98% <100%> (ø) :arrow_up:
src/lm_deterministic.c 99.14% <100%> (ø) :arrow_up:
src/glm_deterministic.c 100% <100%> (ø) :arrow_up:
src/glm_mcmcbas.c 90.36% <100%> (+0.04%) :arrow_up:
src/glm_mcmc.c 100% <100%> (ø) :arrow_up:
src/lm_mcmc.c 97.83% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d99b3d3...abb73a6. Read the comment docs.