Dear WinBUGS community, I recently asked a question about what was causing an "undefined real result" error. Thank you for the many very helpful answers: as was pointed out to me, the solution was to improve my initial values! Now, however, the error has returned, and seems to be caused by the matrix inverse() function. It would be great to hear if anyone has any suggestions as to why this is happening. The issue: I'm trying to generate the posterior density for a function of several other variables (stochastic nodes). I can generate the posteriors for each variable individually, but - because of correlations between variables - it would be much more preferable to get the posterior for this function of them all. One step in this function involves taking the inverse of a matrix. However, when I do this (using the inverse() command in WinBUGS), the model immediately crashes into "undefined real result". Specific details: Specifically, the function I am trying to obtain is the expected first passage time of a Markov chain. Following the matrix methods in Grinstead & Snell (2006), I subtract a 7-by-7 matrix of probabilities (called "Q") from a 7-by-7 identity matrix (called "I"), generating a 7-by-7 matrix called "IminusQ". I then take the inverse of "IminusQ" using this line of code: FundamentalMatrix[SAMPLE,1:7,1:7] <- inverse(IminusQ[SAMPLE,,]) It's this last step that seems to be causing the problems. What I have tried: 1. Since the "undefined real result" error can indicate numerical overflow, I thought the problem might be that a number with very many decimal places is being generated. I therefore tried rounding the values in the "IminusQ" matrix to see if that solved the problem, but - so far - it hasn't. 2. The model above runs through a loop with different values of the constant 'SAMPLE'. I've tried getting rid of the loop, so that it is simply inverse(IminusQ[,]), but this didn't solve the issue either. What the TRAP error looks like: The main part of the TRAP error that shows up is as follows: undefined real result Math.Sqrt [00000120H] .x REAL -10.60785630107878 MathMatrix.LUDecomp [00000384H] .a ARRAY 20, 20 OF REAL Elements .i INTEGER 5 .j INTEGER 5 .k INTEGER -1 .size INTEGER 7 .sum REAL -10.60785630107878 MathMatrix.Invert [000004DFH] .a ARRAY 20, 20 OF REAL Elements .i INTEGER 6415876 .j INTEGER 0 .k INTEGER 0 .size INTEGER 7 .sum REAL 0.0 GraphInverse.Node.Evaluate [00000279H] .component GraphInverse.Node NIL .i INTEGER 7 .j INTEGER 7 .node GraphInverse.Node [04C97BB0H] .off INTEGER 48 .p GraphNodes.Node [04C992E0H] .size INTEGER 7 .values ARRAY 49 OF REAL Elements GraphVector.Node.Value [00000121H] .cursor GraphLogical.List NIL .index INTEGER 918423085 .node GraphVector.Node [04C97BB0H] .p GraphLogical.Node NIL .q GraphVector.Node [04C97BB0H] .value REAL 7.965856772862247E-307 MonitorsSamples.StdMonitor.Update [0000023DH] .blocks POINTER NIL .i INTEGER 884150886 .index INTEGER 0 .monitor MonitorsSamples.StdMonitor [04454240H] .numBlocks INTEGER 0 .value REAL 1.761304528764966E-311 If this isn't easily soluble in WinBUGS, it's been suggested to me to use Stan. However, I'm keen to try to find the solution in WinBUGS before giving in! Very many thanks if you have any ideas that might solve this very perplexing problem! Kind regards, Patrick ------------------------------------------------------------------- This list is for BUGS users to support each other, ask questions or share ideas. To mail the BUGS list, mail to [log in to unmask] Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html Please do not mail attachments to the list. To leave the BUGS list, send LEAVE BUGS to [log in to unmask] If this fails, mail [log in to unmask], NOT the whole list