Tips and Troubleshooting
Contents
Restrictions when modelling
Some error messages
Some Trap messages
The program hangs
Speeding up sampling
Improving convergence
This section covers a range of problems that might arise:
1) restrictions in setting up the model;
2) error messages generated when setting up the model or when sampling;
3) Traps: these corresponds to an error which has not been picked up by WinBUGS . It is difficult to interpret the Trap message!
4) the program just hanging;
5) slow sampling;
6) lack of convergence.
Restrictions when modelling [top]
Restrictions have been stated throughout this manual. A summary list is as follows:
a) Each stochastic and logical node must appear once and only once on the left-hand-side of an expression. The only exception is when carrying out a data transformation (see Data transformations ). This means, for example, that it is generally not possible to give a distribution to a quantity that is specified as a logical function of an unknown parameter.
b) Truncated sampling distributions cannot be handled using the I(.,.) construct - see Censoring and truncation .
c) Multivariate distributions: Wishart distributions may only be used as conjugate priors and must have known parameters; multivariate normal and Student-t distributions can be used anywhere in the graph (i.e. as prior or likelihood) and there are no restrictions regarding their parameters. See Constraints on using certain distributions .
d) Logical nodes cannot be given data or initial values. This means, for example, that it is not possible to model observed data that is the sum of two random variables. (See Logical nodes .)
e) Poisson priors can only be specified for the (unknown) order (n) of a single binomial observation. In this case, the sampling method for a 'shifted Poisson' distribution will be used (see MCMC methods ). If more than one binomial response is assumed to share the same order parameter, then the algorithm for a shifted Poisson cannot be used to update the order parameter and WinBUGS will return the error message "Unable to choose update method for n". A suitably constrained continuous prior may be used for the order parameter, provided that it is used in conjunction with the round(.) function to ensure integer values (see here for an example of using the 'round' function to this end).
Some error messages [top]
a) 'expected variable name' indicates an inappropriate variable name.
b) 'linear predictor in probit regression too large' indicates numerical overflow. See possible solutions below for Trap 'undefined real result'.
c) 'logical expression too complex' - a logical node is defined in terms of too many parameters/constants or too many operators: try introducing further logical nodes to represent parts of the overall calculation; for example, a1 + a2 + a3 + b1 + b2 + b3 could be written as A + B where A and B are the simpler logical expressions a1 + a2 + a3 and b1 + b2 + b3, respectively. Note that linear predictors with many terms should be formulated by 'vectorizing' parameters and covariates and by then using the inprod(.,.) function (see Logical nodes ).
d) 'invalid or unexpected token scanned' - check that the value field of a logical node in a Doodle has been completed.
e) 'unable to choose update method' indicates that a restriction in the program has been violated - see Restrictions when modelling above.
f) 'undefined variable' - variables in a data file must be defined in a model (just put them in as constants or with vague priors). If a logical node is reported undefined , the problem may be with a node on the 'right hand side'.
g) 'index out of range' - usually indicates that a loop-index goes beyond the size of a vector (or matrix dimension); sometimes, however, appears if the # has been omitted from the beginning of a comment line.
Some Trap messages [top]
a) 'undefined real result' indicates numerical overflow. Possible reasons include:
- initial values generated from a 'vague' prior distribution may be numerically extreme - specify appropriate initial values;
- numerically impossible values such as log of a non-positive number - check, for example, that no zero expectations have been given when Poisson modelling;
- numerical difficulties in sampling. Possible solutions include:
- better initial values;
- more informative priors - uniform priors might still be used but with their range restricted to plausible values;
- better parameterisation to improve orthogonality;
- standardisation of covariates to have mean 0 and standard deviation 1.
- can happen if all initial values are equal.
Probit models are particularly susceptible to this problem, i.e. generating undefined real results. If a probit is a stochastic node, it may help to put reasonable bounds on its distribution, e.g.
probit(p[i]) <- delta[i]
delta[i] ~ dnorm(mu[i], tau)I(-5, 5)
This trap can sometimes be escaped from by simply clicking on the update button. The equivalent construction
p[i] <- phi(delta[i])
may be more forgiving.
b) 'index array out of range' - possible reasons include:
- attempting to assign values beyond the declared length of an array;
- if a logical expression is too long to evaluate - break it down into smaller components.
c) 'stack overflow' can occur if there is a recursive definition of a logical node.
d) 'NIL dereference (read)' can occur at compilation in some circumstances when an inappropriate transformation is made, for example an array into a scalar.
e) Trap messages referring to 'DFreeARS' indicate numerical problems with the derivative-free adaptive rejection algorithm used for log-concave distributions. One possibility is to change to "Slice" sampling - see here for details.
The program hangs [top]
This could be due to:
a) a problem that seems to happen with NT - rebooting is a crude way out;
b) interference with other programs running - try to run WinBUGS on its own;
c) a particularly ill-posed model - try the approaches listed above under Trap messages.
Speeding up sampling [top]
The key is to reduce function evaluations by expressing the model in as concise a form as possible. For example, take advantage of the functions provided and use nested indexing wherever possible. Look at the packaged examples and others provided on users' web sites.
Improving convergence [top]
Possible solutions include:
a) better parameterisation to improve orthogonality of joint posterior;
b) standardisation of covariates to have mean 0 and standard deviation 1;
c) use of ordered over-relaxation.
For other problems, try the FAQ pages of the web site and the Classic BUGS manual. Then try mailing us on bugs@mrc-bsu.cam.ac.uk.
Please try and keep the discussion list for modelling issues and problems other than my program won't run!