Creating Database only with summer months

villes_s<-list()

for(i in 1:length(villes)) {
  villes_s[[i]]<-villes[[i]][villes[[i]]$saison=="summer",]
  villes_s[[i]]$temps <- ave(villes_s[[i]]$time,villes_s[[i]]$annee,  FUN = seq_along)
}

names(villes_s)<-cities

## table for month to check to have only summer month
for (i in 1:length(villes)){
print(table(villes_s[[i]]$mois))
}
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0 
## 
##   1   2   3   4   5   6   7   8   9  10  11  12 
##   0   0   0   0   0 540 558 558 540   0   0   0

Creating Heat Wave variable

trshld95<-c()

for (i in 1:length(villes_s)){
  trshld95[i]<-quantile(villes_s[[i]]$tempmax, probs=c(0.95),na.rm=TRUE)
  villes_s[[i]]$heat_wave<-0
  villes_s[[i]]$heat_wave[which(villes_s[[i]]$tempmax > trshld95[i])]<- 1 
}

 

Number of Heat Wave for each city:

Heat wave=0 Heat wave=1
bm 2087 109
bordeaux 2087 109
clermont 2088 108
dijon 2088 108
grenoble 2086 110
lehavre 2088 108
lille 2087 109
lyon 2087 109
marseille 2093 103
montpellier 2089 107
nancy 2086 110
nantes 2087 109
nice 2088 108
paris 2090 106
rennes 2089 107
rouen 2089 107
strasbourg 2086 110
toulouse 2086 110

Analysis

Model for Mortality with only Heat Wave variable

estim <- matrix(NA, nrow = 18, ncol = 5)
colnames(estim) <- c("Ville","Coefficient HW","SE","2.5% CI", "97.5% CI")
mod<-list()


# Model Loop 

for(i in 1:length(villes_s)) {
  mod[[i]]<-glm(nocc_tot~heat_wave+ns(time,df=round(8*length(time)/365.25))+Jours+Vacances+hol,data=villes_s[[i]],family=quasipoisson)
  est<-summary(mod[[i]])
  estim[i, 1] <- as.character(cities[[i]])
  estim[i, 2] <- exp(est$coefficients[2])
  estim[i, 3] <- exp(summary(mod[[i]])$coefficients[, 2][2])
  estim[i, 4:5]<-exp(confint(mod[[i]])[2,])
  }
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
tab_estim<-estim
tab_estim[,2:5]<-round(as.numeric(tab_estim[,2:5]), digits = 4)

kable(tab_estim, align = "rcccc")%>%kable_styling()%>%
  column_spec(1, bold = T, border_right = T)
Ville Coefficient HW SE 2.5% CI 97.5% CI
bm 1.0998 1.0408 1.0161 1.1884
bordeaux 1.259 1.0321 1.1828 1.3388
clermont 1.1749 1.0479 1.0709 1.2865
dijon 1.1768 1.0521 1.0642 1.2986
grenoble 1.1243 1.0408 1.039 1.2152
lehavre 1.0722 1.0485 0.976 1.1751
lille 1.1451 1.0242 1.0923 1.1997
lyon 1.2046 1.0281 1.1406 1.2714
marseille 1.0981 1.0258 1.0443 1.1541
montpellier 0.9996 1.0468 0.913 1.0922
nancy 1.0989 1.0434 1.0103 1.1934
nantes 1.1759 1.0363 1.0959 1.2601
nice 1.0662 1.0332 0.9995 1.1362
paris 1.3646 1.0191 1.3148 1.4158
rennes 1.1642 1.0574 1.0421 1.2968
rouen 1.2218 1.0345 1.1424 1.3051
strasbourg 1.2515 1.0368 1.1654 1.3426
toulouse 1.0892 1.0339 1.0198 1.1621

 

Model for Mortality with Heat Wave variable and Ozone

estim2 <- matrix(NA, nrow = 18, ncol = 5)
colnames(estim2) <- c("Ville","Coefficient HW","SE","2.5% CI", "97.5% CI")

