MCMC Error 0315: Prior variance matrix is not positive defin

Welcome to the forum for runmlwin users. Feel free to post your question about runmlwin here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to runmlwin: Running MLwiN from within Stata >> http://www.bristol.ac.uk/cmm/software/runmlwin/
Post Reply
Raphael
Posts: 19
Joined: Wed Oct 12, 2011 2:52 am

MCMC Error 0315: Prior variance matrix is not positive defin

Post by Raphael »

Hi all,
I am currently trying to run a 2-level model using runmlwin with a random intercepts, a random slope, and a cross-level interaction. My goal is to run this model in the MCMC mode. The problem is that the covariance term obtains a negative value if I fit the model using IGLS (which is not very unusual to happen)
var(cons) 0.0228347
cov(cons,femhead) -0.0037903
var(femhead) 0.0004103
When I switch to MCMC I get the following error message:
"MCMC Error 0315: Prior variance matrix is not positive definite"

Does anyone has an idea how I can fix this problem?
Thanks a lot for your help!

Best,
Raphael
GeorgeLeckie
Site Admin
Posts: 432
Joined: Fri Apr 01, 2011 2:14 pm

Re: MCMC Error 0315: Prior variance matrix is not positive d

Post by GeorgeLeckie »

Hi Rapheal,

When MLwiN says "MCMC Error 0315: Prior variance matrix is not positive definite" what this is telling you is that the IGLS estimates for one or more of your variance covariacne matrices are dodgy. Typically the problem is that the correlations implied by your covariance matrix lie outside the boundaries of the feasible parameter space. MCMC uses the IGLS estimates as starting values for the MCMC chains.

In your case you have a correlation less than -1

. display -0.0037903/sqrt(0.0228347*0.0004103)
-1.238298

This suggests that there is something not quite right with your data or that the model you are trying to fit to the data is not appropriate. You should resolve this issue before you proceed.

Nethereless, you can proceed to fit the model using MCMC by manually providing well behaved starting values for the model parameters where you make sure to specifiy the parameters of the dodgy variance covariance matrix such that the correlation lies in the range -1 to 1. You can do this by using the initsb(matname) option.

Best wishes

George
Raphael
Posts: 19
Joined: Wed Oct 12, 2011 2:52 am

Re: MCMC Error 0315: Prior variance matrix is not positive d

Post by Raphael »

Hi George,
Thanks a lot for the helpful answer and the fast response to my question!
It took me some time to figure out how to use initsb(matrix) as you suggested.
So I thought I might share my newly gained knowledge here. First of all, STATA stores the regression coefficients and variance/covariance values in a certain matrix e(b). The matrix can be viewed by using the STATA command ‘matrix list e(b)’. In order to obtain a correlation between -1 and 1 I decided to adjust the cov(cons,femhead) term (formerly -0.0037903). I first stored the e(b) matrix in a matrix that I named b using the STATA command ‘matrix b = e(b)’ and then changed the specific element for cov(cons,femhead), which was in my case the 18th element using the STATA command ‘matrix b[1,18] = --0.003’ whereas the syntax for addressing an element in a matrix is [row, column]. I chose to set the covariance term to -0.003 because this results in a correlation of -.98 which lies within the range of -1 to 1 and is still very close to the values that I obtained from the IGLS models.
. dis -0.003/sqrt(0.0228347*0.0004103)
-.98010553
I then ran the MCMC models with the following specification ‘mcmc(burnin(500) chain(50000) refresh(500) hcentring(2)) initsb(b)’
This model runs perfectly.

However, I was wondering if you have any recommendation for the choice of optimal default values in case the IGLS priors do not work? For example, I could simply specify the following values which provide a correlation close to 0 and thus in the middle of the allowed range of -1 to 1.
. dis 0.01/sqrt(0.1*0.1)
.1

Thanks a lot!
Best,
Raphael
GeorgeLeckie
Site Admin
Posts: 432
Joined: Fri Apr 01, 2011 2:14 pm

Re: MCMC Error 0315: Prior variance matrix is not positive d

Post by GeorgeLeckie »

Dear Raphael,

Thank you very much for your useful post. I am sure other users will benefit from this.

In terms of initial values, as long as they are reasonably credible and as long as you run for a suffficiently long burnin then you should be fine. So in you case specifying variances of 0.1, a covariance of 0 and a burnin of 500 should be fine. When you manually specifiy starting values (rather than use the IGLS estimates) it is good practice to try different sets and to check that you get similar results. You can also use the mcmcsum command to examine the MCMC diagnostics to check that your burnin is sufficiently long.

However, I am still concerned about why you were getting a correlation outside (-1,1) when you fitted the model by IGLS. Once again I would recomment that you investigate you data and model carefully to try to work this out before you proceed with MCMC estimation.

Best wishes

George
Post Reply