# Spatial GLMM(s) utilizing the INLA Approximation

## Mannequin setup

• We’ve got a rely end result (deaths and births), in counties over time, and a set of time-constant covariates.
• We’ve got a number of choices within the GLM framework with which to mannequin these information, for instance:

• Binomial – [y_{ij} sim Bin(pi_{ij}) text{: } logit(pi_{ij} ) = beta_{0}+ x’beta_k ]

• Poisson – [y_{ij} sim Pois(lambda_{ij} E_{ij}) text{: } log(lambda_{ij} ) = log(E_{ij}) + beta_{0}+ x’beta_k ]

• Unfavourable Binomial – [y_{ij} sim text{Neg Bin} (mu_{ij}, alpha, E_{ij}) text{: } log(mu_{ij} ) = log(E_{ij}) + beta_{0}+ x’beta_k ]

• Along with numerous zero-inflated variations of those information.

````## `stat_bin()` utilizing `bins = 30`. Choose higher worth with `binwidth`.`
```
````## Warning: Eliminated 1849 rows containing non-finite values (stat_bin).`
```  ````## `stat_bin()` utilizing `bins = 30`. Choose higher worth with `binwidth`.`
```
````## Warning: Eliminated 1849 rows containing non-finite values (stat_bin).`
```  ````## `summarise()` ungrouping output (override with `.teams` argument)`
```  We are able to match these mannequin utilizing the Bayesian framework with INLA.

First, we think about the fundamental GLM for the mortality end result, with out any hierarchical construction. We are able to write this mannequin as a Unfavourable Binomial mannequin, as an example as:

[text{Deaths}_{ij} sim NB(mu_{ij}, gamma)] [mu_{ij} = text{log(E_d)}_{ij} + X’ beta]

INLA will use imprecise Regular priors for the (beta)’s, and we have now different parameters within the mannequin to specify priors for. INLA doesn’t require you to specify all priors, as all parameters have a default prior specification. On this instance, I’ll use a (Gamma(1, .5)) prior for all hierarchical variance phrases.

``````## ## Name:
## c("inla(system = f1, household = "nbinomial", information = last.dat, E = ## E_d, ", " verbose = F, management.compute = record(waic = T), ## management.predictor = record(hyperlink = 1), ", " num.threads = 2)") ## Time used:
## Pre = 0.928, Working = 21.8, Publish = 0.722, Complete = 23.5 ## Fastened results:
## imply sd 0.025quant 0.5quant 0.975quant mode kld
## (Intercept) -5.047 10.723 -26.102 -5.048 15.989 -5.047 0
## scale(pblack) 0.159 0.015 0.130 0.159 0.188 0.159 0
## scale(phisp) -0.025 0.013 -0.050 -0.025 0.001 -0.025 0
## scale(ppov) 0.041 0.015 0.012 0.041 0.070 0.041 0
## yr 0.003 0.005 -0.008 0.003 0.013 0.003 0
## ## Mannequin hyperparameters:
## imply sd 0.025quant
## measurement for the nbinomial observations (1/overdispersion) 0.624 0.009 0.608
## 0.5quant 0.975quant
## measurement for the nbinomial observations (1/overdispersion) 0.624 0.641
## mode
## measurement for the nbinomial observations (1/overdispersion) 0.624
## ## Anticipated variety of efficient parameters(stdev): 5.04(0.001)
## Variety of equal replicates : 2124.92 ## ## Watanabe-Akaike info criterion (WAIC) ...: 114586.38
## Efficient variety of parameters .................: 10.27
## ## Marginal log-Chance: -57331.80 ## Posterior marginals for the linear predictor and
## the fitted values are computed```
```

Plot our noticed vs fitted values  ### Fundamental county stage random intercept mannequin

Now we add fundamental nesting of charges inside counties, with a random intercept time period for every county. This is able to permit there to be heterogeneity within the mortality fee for every county, over and above every county’s noticed traits.

This mannequin can be:

[text{Deaths}_{ij} sim NB(mu_{ij}, gamma)] [mu_{ij} = text{log(E_d)}_{ij} + X’ beta + u_j] [u_j sim text{Normal} (0 , tau_u)]

the place (tau_u) right here is the precision, not the variance and precision = 1/variance. INLA places a log-gamma prior on the the precision by default.

``````f2<-rate~scale(pblack)+scale(phisp)+scale(ppov)+yr+ #mounted results
f(struct, mannequin = "iid",param=c(1,.5)) #random results mod2<-inla(system = f2,information = last.dat,
household = "nbinomial", E = E_d,
management.compute = record(waic=T),
verbose = F) #whole mannequin abstract
abstract(mod2)```
```
``````## ## Name:
## c("inla(system = f2, household = "nbinomial", information = last.dat, E = ## E_d, ", " verbose = F, management.compute = record(waic = T), ## management.predictor = record(hyperlink = 1), ", " num.threads = 2)") ## Time used:
## Pre = 0.571, Working = 160, Publish = 1.36, Complete = 162 ## Fastened results:
## imply sd 0.025quant 0.5quant 0.975quant mode kld
## (Intercept) -2.824 10.758 -23.945 -2.824 18.279 -2.824 0
## scale(pblack) 0.158 0.015 0.128 0.158 0.189 0.158 0
## scale(phisp) -0.041 0.014 -0.069 -0.041 -0.013 -0.041 0
## scale(ppov) 0.044 0.015 0.014 0.044 0.074 0.044 0
## yr 0.001 0.005 -0.009 0.001 0.012 0.001 0
## ## Random results:
## Identify Mannequin
## struct IID mannequin
## ## Mannequin hyperparameters:
## imply sd 0.025quant
## measurement for the nbinomial observations (1/overdispersion) 0.627 0.009 0.609
## Precision for struct 50.626 7.005 38.292
## 0.5quant 0.975quant
## measurement for the nbinomial observations (1/overdispersion) 0.627 0.644
## Precision for struct 50.138 65.780
## mode
## measurement for the nbinomial observations (1/overdispersion) 0.626
## Precision for struct 49.174
## ## Anticipated variety of efficient parameters(stdev): 125.34(15.33)
## Variety of equal replicates : 85.47 ## ## Watanabe-Akaike info criterion (WAIC) ...: 114610.09
## Efficient variety of parameters .................: 66.26
## ## Marginal log-Chance: -57375.58 ## Posterior marginals for the linear predictor and
## the fitted values are computed```
```

#### Marginal Distributions of hyperparameters

We are able to plot the posterior marginal of the hyperparameter on this mannequin, on this case (sigma_u = 1/tau_u)

``````## low excessive
## stage:0.95 0.01491462 0.02565338```
```  ``````last.dat\$fitted_m2<-mod2\$abstract.fitted.values\$imply p1<-final.dat%>%
filter(yr%in%c(2000))%>%
mutate(qrr=reduce(fitted_m2, breaks = quantile(last.dat\$fitted_m2, p=seq(0,1,size.out = 6)), embrace.lowest = T))%>%
ggplot()+geom_sf(aes(fill=qrr))+scale_colour_brewer(palette = "RdBu" )+scale_fill_brewer(palette = "RdBu", na.worth="gray")+guides(fill=guide_legend(title="Relative Threat Quartile"))+ggtitle(label="Relative Threat Quartile - IID Mannequin, 2000")+coord_sf(crs = 7603) p2<-final.dat%>%
filter(yr%in%c(2007))%>%
mutate(qrr=reduce(fitted_m2, breaks = quantile(last.dat\$fitted_m2, p=seq(0,1,size.out = 6)), embrace.lowest = T))%>%
ggplot()+geom_sf(aes(fill=qrr))+scale_colour_brewer(palette = "RdBu" )+scale_fill_brewer(palette = "RdBu", na.worth="gray")+guides(fill=guide_legend(title="Relative Threat Quartile"))+ggtitle(label="Relative Threat Quartile - IID Mannequin, 2007")+coord_sf(crs = 7603) library(gridExtra)```
```
````## ## Attaching package deal: 'gridExtra'`
```
``````## The next object is masked from 'package deal:dplyr':
## ## mix```
```  ``````## TableGrob (2 x 1) "prepare": 2 grobs
## z cells title grob
## 1 1 (1-1,1-1) prepare gtable[layout]
## 2 2 (2-2,1-1) prepare gtable[layout]```
```

### BYM Mannequin

Mannequin with spatial correlation – Besag, York, and Mollie (1991) mannequin and temporal heterogeneity [text{Deaths}_{ij} sim NB(mu_{ij}, gamma)] [mu_{ij} = text{log(E_d)}_{ij} + X’ beta + u_j + v_j + gamma_t]

Which has two random results, one an IID random impact and the second a spatially correlated random impact, specified as a conditionally auto-regressive prior for the (v_j)’s. That is the Besag mannequin:

[v_j|v_{neq j},simtext{Normal}(frac{1}{n_i}sum_{isim j}v_j,frac{1}{n_itau})] and (u_j) is an IID regular random impact, (gamma_t) can be given an IID Regular random impact specification, and there at the moment are three hyperparameters, (tau_u) and (tau_v) and (tau_{gamma}) and every are given log-gamma priors.

For the BYM mannequin we should specify the spatial connectivity matrix within the random impact.

``````#last.dat\$year_c<-final.dat\$yr - 2004
f3<-rate~scale(pblack)+scale(phisp)+scale(ppov)+
f(struct, mannequin = "bym", constr = T, scale.mannequin = T, graph = H,param=c(1,.5))+
f(yr, mannequin="iid",param=c(1,.5)) #temporal random impact mod3<-inla(system = f3,information = last.dat,
household = "nbinomial", E = E_d,
management.compute = record(waic=T),
verbose = F,
management.predictor = record(hyperlink=1)) #whole mannequin abstract
abstract(mod3)```
```
``````## ## Name:
## c("inla(system = f3, household = "nbinomial", information = last.dat, E = ## E_d, ", " verbose = F, management.compute = record(waic = T), ## management.predictor = record(hyperlink = 1), ", " num.threads = 2)") ## Time used:
## Pre = 0.737, Working = 138, Publish = 1.26, Complete = 140 ## Fastened results:
## imply sd 0.025quant 0.5quant 0.975quant mode kld
## (Intercept) 0.115 0.129 -0.145 0.115 0.374 0.115 0
## scale(pblack) 0.157 0.016 0.126 0.158 0.189 0.158 0
## scale(phisp) -0.039 0.016 -0.069 -0.039 -0.007 -0.040 0
## scale(ppov) 0.043 0.016 0.012 0.043 0.075 0.043 0
## ## Random results:
## Identify Mannequin
## struct BYM mannequin
## yr IID mannequin
## ## Mannequin hyperparameters:
## imply sd
## measurement for the nbinomial observations (1/overdispersion) 0.627 0.009
## Precision for struct (iid element) 51.094 7.099
## Precision for struct (spatial element) 1974.289 1903.577
## Precision for yr 8.760 4.130
## 0.025quant 0.5quant
## measurement for the nbinomial observations (1/overdispersion) 0.609 0.627
## Precision for struct (iid element) 38.602 50.591
## Precision for struct (spatial element) 174.447 1425.658
## Precision for yr 2.885 8.075
## 0.975quant mode
## measurement for the nbinomial observations (1/overdispersion) 0.644 0.628
## Precision for struct (iid element) 66.447 49.595
## Precision for struct (spatial element) 7055.730 496.592
## Precision for yr 18.742 6.583
## ## Anticipated variety of efficient parameters(stdev): 133.75(15.30)
## Variety of equal replicates : 80.09 ## ## Watanabe-Akaike info criterion (WAIC) ...: 114605.76
## Efficient variety of parameters .................: 69.81
## ## Marginal log-Chance: -56934.15 ## Posterior marginals for the linear predictor and
## the fitted values are computed```
```  ``````m3a<- inla.tmarginal(
operate(x) (1/x),
mod3\$marginals.hyperpar\$`Precision for struct (iid element)`)
m3b<- inla.tmarginal(
operate(x) (1/x),
mod3\$marginals.hyperpar\$`Precision for struct (spatial element)`)
m3c<- inla.tmarginal(
operate(x) (1/x),
mod3\$marginals.hyperpar\$`Precision for yr`) plot(m3a, kind="l", principal=c("Posterior distibution for between county variance", "- BYM mannequin -"), xlim=c(0, .2), ylim=c(0, 300))
strains(m3b, col="purple")
strains(m3c, col="inexperienced")
legend("topright", legend=c("BYM IID", "BYM Spatial", "12 months"), col=c(1, "purple", "inexperienced"), lty=c(1,1,1))```
```  ``````## low excessive
## stage:0.95 0.01475866 0.02544088```
```
``````## low excessive
## stage:0.95 0.00005416961 0.003970123```
```
``````## low excessive
## stage:0.95 0.03927999 0.2945931```
```

This means very low spatially correlated variance in these information.

## Exceedence chances

In Bayesian spatial fashions which might be centered on an epidemiological kind of end result, it is not uncommon to look at the info for spatial clustering. A method to do that is to look at the clustering within the relative threat from one in every of these GLMM fashions. For example if (theta) is the relative threat [theta = exp(beta_0 + beta_1*x_1 + u_j)] from one in every of our Unfavourable binomial fashions above. We are able to use the posterior marginals of the relative threat to ask (theta gt theta^*) the place (theta^*) is a selected stage of extra threat, say 50% additional or (theta > 1.25). If the density, or (textual content{Pr}(theta gt theta^*)) is excessive, then there may be proof that the surplus threat will not be solely excessive, however considerably excessive.

To get the exceedence chances from one in every of our fashions, we will use the `inla.pmarginal()` operate to ask if (textual content{Pr}(theta gt theta^*))  So, we see plenty of events the place the exceedence likelihood is larger than .9. We are able to visualize these in a map.

``````last.dat\$exceedprob<-inlaprob last.dat%>%
filter(yr%in%c(2007))%>%
mutate(qrr=reduce(exceedprob, breaks = c(0, .5, .9, .95, .99, 1), embrace.lowest = T))%>%
ggplot()+geom_sf(aes(fill=qrr))+scale_colour_brewer(palette = "Blues" )+scale_fill_brewer(palette = "Blues", na.worth="gray")+guides(fill=guide_legend(title=""))+ggtitle(label=expression(paste("Exceedence Likelihood Relative Threat ","Pr( ",theta," >1.25"," ) - 2007") ))+coord_sf(crs = 7603)```
```  ``````#library(mapview) #map1<-final.dat%>%
# filter(yearpercentinpercentc(2007))%>%
# mutate(qrr=reduce(exceedprob, breaks = c(0, .5, .9, .95, .99, 1), embrace.lowest = T)) #clrs <- colorRampPalette(brewer.pal(6, "Blues"))
#mapView(as(map1, "Spatial"), zcol="qrr", legend=T, col.areas=clrs, map.sorts="OpenStreetMap")```
```

Which reveals a number of areas of the south the place threat the toddler mortality fee is signficantly larger than the nationwide fee, with excessive posterior likelihood.