estim2_o3 <- matrix(NA, nrow = 18, ncol = 5)
colnames(estim2_o3) <- c("Ville","Coefficient O3","SE","2.5% CI", "97.5% CI")

mod2<-list()


# Model Loop 

for(i in 1:length(villes_s)) {
  mod2[[i]]<-glm(nocc_tot~heat_wave+o3+ns(time,df=round(8*length(time)/365.25))+Jours+Vacances+hol,data=villes_s[[i]],family=quasipoisson)
  est2<-summary(mod2[[i]])
  estim2[i, 1] <- as.character(cities[[i]])
  estim2[i, 2] <- exp(est2$coefficients[2])
  estim2[i, 3] <- exp(summary(mod2[[i]])$coefficients[, 2][2])
  estim2[i, 4:5]<-exp(confint(mod2[[i]])[2,])
  estim2_o3[i, 1] <- as.character(cities[[i]])
  estim2_o3[i, 2] <- exp(est2$coefficients[3])
  estim2_o3[i, 3] <- exp(summary(mod2[[i]])$coefficients[, 2][3])
  estim2_o3[i, 4:5]<-exp(confint(mod2[[i]])[3,])
  }
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
tab_estim2<-estim2
tab_estim2[,2:5]<-round(as.numeric(tab_estim2[,2:5]), digits = 4)


kable(tab_estim2, align="rcccc")%>%kable_styling()%>%
  column_spec(1, bold = T, border_right = T)
Ville Coefficient HW SE 2.5% CI 97.5% CI
bm 1.0668 1.0467 0.9749 1.166
bordeaux 1.2192 1.0352 1.1387 1.3043
clermont 1.1454 1.0505 1.039 1.2605
dijon 1.1006 1.0567 0.9869 1.2252
grenoble 1.0677 1.0431 0.9824 1.1592
lehavre 1.0124 1.0571 0.9072 1.1279
lille 1.0847 1.028 1.0273 1.1449
lyon 1.152 1.0297 1.0876 1.2196
marseille 1.0724 1.0263 1.0189 1.1282
montpellier 0.9938 1.047 0.9073 1.0863
nancy 1.0895 1.0468 0.9954 1.1908
nantes 1.1043 1.0414 1.0193 1.195
nice 1.057 1.0341 0.9892 1.1283
paris 1.2438 1.0214 1.1932 1.2963
rennes 1.0912 1.0648 0.9638 1.2327
rouen 1.1401 1.0397 1.0558 1.2301
strasbourg 1.1292 1.0444 1.0363 1.2289
toulouse 1.038 1.0359 0.9681 1.1118

 

Compare Heat Wave coefficient in model 1 and model 2

Model 1
Model 2
Ville Coefficient HW 2.5% CI 97.5% CI Coefficient HW 2.5% CI 97.5% CI
bm 1.1 1.016 1.188 1.067 0.975 1.166
bordeaux 1.259 1.183 1.339 1.219 1.139 1.304
clermont 1.175 1.071 1.286 1.145 1.039 1.261
dijon 1.177 1.064 1.299 1.101 0.987 1.225
grenoble 1.124 1.039 1.215 1.068 0.982 1.159
lehavre 1.072 0.976 1.175 1.012 0.907 1.128
lille 1.145 1.092 1.2 1.085 1.027 1.145
lyon 1.205 1.141 1.271 1.152 1.088 1.22
marseille 1.098 1.044 1.154 1.072 1.019 1.128
montpellier 1 0.913 1.092 0.994 0.907 1.086
nancy 1.099 1.01 1.193 1.089 0.995 1.191
nantes 1.176 1.096 1.26 1.104 1.019 1.195
nice 1.066 1 1.136 1.057 0.989 1.128
paris 1.365 1.315 1.416 1.244 1.193 1.296
rennes 1.164 1.042 1.297 1.091 0.964 1.233
rouen 1.222 1.142 1.305 1.14 1.056 1.23
strasbourg 1.252 1.165 1.343 1.129 1.036 1.229
toulouse 1.089 1.02 1.162 1.038 0.968 1.112

