bayesian hierarchical models - ubc department of …gavin/stepibooknewstyle/course/clapem/... · 1/...

20
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

Upload: phungkiet

Post on 03-May-2018

225 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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

Page 2: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

2/ 20

R and RStudio Statistical Analyses Packages R-INLA

IMPLEMENTING BAYESIANMODELS USING R-INLA

Page 3: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

3/ 20

R and RStudio Statistical Analyses Packages R-INLA

OUTLINE

R and RStudio

Statistical Analyses

Packages

R-INLA

Page 4: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

4/ 20

R and RStudio Statistical Analyses Packages R-INLA

R and RStudio

Page 5: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

5/ 20

R and RStudio Statistical Analyses Packages R-INLA

R

Page 6: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

6/ 20

R and RStudio Statistical Analyses Packages R-INLA

RSTUDIO

Page 7: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

7/ 20

R and RStudio Statistical Analyses Packages R-INLA

Statistical Analyses

Page 8: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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.

Page 9: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

9/ 20

R and RStudio Statistical Analyses Packages R-INLA

Packages

Page 10: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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."

Page 11: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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!!

Page 12: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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

Page 13: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

13/ 20

R and RStudio Statistical Analyses Packages R-INLA

R-INLA

Page 14: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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.

Page 15: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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).

Page 16: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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.

Page 17: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

17/ 20

R and RStudio Statistical Analyses Packages R-INLA

FITTING A POISSON REGRESSION MODEL IN R–INLA

Page 18: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

18/ 20

R and RStudio Statistical Analyses Packages R-INLA

FITTING A POISSON REGRESSION MODEL IN R–INLA

Page 19: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

19/ 20

R and RStudio Statistical Analyses Packages R-INLA

FITTING A POISSON REGRESSION MODEL IN R–INLA

Page 20: Bayesian Hierarchical Models - UBC Department of …gavin/STEPIBookNewStyle/course/clapem/... · 1/ 20 R and RStudioStatistical AnalysesPackagesR-INLA Bayesian Hierarchical Models

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.