florianhartig / BayesianTools

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

Metropolis sampler startup error: Matrix seems negative semi-definite #242

Closed wwbgroup closed 1 year ago

wwbgroup commented 2 years ago

Hi,

I'm trying to use the runMCMC function but seems that there's an error: BT runMCMC: trying to find optimal start and covariance valuesError in Matrix::nearPD(MASS::ginv(-hessian)) : Matrix seems negative semi-definite runMCMC terminated after 0.540000000037253seconds If the sample is wrong, MCMC should reject it and resample to get a new one. But it seems that there's no resample and I'm not sure what the Matrix::nearPD(MASS::ginv(-hessian)) is. Appreciate for your help.

Thanks, Weibing

florianhartig commented 1 year ago

Hello,

sorry for the late reply

The error comes from the optimisation prior to the MCMC in the Metropolis algorithm - the default setting is to start the MCMC by running an optimisation first and adjusting the proposal function from the Hessian of the optimiser. Obviously, this calculation can fail. In this case, you can just switch it off (see help).

Side note: the default DE sampler family will usually sample more robust / efficient than the adaptive metropolis, so if you have no particular reason to use the Metropolis, I would recommend to stay with the DEzs sampler (which is the default)

Cheers, Florian