# JAGS Model Code

The following three tables describe the distributions, functions and operators used in JAGS model code on this site. For additional information on the JAGS dialect of the BUGS language see the JAGS User Manual.

### JAGS Distributions

Distribution | Description |
---|---|

`dbern(p)` |
Bernoulli where `p` is the probability |

`dbin(p, n)` |
Binomial where `p` is the probability and `n` the number of trials |

`dcat(pi)` |
Categorical where `pi` is a vector of (possibly unnormalized) probabilities |

`ddirch(alpha)` |
Dirichlet where `alpha` is a vector of positive concentration parameters |

`dgamma(a, b)` |
Gamma where `a` is the shape and `b` the rate |

`dlnorm(mu, sd^-2)` |
Log-normal where `mu` is the `log` mean and `sd` the `log` standard deviation |

`dmnorm(mu, Omega)` |
Multivariate normal where `mu` is a k-dimensional vector of the means and `Omega` is a k x k positive definite matrix |

`dnorm(mu, sd^-2)` |
Normal where `mu` is the mean and `sd` the standard deviation |

`dpois(lambda)` |
Poisson where `lambda` is the mean (and the variance) |

`dunif(a, b)` |
Uniform where `a` is the lower limit and `b` the upper limit |

`dwish(R, k)` |
Wishart where `R` is a p x p positive definite matrix and `k` >= p |

### JAGS Functions

Function | Description |
---|---|

`equals(x, y)` |
Test for equality of x and y |

`exp(x)` |
Exponential of x |

`ifelse(x, a, b)` |
If x then a else b |

`inprod(x,y)` |
Inner product of x and y |

`inverse(x)` |
Matrix inverse were x is a symmetric positive deﬁnite matrix |

`length(x)` |
Length of vector x |

`log(x)` |
Natural logarithm of x |

`logit(x)` |
Log-odds of x |

`max(x,y)` |
Maximum of x and y |

`min(x,y)` |
Minimum of x and y |

`phi(x)` |
Standard normal cumulative distribution function for x |

`pnorm(x, mu, sd^-2)` |
Cumulative distribution function for x with a normal distribution with a mean of mu and standard deviation of sd |

`round(x)` |
Round to integer away from 0 |

`step(x)` |
Test for x >= 0 |

`sum(a)` |
Sum of elements of a |

`T(x,y)` |
Truncate distribution so that values lie between x and y |

### JAGS Operators

Operator | Description |
---|---|

`<-` |
Deterministic relationship |

`~` |
Stochastic relationship |

`1:n` |
Vector of integers from 1 to n |

`a[1:n]` |
Subset of first n values in a |

`for (i in 1:n) {...}` |
Repeat … for 1 to n times incrementing i each time |

`x^y` |
Power where x is raised to the power of y |