174 Handbook of Discrete-Valued Time Series
where p
G
(x|θ, y) is a Gaussian approximation to the full conditional of x, p(x|θ, y), obtained
by matching the modal conguration and the curvature at the mode, and x
∗
(θ) is the mode
of the full conditional for x,foragiven θ. Expression (8.20) is equivalent to the Laplace
approximation of a marginal posterior distribution (Tierney and Kadane, 1986), and it is
exact if p(x|y, θ) is Gaussian.
For p(x
i
|θ, y), three options are available, and they vary in terms of speed and accu-
racy. The fastest option, p
G
(x
i
|θ, y), is to use the marginals of the Gaussian approximation
p
G
(x|θ, y), which is already computed when evaluating expression (8.20). The only extra
cost in obtaining p
G
(x
i
|θ, y) is to compute the marginal variances from the sparse precision
matrix of p
G
(x|θ, y), see Rue et al. (2009) for details. The Gaussian approximation often
gives reasonable results, but it may contain errors in the location and/or errors due to its
lack of skewness (Rue and Martino, 2007). The more accurate approach would be to again
use a Laplace approximation, denoted by p
LA
(x
i
|θ, y), with a form similar to (8.20), that is,
p(x, θ, y)
p
LA
(x
i
|θ, y) ∝
p
GG
(x
−i
|x
i
, θ, y)
∗
, (8.21)
x
−i
=x
−i
(x
i
,θ)
where x
−i
represents the vector x with its ith element excluded and p
GG
(x
−i
|x
i
, θ, y) is the
Gaussian approximation to x
−i
|x
i
, θ, y and x
−
∗
i
(x
i
, θ) is the modal conguration. A third
option p
SLA
(x
i
|θ, y), called simplied Laplace approximation, is obtained by doing a Taylor
expansion on the numerator and denominator of (8.21) up to third order, thus correcting
the Gaussian approximation for location and skewness with a much lower cost when com-
pared to p
LA
(x
i
|θ, y). We refer to Rue et al. (2009) for a detailed description of the Gaussian,
Laplace and simplied Laplace, approximations to p(x
i
|θ, y).
Finally, once we have the approximations
p
˜
(θ|y),
p
˜
(x
i
|θ, y) described earlier, the inte-
grals in (8.18) and (8.19) are numerically approximated by discretizing the θ space
through a grid exploration of
p
˜
(θ|y). Details about this grid exploration can be found in
Martins et al. (2013).
8.4.2 R-INLA through Examples
The syntax for the R-INLA package is based on the built-in glm function in R,andabasic
call starts with
formula = y ˜ a + b + a:b + c*d + f(idx1, model1, ...)
+ f(idx2, model2, ...),
where formula describes the structured additive linear predictor η(x). Here, y is the
response variable, the term a + b + a:b + c*d holds similar meaning as in the builtin
glm function in R and is then responsible for the xed effects specication. The f() terms
specify the general Gaussian random effects components of the model. In this case we say
that both idx1 and idx2 are latent building blocks that are combined together to form a
joint latent Gaussian model of interest. Once the linear predictor is specied, a basic call to
t the model with R-INLA takes the following form:
result = inla(formula, data = data.frame(y, a, b, c, d, idx1, idx2),
family = "gaussian").