1/ 20 R and RStudio Statistical Analyses Packages R-INLA Bayesian Hierarchical Models Gavin Shaddick, Millie Green, Matthew Thomas University of Bath 6 th -9 th December 2016
1/ 20
R and RStudio Statistical Analyses Packages R-INLA
Bayesian Hierarchical Models
Gavin Shaddick,
Millie Green, Matthew ThomasUniversity of Bath
6th - 9th December 2016
2/ 20
R and RStudio Statistical Analyses Packages R-INLA
IMPLEMENTING BAYESIANMODELS USING R-INLA
3/ 20
R and RStudio Statistical Analyses Packages R-INLA
OUTLINE
R and RStudio
Statistical Analyses
Packages
R-INLA
4/ 20
R and RStudio Statistical Analyses Packages R-INLA
R and RStudio
5/ 20
R and RStudio Statistical Analyses Packages R-INLA
R
6/ 20
R and RStudio Statistical Analyses Packages R-INLA
RSTUDIO
7/ 20
R and RStudio Statistical Analyses Packages R-INLA
Statistical Analyses
8/ 20
R and RStudio Statistical Analyses Packages R-INLA
STATISTICAL ANALYSIS IN R
I R comes with many statistical tools already installedI descriptive statisticsI visualisationI statistical testsI model fitting.
9/ 20
R and RStudio Statistical Analyses Packages R-INLA
Packages
10/ 20
R and RStudio Statistical Analyses Packages R-INLA
CAN R DO MORE?
I The default installation of R has a comprehensive set of tools forstatistical analyses.
I To meet the specific needs of data scientists, many otherstatistical tools are readily available in the form of packages.
I Packages are collections of functions and data.I "During the last decade, the momentum coming from both
academia and industry has lifted R to become the single mostimportant tool for computational statistics, visualisation anddata science."
11/ 20
R and RStudio Statistical Analyses Packages R-INLA
R PACKAGES: EXAMPLES USED IN THIS COURSE
I ggplot2
I raster
I Rmisc
I mgcv
I maptools
I ... many many more!!
12/ 20
R and RStudio Statistical Analyses Packages R-INLA
OTHER R PACKAGES
I A list of R Packages can be seen and downloaded fromhttps://cran.r-project.org
13/ 20
R and RStudio Statistical Analyses Packages R-INLA
R-INLA
14/ 20
R and RStudio Statistical Analyses Packages R-INLA
R-INLA
I The R–INLA package provides a practical implementation ofIntegrated Nested Laplace Approximations (INLA).
I The class of models that can be expressed in this form and thuscan be used with R–INLA is very large and includes, amongstothers, the following:
I Dynamic linear models.I Stochastic volatility models.I Generalised linear (mixed) models.I Generalised additive (mixed) models.I Spline smoothing.I Semi–parametric regression.I Disease mapping.I Log–Gaussian Cox–processes.I Model–based geostatistics.I Spatio–temporal models.I Survival analysis.
15/ 20
R and RStudio Statistical Analyses Packages R-INLA
THE SYNTAX OF R–INLA
I There are three main parts to fitting a model using R–INLA:1. The data.2. Defining the model formula.3. The call to the INLA program.
I The basic syntax of running models in R–INLA is very similar inappearance to that of glm in R and takes the general formformula, data, family but with the addition of thespecification of the nature of the random effects, f().
I For the latter component, common examples includeI f(i, model="iid") (independent)I f(i, model="rw") (random walk of order one)I f(i, model="ar") (autoregressive of order p).
16/ 20
R and RStudio Statistical Analyses Packages R-INLA
FITTING A POISSON REGRESSION MODEL IN R–INLA
I An extension of the standard Poisson model to includelog–normal random effects in the linear predictor
logµl = β0 + β0i + β1Xl + βdXl + εl (1)
where βl represents the effect of exposure, βd is the effect of anarea-level covariate and β0i denotes the random effect for area i.
I The syntax of the R–INLA code to fit this model is very similar tothat of a standard glm in R.
17/ 20
R and RStudio Statistical Analyses Packages R-INLA
FITTING A POISSON REGRESSION MODEL IN R–INLA
18/ 20
R and RStudio Statistical Analyses Packages R-INLA
FITTING A POISSON REGRESSION MODEL IN R–INLA
19/ 20
R and RStudio Statistical Analyses Packages R-INLA
FITTING A POISSON REGRESSION MODEL IN R–INLA
20/ 20
R and RStudio Statistical Analyses Packages R-INLA
FITTING MODELS IN R–INLA
I Future details can be found on the R–INLA webpage:http://www.R-INLA.org.