Disease risk modelling and visualization using R Paula Moraga - - PowerPoint PPT Presentation

disease risk modelling and visualization using r
SMART_READER_LITE
LIVE PREVIEW

Disease risk modelling and visualization using R Paula Moraga - - PowerPoint PPT Presentation

Disease risk modelling and visualization using R Paula Moraga useR! 2018 Brisbane, 10 July 2018 1/51 Outline Introduction to disease mapping Tutorials Tutorial: areal data Tutorial: geostatistical data Presentations options: interactive


slide-1
SLIDE 1

Disease risk modelling and visualization using R

Paula Moraga

useR! 2018 Brisbane, 10 July 2018

1/51

slide-2
SLIDE 2

Outline

Introduction to disease mapping Tutorials Tutorial: areal data Tutorial: geostatistical data Presentations options: interactive dashboards and Shiny apps SpatialEpiApp Shiny Tutorial: Shiny

2/51

slide-3
SLIDE 3

Introduction to disease mapping

3/51

slide-4
SLIDE 4

John Snow’s map of cholera deaths in Soho, London, 1854

4/51

slide-5
SLIDE 5

Disease mapping

Disease maps help understand the spatial patterns of disease and its

  • determinants. This information can guide decision makers and

programme managers to better allocate limited resources and to design strategies for disease prevention and control

5/51

slide-6
SLIDE 6

Types of spatial data

  • 1. Areal data
  • 2. Geostatistical data
  • 3. Point patterns

Moraga and Lawson 2012 Moraga et al. 2015 Moraga and Montes 2011 6/51

slide-7
SLIDE 7

Modelling

  • Disease risk predictions are based on the observed disease

cases, the number of individuals at risk, and risk factors information such as demographic and environmental factors

  • Models describe the variability in the response variable as a

function of the risk factors covariates and random effects to account for unexplained variability

7/51

slide-8
SLIDE 8

Areal data

Moraga and Lawson 2012 8/51

slide-9
SLIDE 9

Areal data

Disease risk is often estimated by the Standardized Mortality Ratio: SMRi = Yi Ei

  • Yi number of observed cases in area i
  • Ei number of expected cases in area i (number expected cases

if area had the same disease rate as the standard population)

  • SMRi > 1 (< 1): more (fewer) cases observed than expected
  • Expected cases calculated using indirect standardization

Ei =

m

  • j=1

r(s)

j n(i) j

  • r(s)

j

disease rate in strata j in standard population = (number disease cases)/(population) in strata j in standard pop

  • n(i)

j

population in strata j in area i

  • strata j can indicate age group, sex, etc

9/51

slide-10
SLIDE 10

Areal data

  • SMRs may be misleading and insufficiently reliable in areas

with small populations

  • In contrast, model-based approaches enable to incorporate

covariates and borrow information from neighboring areas to improve local estimates, resulting in the smoothing of extreme rates based on small sample sizes

10/51

slide-11
SLIDE 11

Areal data

Model to estimate disease risks θi in areas i = 1, . . . , n Yi|θi ∼ Po(Ei × θi), log(θi) = z′

iβ + ui + vi

  • ui is an structured spatial effect to account for the spatial

dependence between relative risks (areas that are close show more similar risk than areas that are not close)

  • vi is an unstructured spatial effect to account for independent

area-specific noise

11/51

slide-12
SLIDE 12

Geostatistical data

Moraga et al. 2015 12/51

slide-13
SLIDE 13

Geostatistical data

Yi|P(xi) ∼ Binomial(Ni, P(xi)), logit(P(xi)) = z′

iβ + S(xi) + vi

Risk factors covariates

(e.g. temperature, precipitation, vegetation, etc)

NASA Earth Observations

Gaussian Random Field

13/51

slide-14
SLIDE 14

Coordinate Reference Systems (CRS)

1 unprojected or geographic: Latitude/Longitude for

referencing location on the ellipsoid Earth

2 projected: Easting/Northing for referencing location on

2-dimensional representation of Earth. Common projection: Universal Transverse Mercator (UTM)

14/51

slide-15
SLIDE 15

Tutorials

15/51

slide-16
SLIDE 16

Install R packages

install.packages(c("dplyr", "ggplot2", "leaflet", "geoR", "rgdal", "raster", "sp", "spdep", "SpatialEpi", "SpatialEpiApp")) install.packages("INLA", repos = "https://inla.r-inla-download.org/R/stable", dep = TRUE)

16/51

slide-17
SLIDE 17

Tutorial: areal data

17/51

slide-18
SLIDE 18

Areal data. Lung cancer in Pennsylvania

https://paula-moraga.github.io/tutorial-areal-data/

18/51

slide-19
SLIDE 19

Tutorial: geostatistical data

19/51

slide-20
SLIDE 20

Geostatistical data. Malaria in The Gambia

https://paula-moraga.github.io/tutorial-geostatistical-data/

20/51

slide-21
SLIDE 21

Presentations options: interactive dashboards and Shiny apps

21/51

slide-22
SLIDE 22