Model for Ozone with Heat Wave variable

estim3 <- matrix(NA, nrow = 18, ncol = 5)
colnames(estim3) <- c("Ville","Coefficient HW","SE","2.5% CI", "97.5% CI")
mod3<-list()


# Model Loop 

for(i in 1:length(villes_s)) {
  mod3[[i]]<-glm(o3~heat_wave+ns(time,df=round(8*length(time)/365.25))+Jours+Vacances+hol,data=villes_s[[i]],family=quasipoisson)
  est3<-summary(mod3[[i]])
  estim3[i, 1] <- as.character(cities[[i]])
  estim3[i, 2] <- exp(est3$coefficients[2])
  estim3[i, 3] <- exp(summary(mod3[[i]])$coefficients[, 2][2])
  estim3[i, 4:5] <- exp(confint(mod3[[i]])[2,])
}
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
## Waiting for profiling to be done...
tab_estim3<-estim3
tab_estim3[,2:5]<-round(as.numeric(tab_estim3[,2:5]), digits = 4)


kable(tab_estim3)%>%kable_styling()%>%
  column_spec(1, bold = T, border_right = T)
Ville Coefficient HW SE 2.5% CI 97.5% CI
bm 1.6718 1.0212 1.6042 1.7415
bordeaux 1.483 1.0199 1.4267 1.541
clermont 1.3206 1.0193 1.2717 1.3709
dijon 1.436 1.0199 1.3814 1.4924
grenoble 1.3273 1.0208 1.2746 1.3818
lehavre 1.5868 1.0183 1.5311 1.6441
lille 1.678 1.022 1.6077 1.7507
lyon 1.3768 1.0222 1.3185 1.4372
marseille 1.1889 1.0184 1.1471 1.2319
montpellier 1.057 1.0189 1.0188 1.0962
nancy 1.4232 1.0215 1.3649 1.4834
nantes 1.5666 1.0214 1.5027 1.6325
nice 1.0735 1.016 1.0405 1.1073
paris 1.6543 1.0238 1.5793 1.7321
rennes 1.5587 1.0201 1.4988 1.6205
rouen 1.6338 1.0205 1.5698 1.6998
strasbourg 1.5938 1.0253 1.5172 1.6735
toulouse 1.3386 1.0184 1.2914 1.3871

Mediation Analysis: The Product Method

Natural direct Effect (NDE)

Coefficient associated to Heat Wave variable in Model 2

Natural Indirect Effect (NIE)

Coefficient associated to Heat Wave variable variable in Model 3 x Coefficient associated to Ozone in Model 2

ville NDE_HW1 O3 HW3 NIE total_effect
bm 1.0668248 1.000571 1.671779 1.672734 1.784514
bordeaux 1.2191624 1.000787 1.483008 1.484176 1.809451
clermont 1.1453916 1.000854 1.320577 1.321705 1.513869
dijon 1.1006139 1.001607 1.436044 1.438351 1.583069
grenoble 1.0677373 1.001461 1.327319 1.329258 1.419298
lehavre 1.0124406 1.001180 1.586837 1.588710 1.608474
lille 1.0847336 1.001065 1.678023 1.679810 1.822147
lyon 1.1520396 1.001188 1.376830 1.378466 1.588048
marseille 1.0724306 1.001118 1.188889 1.190217 1.276425
montpellier 0.9938158 1.000673 1.056977 1.057688 1.051147
nancy 1.0894899 1.000220 1.423163 1.423477 1.550863
nantes 1.1042748 1.001373 1.566584 1.568734 1.732314
nice 1.0569743 1.000906 1.073535 1.074507 1.135726
paris 1.2438262 1.001651 1.654301 1.657033 2.061061
rennes 1.0912343 1.001436 1.558712 1.560949 1.703361
rouen 1.1401051 1.001374 1.633849 1.636094 1.865319
strasbourg 1.1291839 1.000714 1.593832 1.594971 1.801015
toulouse 1.0379560 1.001475 1.338581 1.340555 1.391438

BOOTSTRAP METHOD

