6
$\begingroup$

Is there an R package for MCMC that can

  • accept my self-defined (log)likelihood function (can be done in MCMCpack)

and

  • lets the user define contraints to the proposals (like only accept values from the [0,1] interval, or take only positive values (possible in rSTAN)

I already definded my model in R code but obviously no MCMC package in R can handle constraints on the parameters like rstan and I don't want to recode it in rstan.

Update:

I found that the LaplacesDemon package is perfect for my needs, but the package is obviously abandoned :(

$\endgroup$
0

3 Answers 3

6
$\begingroup$

The t-walk package implementing the t-walk algorithm allows you to define the support for your (log)likelihood function, if that is what you are after.

Supp a function that takes a vector of length=dim and returns TRUE if the vector is within the support of the objective and FALSE otherwise. Supp is *always* called right before Obj.

It also seems to be a pretty general sampling algorithm. From the package:

The t-walk is a "A General Purpose Sampling Algorithm for Continuous Distributions" to sample from many objective functions (specially suited for posterior distributions using non-standard models that would make the use of common algorithms and software difficult); it is an MCMC that does not required tuning.

R package here: www.cimat.mx/~jac/twalk/

$\endgroup$
2
  • $\begingroup$ I just wanted to add that I've used the package and it has worked very well for me (but that was on pretty simple models). $\endgroup$ Commented Sep 7, 2014 at 15:26
  • $\begingroup$ I took a look at the blog in your profile and read the post where you mentioned the LaplacesDemon package. It does indeed allow constraints on the parameters (unlike you said in your post, so this might be a new feature). So thank you for finding this great package. $\endgroup$
    – spore234
    Commented Sep 7, 2014 at 15:37
3
$\begingroup$

You should also check out Mamba, a new MCMC package, but its not in R, but rather julia:

https://github.com/brian-j-smith/Mamba.jl

it relies on the julia Distributions package which allows you to create your own distributions

Package documentation and examples: http://mambajl.readthedocs.org/en/latest/

$\endgroup$
2
  • $\begingroup$ nice, thanks. I also implemented my model in Julia, does this package accept self defined loglikelihood functions? $\endgroup$
    – spore234
    Commented Sep 7, 2014 at 19:56
  • $\begingroup$ Of course, use the distributions package in julia: user-defined distributions $\endgroup$
    – bdeonovic
    Commented Sep 7, 2014 at 20:01
0
$\begingroup$

Stan allows user-defined functions (including likelihood) as part of the model's "functions" blocks. These may not be quite as fast as the language's built-in likelihoods (and they won't automatically drop constant terms), but they will still be fairly fast. The specific details of writing functions are found in the Stan manual, and examples can be found on the stan-users mailing list.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.