florianhartig / BayesianTools

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

`calibrationTest()` example #204

Closed torkar closed 3 years ago

torkar commented 4 years ago

Florian, do you have an example somewhere on how to use calibrationTest() (in particular if one can use it with brms)?

florianhartig commented 4 years ago

Hi Richard,

we applied this in https://www.nature.com/articles/s41559-019-0908-0, the code is available with the paper as an example.

It should definitely be possible to run this with brms as well.

I have slightly extended the help in a recent push to the development branch of BT, maybe this further clarifies the issues.

Feel free to post your brms example here, this could also be useful for other brms users.

Best, Florian

ghost commented 3 years ago

Dear Florian,

I am planning to use Bayesian Tools package in R to calibrate a model for my PhD research project. I have read useful and applicable examples you have prepared in the below website: https://cran.r-project.org/web/packages/BayesianTools/vignettes/BayesianTools.html

I follow the instructions in Bayesian Tools package in my codes but have some problems:

  1. For some models, I get different MAP output for parameters in each run.
  2. I don’t get good convergence for all parameters when I plot the trace of each parameter.
  3. I used “dnorm” in “singlelikelihood”, for all models and datasets. Should I choose different distribution function for this part or normal function is good enough?

Kind regards, Nastaran

`My_Data=read.csv('example.csv')

library(Metrics) library(ie2misc) library(BayesianTools)

likelihood1 <- function(param){ pred = param[1]+param[2](My_Data$A/((My_Data$C-My_Data$T)(1+(My_Data$V/(param[3])))))

singlelikelihoods = dnorm(My_Data$G, mean = pred, sd = 1/(param[4]^2), log = T) return(sum(singlelikelihoods)) } setUp1 <- createBayesianSetup(likelihood1, lower = c(-10,-10,-5,0.01), upper = c(20,20,10,30)) settings = list(nrChains = 4,iterations = 15000, message = FALSE) out1 <- runMCMC(bayesianSetup = setUp1, sampler = "Metropolis", settings = settings) #sampler: SMC,Metropolis,DEzs,DREAM,Twalk M1 = marginalLikelihood(out1) M1 print(out1) plot(out1) summary(out1) correlationPlot(out1) marginalPlot(out1, prior = TRUE) marginalLikelihood(out1) DIC(out1) Matrix_out1=getSample(out1, start = 100, end = NULL, thin = 5, whichParameters = 1:4) MAP(out1)`

ghost commented 3 years ago

Rplot.pdf

This is the plots for trace of parameters.

florianhartig commented 3 years ago

Hi Nastaran-ch,

this doesn't seem to fit here, I will open a separate issue.