Categorical covariates in JAGS

HOME I've recently been asked about coding categorical covariates in JAGS. You can do it in the usual frequentist manner with dummy variables for all but one of the variables, but JAGS allows other, more easily interpreted ways of coding, especially if the categorical covariate is the only covariate in the model and it is a logistic or log regression. Many of our wildlife models are logistic models under the hood.

In R, the class factor is used for categorical variables. A factor has a levels attribute with the names of the categories, in alphabetical order by default, and the values are stored as integers giving the level number.

### Need a toy example



Royle, J. A. and J. D. Nichols (2003). "Estimating abundance from repeated presence-absence data or point counts." Ecology 84(3): 777-790.

Vehtari A, Gelman A and Gabry J (2016). “Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC.” Statistics and Computing. doi: 10.1007/s11222-016-9696-4 (link).

Updated 27 November 2017 by Mike Meredith