Online companion for
Marc Kéry (2010) Introduction to WinBUGS for Ecologists. Academic Press, Burlington.

A creed for models, algebra and WinBUGS
To make sense of an observation, everybody needs a model ...
whether he knows it or not.
It is difficult to imagine another method
that so effectively fosters clear thinking about a system
than the use of a model written in the language of algebra.
One of the most transparent ways
of building a model
is by describing it in the BUGS language.

Cover photo: Rosalia alpina, Switzerland, 2006 (T. Marent)
Book description
This book is a very gentle introduction for ecologists to Bayesian analysis
using WinBUGS. It covers the linear model and its extensions to the
generalised linear (GLM) and to the linear and generalised linear mixed models
by way of extensive and fully documented examples with all code shown. All
data sets are simulated in program R ; simulation allows a much greater insight
into data and their analysis than the use of real data sets where truth is
unknown. I believe that when you are able to simulate a data set for a
particular model, then you understand that model. Indeed, one of the nicest
things that somebody has said to me about my book was this: Your book made me
finally understand the linear model and the GLM.
You can get your copy here:
www.amazon.com
For more information about the book,
you can read its Preface
and two sample chapters, chapter 4 and
chapter 15.
Introduction to JAGS for ecologists
Development of software WinBUGS was discontinued back in 2005, but fortunately for ecologists,
the BUGS language lives on in the new software JAGS, Nimble and also OpenBUGS. You can run almost
all the code in the book asis. Some changes are required only for the interface with R.
The following link: Code_Kery2010_with_JAGS.R, displays
a text file that contains all the R and BUGS language code from the book, which lets you run everything
in JAGS, linked to R via the R package jagsUI (Kellner 2019).
Website description
This website contains additional information on the book,
R,
WinBUGS and
JAGS
code
for all examples in the book as well as solutions to the exercises and bonus
material. Later, there will also be a list of errors.
Table of contents
Below is a concise table of contents of the book. You can find the complete
TOC here: Table of Contents
 Foreword by Jim Nichols
 Preface
 Acknowledgements
 Introduction
 Introduction to the Bayesian analysis of a statistical model
 WinBUGS
 A first session in WinBUGS: The "model of the mean"
 Running WinBUGS from R via R2WinBUGS
 Key components of (generalised) linear models: Statistical distributions and the linear predictor
 tTest: Equal and unequal variances
 Normal linear regression
 Normal oneway ANOVA
 Normal twoway ANOVA
 General linear model (ANCOVA)
 Linear mixedeffects model
 Introduction to the Generalised linear model (GLM): Poisson ttest
 Overdispersion and offsets in the GLM
 Poisson ANCOVA
 Poisson mixedeffects model (Poisson GLMM)
 Binomial ttest
 Binomial ANCOVA
 Binomial mixedeffects model (Binomial GLMM)
 Nonstandard GLMMs 1: Siteoccupancy species distribution model
 Nonstandard GLMMs 2: Binomial mixture model for the modeling of abundance
 Conclusions
R/WinBUGS code (for JAGS, see towards the start of the page!)
You will use WinBUGS
called from R
throughout the book with the exception of
chapter 4, where we use WinBUGS as a standalone application for the simplest
example of a linear model: the estimation of the mean of a normal population.
Here, you can download that WinBUGS document
(
The_model_of_the_(normal)_mean.odc)
Text file with all R/WinBUGS code: R_WB_code.txt
Solutions to exercises
There is a series of exercises at the end of most chapters; here are the solutions:
Link to Solutions.txt
The Swiss hare data
This is the only realworld data set you will meet in the book. We deal with
it extensively in the exercises. The Swiss hare data contain replicated counts
of Brown hares (Lepus europaeus: see chapter 13) conducted over 17 years
(19922008) at 56 sites in 8 regions of Switzerland. Replicated means that
each year two counts were conducted during a twoweek period. Sites vary in
area, elevation, and belong to two types of habitat (arable and grassland):
hence, there are both continuous and discrete explanatory variables. Unbounded
counts may be modeled as Poisson random variables with log(area) as an offset,
but we can also treat the observed density (i.e., the ratio of a count to
area) as a normal or the incidence of a density exceeding some threshold as a
binomial random variable. Hence, you can practice with all models shown in
this book and meet features of genuine data sets such as missing values and
other nuisances of real life.
Download text file containing the Swiss hare data.
List of errors and replies to comments
Thank you for pointing out
errors to me at marc_kery@vogelwarte.ch.
I am also grateful for any comments
you might have on the book.
Erratum: (None found yet ...) (Later Link to Erratum.html)
How to present the results from a Bayesian analysis
Somebody pointed out to
me that there is little in my book about the way in which the results from a
Bayesian analysis are presented in a paper. This may be true. I give a very
brief example of this at the end of chapter 4, but in later chapters, this is
not shown any longer in a very explicit manner. I may add a little document
with more explanations (or examples) on that topic later, but for the moment I
simply refer you to any journal article that uses Bayesian modeling. For
instance, you can check out almost all of mine that are in the List of
References of the book.
Information on a similar, but more advanced book published in 2012:
Bayesian Population Analysis
using WinBUGS by Kéry & Schaub
The current book is targeted at ecologists, but the statistical models are
simply general regression models with their ordinary extensions. There are
only two chapters on the kinds of models that ecologists use for more
specialized inference about populations (the last two chapters).
My colleague, Michael Schaub, and I
I have just written a more advanced sequel to this book, which has been
published by Academic Press in 2012. We call it the BPA book. It covers
a fairly comprehensive selection of specialized ecological statistical
models for the analysis of populations using WinBUGS, not unlike the
landmark book by Royle and Dorazio (2008), but in a similar format as
the current book. For more information about our new book, see its full
table of contents:
BPA_TOC.pdf
Workshops
Both the WinBUGS introduction and the more advanced Bayesian population
analysis (BPA) book grew out of workshops that I teach (BPA together with
Michael Schaub). Both workshops last about 5 days. We have taught them
repeatedly in Europe and in the United States. Send me
Marc an email if you're
interested in hosting or attending one.
Acknowledgements
I thank Andy Royle for helping me to fledge as a statistical ecologist and
BUGS programmer, Jim Nichols for teaching me how to be a scientist and for
writing the foreword, Jim Hines
for creating and maintaining this website, and
to my family (Susana and Gabriel) for their love and their patience.
This page last revised: 27March2019