---
title: "INLA (contributed functions)"
author: "Gianluca Baio"
date: 2018-03-19T22:16:14-05:00
publishdate: 2020-09-22
categories: ["Bayesian statistics"]
weight: 60 
toc: false
#links:
#  - icon_pack: fab
#    icon: github
#    name: Code
#    url: 'https://github.com/giabaio/BCEA'
#  - name: "Go to project site"
#    url: https://gianluca.statistica.it/book/bcea
---


## Integrated Nested Laplace Approximation
`R-INLA` is an R package that implements *Integrated Nested Laplace Approximation* (INLA), a method to perform approximate Bayesian analysis for a wide class of model specifications, including hierarchical regression models and spatial or spatio-temporal models. 

The idea underlying INLA is that, instead of performing computation for the posterior or predictive distributions using MCMC (which is generally very effective, but can be very computationally intensive, especially for complex models or very large datasets), in a specific class of models in which the prior distribution for the (vector of) parameter(s) is characterised by Gaussian Random Markov Fields, these tasks can be performed using approximations based on Laplace methods. This in turn produces reliable inference with massive improvements in computational time.

The papers linked here give detailed information on INLA. This is a tutorial on INLA for spatio- and spatio-temporal models (which I co-wrote). This is a presentation I prepared (drawing on material by Håvard Rue), for the Bayes Pharma 2013 workshop, in Rotterdam.

## `inla.contrib.sd`
I have written a function `inla.contrib.sd`, which can be used to express the uncertainty in the structured ("random") effects of an INLA model in terms of the standard deviation, instead of the precision (which INLA gives by default - see [here](/blog/2012/09/inla-functions-continued.html) and [here](/blog/2012/09/inla-functions-yet-again.html) for a couple of entries on the blog on this). 

<br><br>
`inla.contrib.sd` is available in the latest development version of `R-INLA`. Assuming that the package is installed, this version can be obtained by typing 
```
inla.upgrade(testing=TRUE)
```
in the R session.

<br><br>
Given a the output of the call to the `inla` function (which uses INLA to fit the model specified by the user), say the R object `m`, it is possible to run 
```
s <- inla.contrib.sd(m)
```
to obtain an object `s` containing the following elements
- `s$hyper`: a table with the summary of the standard deviations for the structured effects
- `s$samples`: the simulated values from the posterior distributions on the standard deviation scale, which can be used for example to draw a histogram or other summaries

Currently, `inla.contrib.sd` only works for hierarchical models (i.e. not for spatially or spatio-temporally structured models)
<br><br>

:::: {.g-col-12}
::: {.last-updated}
Last updated: `r paste(lubridate::day(Sys.Date()),lubridate::month(Sys.Date(),abbr=FALSE,label=TRUE),lubridate::year(Sys.Date()))`
:::
::::
