Dear List, Very many thanks to Nicky Best for the following information in relation to overwriting temporary data within a winBUGS program. Martin ********************************************* You could try writing a 'hard wired' logical function to carry out the calculations needed to get yconv. It is pretty straightforward to add your own logical functions to the BUGS language using the WBDev tools (see http://www1.imperial.ac.uk/medicine/about/divisions/pcphs/eph/bugs/winbu gs_2.html). This should not only speed up the compilation/run time but will make your code a lot less messy as you won't need to create lots of intermediate variables. Nicky Best ********************************************* Original Message I am an occasional winBUGS user, and I do not know the syntax well. I hope the following question is not too silly. I am working on a convolution problem, and need to evaluate expressions of the form: for(index in 1:NROWS) { ysum=0.0 for(shift in 1:index) { coef = (index-shift) * x1 ysum = ysum + yin[shift] * exp(-coef) } yout[index]=ysum*x2 } But a direct translation of this generic code into BUGS results in multiple definition errors for coef and ysum. The following code compiles without error. for(index in 1:NROWS) { for(shift in 1:index) { coef[index, shift] <- (index-shift) * x1[jsubj[index]] ytemp[index, shift] <- ymca[index] * exp(-coef[index, shift]) } yconv[index] <sum(ytemp[index,1:index]) *x2[jsubj[index]] } Congdon (2001, Bayesian Statistical Modelling) uses similar syntax in a program for regression with autocorrelated errors (Prog. 7.10). But given a large problem, this would appear to make extravagant use of memory. (Also takes ages to compile.) Presumably, the extra indexing operations must result in substantial run-time cpu demands. I can see the reason for getting the compiler to flag overwrites as an error. Nevertheless, is there a way of 'overwriting' temporary results, thus replacing the unwanted matrix/vector ops with scalar ops, and avoiding the resulting overheads? **************************************************** Dave Lunn makes the following comments on using the WBDev functions coding approach. There are three main advantages to doing this: first, function evaluations associated with 'hard-wired' components can be computed much more quickly than with their BUGS-language counterparts; second, the full flexibility of a general-purpose computer language is available for specifying each new component, and so piecewise functions, for example, can be specified straightforwardly whereas their specification via the BUGS language (using the "step(.)" function) can be somewhat awkward; finally, the practice of hiding the details of complex entities within 'hard-wired' components can lead to vastly simplified WinBUGS code for the required statistical model, which reduces the likelihood of coding errors occurring and is easier both to read and to modify. Thanks again to Nicky for suggesting this approach, Martin ***************** Martin King Biophysics, Radiology & Physics Unit Institute of Child Health/Gt Ormond Street Hospital for Children 30 Guilford Street London WC1N 1EH, UK tel: + 44 (0)20 7905 2273 fax: + 44 (0)20 7905 2358 email: [log in to unmask] ------------------------------------------------------------------- This list is for discussion of modelling issues and the BUGS software. For help with crashes and error messages, first mail [log in to unmask] 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