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

Specifying data to fit over? #187

Closed carran closed 4 years ago

carran commented 4 years ago

This is probably a silly question, but I haven't been able to find it in the documentation - the pseudocode example given for setting up a likelihood function is

likelihood = function(param){
  predicted = processmodel(param)
  ll = sum(dnorm(observed, mean = predicted, sd =param[x], log = T))
  return(ll)
}

Shouldn't it be

likelihood = function(param, observed){
  predicted = processmodel(param)
  ll = sum(dnorm(observed, mean = predicted, sd =param[x], log = T))
  return(ll)
}

At least, the above is how I've always written out likelihood functions in R (eg for use in optim() or similar). What is the standard way of specifying data in BayesianTools?

florianhartig commented 4 years ago

Hi carran,

in BT, there is currently no option to pass on further variables to the likelihood, so you have to specify your data in the global environment (i.e. observed must be defined somewhere before you define the likelihood).

We realize that this may be less safe at times, but on the other hand, given the large number of samplers that we have, it saves us a lot of programming work.

See also https://github.com/florianhartig/BayesianTools/issues/30