florianhartig / BayesianTools

General-Purpose MCMC and SMC Samplers and Tools for Bayesian Statistics
https://cran.r-project.org/web/packages/BayesianTools/index.html
115 stars 29 forks source link

Discrete valued parameters in Bayesian Tools #206

Open florianhartig opened 4 years ago

florianhartig commented 4 years ago

From a user:

Thank you for developing the Bayesian Tools package with so many powerful and flexible sampling functions and options. Can I sample a binary parameter (0/1) or a discrete valued parameter (as one of other parameters which are treated as continuous valued) using the functions in this package?

florianhartig commented 4 years ago

At the moment (version 0.1.7), BT doesn't explicitly support discrete or binary parameters.

If this is only about a small number of parameters, you could probably emulate a discrete parameter by adding a round() argument in your likelihood, and sampling continuously. This should give you the correct posterior (assuming all discrete parameters receice the appropriate prior weight), but I would not guarantee that all the functions in BT (e.g. convergence checks, marginal Likelihoods etc) work appropriately when using this hack. In doubt, check if what you want to do works with an example where the posterior is known to you.

peterlevy commented 1 year ago

I have a similar issue, with (several) discrete parameters, which can only take the values 1, 2, 3, or 4. Can I somehow force a step size of 1 in the proposal generator, so I only move between these values?