Code:

  # start bootstrap
  nreps=1000 #number of bootstrap reps
  results<-matrix(NA,nrow = 18,ncol=7)
  colnames(results)<-c("city","NDE","NDE_2.5","NDE_97.5","NIE","NIE_2.5","NIE_97.5")
  
for (i in (1:length(villes_s))){
  boot.nde<- rep(NA,nreps)
  boot.nie <- rep(NA,nreps)
  for (rep in 1:nreps)
      
    {
      dat_resample <- sample(1:nrow(villes_s[[i]]),nrow(villes_s[[i]]),replace=T)
      dat_boot <- villes_s[[i]][dat_resample,]
        
      # outcome model - Poisson Regression: Mortality, HW and O3
      m.outcome<-glm(nocc_tot~heat_wave+o3+ns(time,df=round(8*length(time)/365.25))+Jours+Vacances+hol,data=dat_boot,family=quasipoisson)
      
      # mediator model - multinomial linear regression
      m.mediator<-lm(o3~heat_wave+ns(time,df=round(8*length(time)/365.25))+Jours+Vacances+hol,data=dat_boot) 
      
      # save coefficients
      theta1<-coef(m.outcome)[2]
      
      theta2<-coef(m.outcome)[3]
     
      beta1<-coef(m.mediator)[2]
      
      # estimate CDE and NIE
      
      boot.nde[rep] <- exp(theta1) #NDE
      
      boot.nie[rep] <-exp(theta2*beta1) #NIE 
                             
      
    } #end bootstrap

  results[i,1]<-cities[[i]]
  results[i,2]<-median(boot.nde, na.rm=T)
  results[i,3]<-quantile(boot.nde, 0.025, na.rm=T)
  results[i,4]<-quantile(boot.nde, 0.975, na.rm=T)
  results[i,5]<-median(boot.nie, na.rm=T)
  results[i,6]<-quantile(boot.nie, 0.025, na.rm=T)
  results[i,7]<-quantile(boot.nie, 0.975, na.rm=T)
  
     }
  
  # output CDE and NIE and confidence intervals

Results:

res<-data.frame(results)

for (i in (2:7)){
res[,i]<-as.numeric(as.character(res[,i]))
}

res[,2:7]<-round(res[,2:7],digits = 4)

kable(res)%>%kable_styling()%>%
  column_spec(1, bold = T, border_right = T)%>%
  column_spec(4, border_right = T)
city NDE NDE_2.5 NDE_97.5 NIE NIE_2.5 NIE_97.5
bm 1.0608 0.9550 1.1606 1.0330 0.9909 1.0782
bordeaux 1.2120 1.1269 1.3002 1.0319 1.0027 1.0642
clermont 1.1457 1.0271 1.2728 1.0271 0.9951 1.0611
dijon 1.0955 0.9727 1.2246 1.0665 1.0193 1.1135
grenoble 1.0609 0.9781 1.1486 1.0523 1.0246 1.0829
lehavre 1.0116 0.9096 1.1209 1.0593 1.0024 1.1172
lille 1.0875 1.0312 1.1528 1.0553 1.0277 1.0849
lyon 1.1475 1.0543 1.2482 1.0436 1.0238 1.0672
marseille 1.0705 1.0123 1.1328 1.0235 1.0126 1.0370
montpellier 0.9868 0.9036 1.0741 1.0041 0.9986 1.0133
nancy 1.0812 0.9636 1.2032 1.0101 0.9781 1.0456
nantes 1.1127 1.0197 1.2096 1.0622 1.0238 1.1049
nice 1.0505 0.9800 1.1224 1.0088 1.0011 1.0197
paris 1.2349 1.1213 1.3719 1.0836 1.0567 1.1172
rennes 1.0897 0.9557 1.2219 1.0636 1.0038 1.1260
rouen 1.1367 1.0597 1.2287 1.0705 1.0311 1.1140
strasbourg 1.1284 1.0361 1.2234 1.0461 1.0114 1.0864
toulouse 1.0392 0.9670 1.1142 1.0488 1.0236 1.0754