Interactive dashboards with flexdashboard

  • https://rmarkdown.rstudio.com/flexdashboard/
  • Uses R Markdown to publish a group of related data

visualizations as a dashboard

  • Components that can be included include plots, tables, value

boxes and htmlwidgets

22/51

slide-23
SLIDE 23

Layout

23/51

slide-24
SLIDE 24

Example

https://rmarkdown.rstudio.com/flexdashboard/examples.html

24/51

slide-25
SLIDE 25

Interactive Shiny web applications

  • https://shiny.rstudio.com/
  • Shiny is a web application framework for R that enables to

build interactive web applications

25/51

slide-26
SLIDE 26

SpatialEpiApp

26/51

slide-27
SLIDE 27

R package SpatialEpiApp

  • Shiny web application that allows to visualize spatial and

spatio-temporal disease data, estimate disease risk and detect clusters

  • Risk estimates by fitting Bayesian models with INLA
  • Detection of clusters by using the scan statistics in SaTScan

Launch SpatialEpiApp: install.packages("SpatialEpiApp") library(SpatialEpiApp) run_app()

27/51

slide-28
SLIDE 28

Data entry

28/51

slide-29
SLIDE 29

Interactive

29/51

slide-30
SLIDE 30

Maps

30/51

slide-31
SLIDE 31

Clusters

31/51

slide-32
SLIDE 32

Report

32/51

slide-33
SLIDE 33

Shiny

33/51

slide-34
SLIDE 34

Shiny

  • Shiny is a web application framework for R that enables to

build interactive web applications

  • https://shiny.rstudio.com/

34/51

slide-35
SLIDE 35

Examples

https://shiny.rstudio.com/gallery/single-file-shiny-app.html

35/51

slide-36
SLIDE 36

Examples

https://shiny.rstudio.com/gallery/telephones-by-region.html

36/51

slide-37
SLIDE 37

Structure of a Shiny App

A Shiny app is a directory that contains an R file called app.R. app.R has three components:

  • user interface object (ui) which controls the layout and

appearance of the app

  • server() function with the instructions to build the objects

displayed in the ui

  • call to shinyApp() that creates the Shiny app from the

ui/server pair

37/51

slide-38
SLIDE 38

Content app.R

# define user interface object ui <- fluidPage( ) # define server() function server <- function(input, output){ } # call to shinyApp() which returns the Shiny app shinyApp(ui = ui, server = server) Save app.R inside the appdir directory. Launch the app: library(shiny) runApp("appdir_path")

38/51

slide-39
SLIDE 39

Inputs

39/51

slide-40
SLIDE 40

Outputs

  • Plots, tables, texts, images

40/51

slide-41
SLIDE 41

Inputs, outputs and reactivity

  • Inputs: we can interact with the app by modifying their values
  • Outputs: objects we want to show in the app

ui <- fluidPage( *Input(inputId = myinput, label = mylabel, ...) *Output(outputId = myoutput, ...) ) server <- function(input, output){

  • utput$myoutput <- render*({

# code to build the output. # If it uses an input value (input$myinput), # the output will be rebuilt whenever # the input value changes })}

41/51

slide-42
SLIDE 42

Inputs, outputs and reactivity

42/51

slide-43
SLIDE 43

HTML widgets

Interactive web visualizations using JavaScript http://www.htmlwidgets.org/

43/51

slide-44
SLIDE 44

Leaflet

http://rstudio.github.io/leaflet/

44/51

slide-45
SLIDE 45

Dygraphs

http://rstudio.github.io/dygraphs

45/51

slide-46
SLIDE 46

DataTables

http://rstudio.github.io/DT/

46/51

slide-47
SLIDE 47

Options to share a Shiny app

1 Share R scripts with other users

  • need R

library(shiny) runApp("appdir_path")

2 Host app as a web page at its own URL

  • do not need R
  • app can be navigated through the internet with a web browser
  • host apps on own servers or using one of the ways RStudio
  • ffers such as shinyapps.io and Shiny Server

https://paulamoraga.shinyapps.io/spatialepiapp/

47/51

slide-48
SLIDE 48

Tutorial: Shiny

48/51

slide-49
SLIDE 49

Tutorial: Shiny

https://paula-moraga.github.io/tutorial-shiny-spatial/

49/51

slide-50
SLIDE 50

References

  • Paula Moraga. SpatialEpiApp: A Shiny Web Application for

the analysis of Spatial and Spatio-Temporal Disease Data, (2017), Spatial and Spatio-temporal Epidemiology, 23:47-57

  • Winston Chang, Joe Cheng, JJ Allaire, Yihui Xie and Jonathan

McPherson (2017). shiny: Web Application Framework for R. https://CRAN.R-project.org/package=shiny

  • Barbara Borges and JJ Allaire (2017). flexdashboard: R

Markdown Format for Flexible Dashboards. https://CRAN.R-project.org/package=flexdashboard

50/51

slide-51
SLIDE 51

Thanks!

https://Paula-Moraga.github.io Twitter @_PaulaMoraga_

51/51