Disease Mapping using R

North Carolina SIDS data

Calculation of the Standardised Mortality Ratios’s (SMR)

library(spdep)
## Warning: package 'spdep' was built under R version 3.3.1
## Loading required package: sp
## Loading required package: Matrix
data(nc.sids)

nc.sids$NWPROP74<-nc.sids$NWBIR74/nc.sids$BIR74
nc.sids$NWPROP79<-nc.sids$NWBIR79/nc.sids$BIR79

r74<-sum(nc.sids$SID74)/sum(nc.sids$BIR74)
nc.sids$EXP74<-r74*nc.sids$BIR74
nc.sids$SMR74<-nc.sids$SID74/nc.sids$EXP74

r79<-sum(nc.sids$SID79)/sum(nc.sids$BIR79)
nc.sids$EXP79<-r79*nc.sids$BIR79
nc.sids$SMR79<-nc.sids$SID79/nc.sids$EXP79

ncglm74<-glm(SID74~offset(log(EXP74))+NWPROP74, data=nc.sids, family="poisson")
ncglm79<-glm(SID79~offset(log(EXP79))+NWPROP79, data=nc.sids, family="poisson")

Importing shapefile

The following code shows how to read the SIDS data shapefile into the R environment and also shows the output of the SMR’s and the corresponding Relative Risks are calculated.

library(maptools)
## Checking rgeos availability: TRUE
#Read North Carolina county map
nc.sidsmap <- readShapePoly(system.file("etc/shapes/sids.shp",
   package="spdep")[1], ID="FIPSNO")

#Compute SMR
nc.sidsmap$SMR74<-nc.sids$SMR74
nc.sidsmap$RR74<-exp(coefficients(ncglm74)[1]+coefficients(ncglm74)[2]*nc.sids$NWPROP74)
nc.sidsmap$SMR79<-nc.sids$SMR79
nc.sidsmap$RR79<-exp(coefficients(ncglm79)[1]+coefficients(ncglm79)[2]*nc.sids$NWPROP79)

Map of the SMR and RR

library(RColorBrewer)
print(spplot(nc.sidsmap, c("SMR74", "RR74", "SMR79", "RR79"),
   at=c(0, .5, .75, .9, 1.1, 1.25, 1.5, 4.8),
   col.regions=brewer.pal(7, "Oranges") ) )

Probability Mapping

nc.sidsmap$Observed<-nc.sidsmap$SID74
nc.sidsmap$Expected<-nc.sids$EXP74

nc.sidsmap$NWPROP<-nc.sids$NWBIR74/nc.sids$BIR74


nc.sidsmap$SMR<-nc.sidsmap$Observed/nc.sidsmap$Expected

nc.sidsmap$PPOIS<-ppois(nc.sidsmap$Observed, 
   nc.sidsmap$Expected, lower.tail =FALSE)

Probability Map

print(spplot(nc.sidsmap, "PPOIS"))

Empirical Bayes Estimate

eb1 <- EBest(nc.sidsmap$Observed,nc.sidsmap$Expected)
unlist(attr(eb1, "parameters"))
##       a       b 
## 3.46409 1.00000
nc.sidsmap$EB_mm <-eb1$estmm
library(DCluster)
## Warning: package 'DCluster' was built under R version 3.3.2
## Loading required package: boot
## Loading required package: MASS
res <- empbaysmooth(nc.sidsmap$Observed,nc.sidsmap$Expected)
unlist(res[2:3])
##        nu     alpha 
## 0.4764114 0.2185116
nc.sidsmap$EB_ml <- res$smthrr
eb2 <- EBlocal(nc.sidsmap$Observed, nc.sidsmap$Expected, neigh)
nc.sidsmap$EB_mm_local <- eb2$est

Map of the EB estimates

print(spplot(nc.sidsmap, c("SMR", "EB_ml", "EB_mm", "EB_mm_local")) )

GLM(Intercept only models)

base.glm <- glm(Observed ~ 1 + offset(log(Expected)), data = nc.sidsmap,
   family = poisson())
base.glmQ <- glm(Observed ~ 1 + offset(log(Expected)), data = nc.sidsmap,
   family = quasipoisson())

library(MASS)
base.nb <- glm.nb(Observed ~ 1 + offset(log(Expected)), data = nc.sidsmap)

Test for overdispersion

test.nb.pois(base.nb, base.glm)
## 
##  Likelihood ratio test for overdispersion
## 
## data:  base.nb : base.glm
## LR = 904.02, = 1, p-value < 2.2e-16
## sample estimates:
##       zscore p.mayor.modZ 
## 3.6175325718 0.0002974249
DeanB(base.glm)
## 
##  Dean's P_B test for overdispersion
## 
## data:  base.glm
## P_B = 72.12, p-value < 2.2e-16
## alternative hypothesis: greater

Adding covariates

nc.sidsmap.glm <- glm(Observed ~ offset(log(Expected))+NWPROP,
   data = nc.sidsmap, family = poisson())

nc.sidsmap.glmQ <- glm(Observed ~ offset(log(Expected))+NWPROP,
   data = nc.sidsmap, family = quasipoisson())

nc.sidsmap.nb <- glm.nb(Observed ~ offset(log(Expected))+NWPROP,
   data = nc.sidsmap)
unlist(summary(nc.sidsmap.nb)[20:21])
## NULL
anova(base.nb, nc.sidsmap.nb)
## Likelihood ratio tests of Negative Binomial Models
## 
## Response: Observed
##                            Model     theta Resid. df    2 x log-lik.
## 1      1 + offset(log(Expected)) 0.5920218        99       -642.0286
## 2 offset(log(Expected)) + NWPROP 0.6032657        98       -640.2443
##     Test    df LR stat.   Pr(Chi)
## 1                                
## 2 1 vs 2     1 1.784342 0.1816171
summary(nc.sidsmap.nb)
## 
## Call:
## glm.nb(formula = Observed ~ offset(log(Expected)) + NWPROP, data = nc.sidsmap, 
##     init.theta = 0.6032657263, link = log)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.3681  -1.1713  -0.5126   0.2832   2.1313  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   1.0151     0.2440    4.16 3.19e-05 ***
## NWPROP       -0.8531     0.6561   -1.30    0.193    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Negative Binomial(0.6033) family taken to be 1)
## 
##     Null deviance: 118.54  on 99  degrees of freedom
## Residual deviance: 116.74  on 98  degrees of freedom
## AIC: 646.24
## 
## Number of Fisher Scoring iterations: 1
## 
## 
##               Theta:  0.6033 
##           Std. Err.:  0.0878 
## 
##  2 x log-likelihood:  -640.2440

Tests for overdispersion

DeanB(base.glm)
## 
##  Dean's P_B test for overdispersion
## 
## data:  base.glm
## P_B = 72.12, p-value < 2.2e-16
## alternative hypothesis: greater
DeanB(nc.sidsmap.glm)
## 
##  Dean's P_B test for overdispersion
## 
## data:  nc.sidsmap.glm
## P_B = 71.641, p-value < 2.2e-16
## alternative hypothesis: greater

Residuals

nc.sidsmap$base_glm_rst <- rstandard(base.glm)
nc.sidsmap$base_glmQ_rst <- rstandard(base.glmQ)
nc.sidsmap$base_nb_rst <- rstandard(base.nb)
nc.sidsmap$COV_glm_rst <- rstandard(nc.sidsmap.glm)
nc.sidsmap$COV_glmQ_rst <- rstandard(nc.sidsmap.glmQ)
nc.sidsmap$COV_nb_rst <- rstandard(nc.sidsmap.nb)

Map of the residuals resulted from the models

print(spplot(nc.sidsmap,
   c("base_glm_rst", "base_glmQ_rst", "base_nb_rst",
   "COV_glm_rst", "COV_glmQ_rst", "COV_nb_rst"))
)