library(dplyr)
library(purrr)
library(gsheet)
library(raster)
library(ncdf4)
library(lubridate)
library(readxl)
library(writexl)
library(tidyverse)
library(ggplot2)
library(INLA)
library(caret)
library(inlabru)
library(PresenceAbsence)
Target spot
Packages
<- gsheet2tbl("https://docs.google.com/spreadsheets/d/1j0WZXtJsSMN1MAbmkppnCMnr5d9LnsxV/edit?usp=sharing&ouid=112586075609758894128&rtpof=true&sd=true") ma2
= ma2 %>%
ma3 filter(year == 2025) %>%
filter(Source == "Claudia")
<- ma3 %>%
ma3 mutate(
pd_90 = planting_date + 90)
$id <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19) ma3
Nasapower - Claudia 90
library(janitor)
# IMPORTING DATA FROM NASAPOWER AND CREATING A NEW DATAFRAME WITH THE WEATHER DATA
library(nasapower)
<- data.frame()
box
# Loop para extrair dados climáticos para cada estudo
for(i in 1:nrow(ma3)) {
# Obter os dados climáticos usando nasapower
<- get_power(
lil_nasa community = "ag",
temporal_api = "daily",
dates = c(ma3$planting_date[i], ma3$pd_90[i]), # Data de plantio e 140 dias depois
lonlat = c(ma3$longitude[i], ma3$lat[i]), # Longitude e Latitude
pars = c("T2M", "RH2M", "PRECTOTCORR", "T2M_MAX", "T2M_MIN", "T2MDEW") # Parâmetros desejados
%>%
) # Adicionar colunas de identificação ao dataframe
mutate(
id = ma3$id[i],
location = ma3$location[i], # Adiciona a localização
state = ma3$state[i],
mean_sev = ma3$mean_sev[i],# Adiciona o estado
year = format(as.Date(ma3$planting_date[i]), "%Y") # Adiciona o ano a partir da data de plantio
)
# Combina os dados atuais com os anteriores
<- bind_rows(box, lil_nasa)
box
}
#write_xlsx(box, "data/weather_nasa.xlsx")
= box
wd_f90 $wd_90 <- rep(0:90, times = 19)
wd_f90$mean_sev = wd_f90$mean_sev/100
wd_f90
= wd_f90 %>% #wd_f90
wd_f90 ::filter(wd_90 >= 0 & wd_90 <= 40) %>%
dplyrgroup_by(id) %>%
::summarise(
dplyrRH2M = mean(RH2M),
T2M = mean(T2M),
T2M_MAX = mean(T2M_MAX),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev)
%>%
)::select(-id) dplyr
Nasapower - Bio 90
= ma2 %>%
ma4 filter(Source == "Bio")
<- ma4 %>%
ma4 ::mutate(
dplyrpd_90 = planting_date + 90)
$id <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)
ma4
$mean_sev = ma4$mean_sev/100
ma4
library(janitor)
# IMPORTING DATA FROM NASAPOWER AND CREATING A NEW DATAFRAME WITH THE WEATHER DATA
library(nasapower)
<- data.frame()
box3
# Loop para extrair dados climáticos para cada estudo
for(i in 1:nrow(ma4)) {
# Obter os dados climáticos usando nasapower
<- get_power(
lil_nasa community = "ag",
temporal_api = "daily",
dates = c(ma4$planting_date[i], ma4$pd_90[i]), # Data de plantio e 140 dias depois
lonlat = c(ma4$longitude[i], ma4$lat[i]), # Longitude e Latitude
pars = c("T2M", "RH2M", "PRECTOTCORR", "T2M_MAX", "T2M_MIN", "T2MDEW") # Parâmetros desejados
%>%
) # Adicionar colunas de identificação ao dataframe
mutate(
id = ma4$id[i],
location = ma4$location[i], # Adiciona a localização
state = ma4$state[i], # Adiciona o estado
mean_sev = ma4$mean_sev[i],
year = format(as.Date(ma4$planting_date[i]), "%Y") # Adiciona o ano a partir da data de plantio
)
# Combina os dados atuais com os anteriores
<- bind_rows(box3, lil_nasa)
box3
}
#write_xlsx(box, "data/weather_nasa.xlsx")
= box3
wd_f90_bio $wd_90 <- rep(0:90, times = 21)
wd_f90_bio
= wd_f90_bio %>% #wd_f90
wd_f90_bio ::filter(wd_90 >= 0 & wd_90 <= 40) %>%
dplyrgroup_by(id) %>%
::summarise(
dplyrRH2M = mean(RH2M),
T2M = mean(T2M),
T2M_MAX = mean(T2M_MAX),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev)
%>%
)::select(-id) dplyr
#wd_b90_bio = rbind(wd_f90_bio,wd_f90)
#write_xlsx(wd_b90_bio,"data/wd_f90.xlsx")
= read_xlsx("data/wd_f90.xlsx") wd_b90_bio
Nasapower - All epidemics
= ma2 %>%
ma2 ::mutate(
dplyrpd_90 = planting_date + 90)
$id = 1:254
ma2
# IMPORTING DATA FROM NASAPOWER AND CREATING A NEW DATAFRAME WITH THE WEATHER DATA
library(nasapower)
<- data.frame()
box
# Loop para extrair dados climáticos para cada estudo
for(i in 1:nrow(ma2)) {
# Obter os dados climáticos usando nasapower
<- get_power(
lil_nasa community = "ag",
temporal_api = "daily",
dates = c(ma2$planting_date[i], ma2$pd_90[i]), # Data de plantio e 140 dias depois
lonlat = c(ma2$longitude[i], ma2$lat[i]), # Longitude e Latitude
pars = c("T2M", "RH2M", "PRECTOTCORR", "T2M_MAX", "T2M_MIN", "T2MDEW") # Parâmetros desejados
%>%
) # Adicionar colunas de identificação ao dataframe
mutate(
id = ma2$id[i],
location = ma2$location[i], # Adiciona a localização
state = ma2$state[i], # Adiciona o estado
mean_sev = ma2$mean_sev[i],
planting_date = ma2$planting_date[i],
year = format(as.Date(ma2$planting_date[i]), "%Y") # Adiciona o ano a partir da data de plantio
)
# Combina os dados atuais com os anteriores
<- bind_rows(box, lil_nasa)
box }
#write_xlsx(box,data/weather_total.xlsx")
= read_xlsx("data/weather_total.xlsx") box
<- box %>%
box mutate(
# Criando a data permitida diretamente com base no estado
allowed_date = case_when(
== "MT" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-09-16")),
state == "MS" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-09-16")),
state == "GO" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-09-25")),
state == "PR" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-09-11")),
state == "TO" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-10-01")),
state == "DF" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-10-01")),
state == "BA" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-10-01")),
state == "MG" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-10-01")),
state == "SP" ~ as.Date(paste0(format(YYYYMMDD, "%Y"), "-9-16"))
state
),# Ajustando o ano da allowed_date para casos de janeiro e fevereiro
allowed_date = if_else(
format(YYYYMMDD, "%m") %in% c("01", "02"),
as.Date(paste0(as.numeric(format(YYYYMMDD, "%Y")) - 1, "-", format(allowed_date, "%m-%d"))),
allowed_date
),# Calculando a diferença em dias
days_difference = as.numeric(YYYYMMDD - allowed_date)
)
Inference
0 to 20
#box$mean_sev = box$mean_sev/100
= box %>%
wd_0_20 ::filter(days >=0 & days <= 20)
dplyr
= wd_0_20 %>%
wd_0_20 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
#ma3 <- head(ma, nrow(ma2) - 37)
#wd_0_20$year = ma2$year # ESTAVA RODANDO ESSE NO INICIO
= wd_0_20 %>%
wd_0_20 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
<-cor.test(x = wd_0_20$RH2M,y = wd_0_20$PRECTOTCORR, method = "spearman")
corr corr
Spearman's rank correlation rho
data: wd_0_20$RH2M and wd_0_20$PRECTOTCORR
S = 746631, p-value < 2.2e-16
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.7266223
#wd_0_20 <- head(wd_0_20, nrow(wd_0_20) - 4)
= inla(epidemic ~T2M + RH2M+PRECTOTCORR+
inla_0_20 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_0_20,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_0_20)
Time used:
Pre = 0.23, Running = 0.151, Post = 0.0563, Total = 0.438
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -10.862 3.973 -18.694 -10.849 -3.107 -10.849 0
T2M 0.264 0.101 0.067 0.264 0.465 0.264 0
RH2M 0.073 0.029 0.016 0.073 0.131 0.073 0
PRECTOTCORR -0.001 0.004 -0.010 -0.001 0.007 -0.001 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 2.26 2.89 0.40 1.50 8.36 0.925
Deviance Information Criterion (DIC) ...............: 277.03
Deviance Information Criterion (DIC, saturated) ....: 276.67
Effective number of parameters .....................: 12.49
Watanabe-Akaike information criterion (WAIC) ...: 277.15
Effective number of parameters .................: 11.91
Marginal log-Likelihood: -166.23
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
20 to 40
= box %>%
wd_20_40 ::filter(days >= 20 & days <= 40)
dplyr
= wd_20_40 %>%
wd_20_40 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_20_40 %>%
wd_20_40 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_20_40 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_20_40,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_20_40)
Time used:
Pre = 0.143, Running = 0.147, Post = 0.0406, Total = 0.331
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -9.088 4.552 -18.023 -9.086 -0.162 -9.086 0
T2M 0.185 0.121 -0.052 0.185 0.424 0.185 0
RH2M 0.081 0.030 0.023 0.081 0.139 0.081 0
PRECTOTCORR -0.005 0.004 -0.014 -0.005 0.003 -0.005 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 3.44 5.87 0.462 1.87 14.58 1.06
Deviance Information Criterion (DIC) ...............: 281.75
Deviance Information Criterion (DIC, saturated) ....: 281.39
Effective number of parameters .....................: 11.97
Watanabe-Akaike information criterion (WAIC) ...: 282.25
Effective number of parameters .................: 11.78
Marginal log-Likelihood: -167.90
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
40 to 60
= box %>%
wd_40_60 ::filter(days >= 40 & days <= 60)
dplyr
= wd_40_60 %>%
wd_40_60 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_40_60 %>%
wd_40_60 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_40_60 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_40_60,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_40_60)
Time used:
Pre = 0.135, Running = 0.141, Post = 0.0466, Total = 0.323
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -9.123 5.051 -19.001 -9.133 0.813 -9.133 0
T2M 0.223 0.133 -0.038 0.223 0.484 0.223 0
RH2M 0.052 0.031 -0.008 0.052 0.112 0.052 0
PRECTOTCORR 0.004 0.004 -0.004 0.004 0.012 0.004 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 2.97 4.81 0.423 1.69 12.26 0.97
Deviance Information Criterion (DIC) ...............: 277.39
Deviance Information Criterion (DIC, saturated) ....: 277.02
Effective number of parameters .....................: 12.25
Watanabe-Akaike information criterion (WAIC) ...: 277.37
Effective number of parameters .................: 11.56
Marginal log-Likelihood: -165.72
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
60 to 80
= box %>%
wd_60_80 ::filter(days >= 60 & days <= 80)
dplyr
= wd_60_80 %>%
wd_60_80 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_60_80 %>%
wd_60_80 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+PRECTOTCORR+
inla_60_80 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_60_80,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_60_80)
Time used:
Pre = 0.129, Running = 0.148, Post = 0.0351, Total = 0.312
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -4.664 4.916 -14.289 -4.670 4.995 -4.670 0
T2M 0.056 0.125 -0.189 0.056 0.301 0.056 0
RH2M 0.062 0.033 -0.003 0.062 0.126 0.062 0
PRECTOTCORR -0.005 0.003 -0.011 -0.005 0.002 -0.005 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 3.10 4.36 0.508 1.93 12.00 1.17
Deviance Information Criterion (DIC) ...............: 285.68
Deviance Information Criterion (DIC, saturated) ....: 285.31
Effective number of parameters .....................: 12.10
Watanabe-Akaike information criterion (WAIC) ...: 286.03
Effective number of parameters .................: 11.77
Marginal log-Likelihood: -169.94
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
0 to 80
= box %>%
wd_0_80 ::filter(days >= 0 & days <= 80)
dplyr
= wd_0_80 %>%
wd_0_80 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_0_80 %>%
wd_0_80 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_0_80 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_0_80,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_0_80)
Time used:
Pre = 0.13, Running = 0.141, Post = 0.038, Total = 0.309
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -11.249 4.927 -20.929 -11.244 -1.600 -11.244 0
T2M 0.229 0.125 -0.016 0.229 0.475 0.229 0
RH2M 0.089 0.039 0.012 0.089 0.165 0.089 0
PRECTOTCORR -0.001 0.002 -0.004 -0.001 0.003 -0.001 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 2.76 4.06 0.433 1.67 10.89 0.997
Deviance Information Criterion (DIC) ...............: 279.06
Deviance Information Criterion (DIC, saturated) ....: 278.69
Effective number of parameters .....................: 12.13
Watanabe-Akaike information criterion (WAIC) ...: 279.36
Effective number of parameters .................: 11.76
Marginal log-Likelihood: -167.37
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
0 to 60
= box %>%
wd_0_60 ::filter(days >= 0 & days <= 60)
dplyr
= wd_0_60 %>%
wd_0_60 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_0_60 %>%
wd_0_60 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_0_60 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_0_60,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_0_60)
Time used:
Pre = 0.133, Running = 0.152, Post = 0.0351, Total = 0.319
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -11.345 4.738 -20.656 -11.339 -2.069 -11.339 0
T2M 0.268 0.123 0.029 0.267 0.510 0.267 0
RH2M 0.068 0.036 -0.002 0.068 0.138 0.068 0
PRECTOTCORR 0.001 0.002 -0.003 0.001 0.006 0.001 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 2.74 4.04 0.431 1.66 10.84 0.989
Deviance Information Criterion (DIC) ...............: 277.04
Deviance Information Criterion (DIC, saturated) ....: 276.67
Effective number of parameters .....................: 12.11
Watanabe-Akaike information criterion (WAIC) ...: 277.35
Effective number of parameters .................: 11.75
Marginal log-Likelihood: -166.25
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
0 to 40
= box %>%
wd_0_40 ::filter(days >= 0 & days <= 40)
dplyr
= wd_0_40 %>%
wd_0_40 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_0_40 %>%
wd_0_40 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_0_40 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_0_40,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_0_40)
Time used:
Pre = 0.129, Running = 0.137, Post = 0.0623, Total = 0.328
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -11.499 4.418 -20.194 -11.489 -2.862 -11.489 0
T2M 0.256 0.114 0.034 0.256 0.481 0.256 0
RH2M 0.088 0.033 0.022 0.088 0.154 0.088 0
PRECTOTCORR -0.002 0.003 -0.008 -0.002 0.004 -0.002 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 2.54 3.56 0.418 1.60 9.82 0.965
Deviance Information Criterion (DIC) ...............: 277.98
Deviance Information Criterion (DIC, saturated) ....: 277.62
Effective number of parameters .....................: 12.22
Watanabe-Akaike information criterion (WAIC) ...: 278.27
Effective number of parameters .................: 11.82
Marginal log-Likelihood: -166.80
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
20 to 60
= box %>%
wd_20_60 ::filter(days >= 20 & days <= 60)
dplyr
= wd_20_60 %>%
wd_20_60 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_20_60 %>%
wd_20_60 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_20_60 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_20_60,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_20_60)
Time used:
Pre = 0.131, Running = 0.142, Post = 0.0365, Total = 0.31
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -10.064 4.909 -19.694 -10.064 -0.435 -10.064 0
T2M 0.228 0.129 -0.025 0.228 0.482 0.228 0
RH2M 0.067 0.032 0.003 0.067 0.130 0.067 0
PRECTOTCORR 0.001 0.003 -0.004 0.001 0.006 0.001 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 4.35 8.33 0.497 2.08 19.30 1.13
Deviance Information Criterion (DIC) ...............: 281.28
Deviance Information Criterion (DIC, saturated) ....: 280.92
Effective number of parameters .....................: 11.73
Watanabe-Akaike information criterion (WAIC) ...: 281.71
Effective number of parameters .................: 11.51
Marginal log-Likelihood: -167.62
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
20 to 80
= box %>%
wd_20_80 ::filter(days >= 20 & days <= 80)
dplyr
= wd_20_80 %>%
wd_20_80 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_20_80 %>%
wd_20_80 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_20_80 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_20_80,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_20_80)
Time used:
Pre = 0.149, Running = 0.148, Post = 0.0412, Total = 0.338
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -9.514 5.077 -19.470 -9.515 0.446 -9.515 0
T2M 0.176 0.131 -0.080 0.176 0.432 0.176 0
RH2M 0.084 0.037 0.012 0.084 0.156 0.084 0
PRECTOTCORR -0.001 0.002 -0.005 -0.001 0.003 -0.001 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 3.58 6.21 0.469 1.91 15.26 1.07
Deviance Information Criterion (DIC) ...............: 282.39
Deviance Information Criterion (DIC, saturated) ....: 282.02
Effective number of parameters .....................: 11.92
Watanabe-Akaike information criterion (WAIC) ...: 282.80
Effective number of parameters .................: 11.67
Marginal log-Likelihood: -168.54
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
40 to 80
= box %>%
wd_40_80 ::filter(days >= 40 & days <= 80)
dplyr
= wd_40_80 %>%
wd_40_80 :: group_by(id) %>%
dplyr::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
year = first(YEAR)
%>%
) ::select(-id)
dplyr
= wd_40_80 %>%
wd_40_80 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= inla(epidemic ~T2M + RH2M+ PRECTOTCORR+
inla_40_80 f(year, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
#f(days, model = "iid", hyper = list(prec = list(param = c(0.001,0.001)))),
data = wd_40_80,
family = "binomial",
control.predictor = list(compute = TRUE),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE, config = TRUE))
summary(inla_40_80)
Time used:
Pre = 0.138, Running = 0.14, Post = 0.0651, Total = 0.343
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) -7.684 5.198 -17.860 -7.691 2.531 -7.691 0
T2M 0.142 0.134 -0.121 0.142 0.404 0.142 0
RH2M 0.069 0.036 -0.002 0.069 0.140 0.069 0
PRECTOTCORR -0.001 0.003 -0.006 -0.001 0.004 -0.001 0
Random effects:
Name Model
year IID model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Precision for year 2.27 3.01 0.389 1.48 8.53 0.90
Deviance Information Criterion (DIC) ...............: 280.21
Deviance Information Criterion (DIC, saturated) ....: 279.85
Effective number of parameters .....................: 12.65
Watanabe-Akaike information criterion (WAIC) ...: 280.27
Effective number of parameters .................: 11.99
Marginal log-Likelihood: -167.83
CPO, PIT is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
PREDICTION INLAbru
$days <- rep(0:90, times = 254)
box
= box %>%
wd_60_8022 ::filter(days >= 0 & days <= 40)
dplyr
= wd_60_8022 %>%
wd_60_8022 group_by(id) %>%
::summarise(
dplyrRH2M = mean(RH2M),
T2M_MAX = mean(T2M_MAX),
T2M = mean(T2M),
T2M_MIN = mean(T2M_MIN),
PRECTOTCORR = sum(PRECTOTCORR),
mean_sev = mean(mean_sev),
%>%
) ::select(-id)
dplyr
= wd_60_8022 %>%
wd_60_8022 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0)) dplyr
= wd_60_8022 %>%
wd_0_203 ::select(-epidemic)
dplyr
= bru(epidemic ~T2M + RH2M,
inla_0_20 data = wd_60_8022,
family = "binomial")
summary(inla_0_20)
inlabru version: 2.12.0
INLA version: 24.12.11
Components:
T2M: main = linear(T2M), group = exchangeable(1L), replicate = iid(1L), NULL
RH2M: main = linear(RH2M), group = exchangeable(1L), replicate = iid(1L), NULL
Intercept: main = linear(1), group = exchangeable(1L), replicate = iid(1L), NULL
Likelihoods:
Family: 'binomial'
Tag: ''
Data class: 'tbl_df', 'tbl', 'data.frame'
Response class: 'numeric'
Predictor: epidemic ~ .
Used components: effects[T2M, RH2M, Intercept], latent[]
Time used:
Pre = 0.226, Running = 0.138, Post = 0.0222, Total = 0.386
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
T2M 0.207 0.100 0.012 0.207 0.403 0.207 0
RH2M 0.072 0.021 0.030 0.072 0.114 0.072 0
Intercept -9.616 3.836 -17.134 -9.616 -2.098 -9.616 0
Deviance Information Criterion (DIC) ...............: 289.23
Deviance Information Criterion (DIC, saturated) ....: 288.87
Effective number of parameters .....................: 2.96
Watanabe-Akaike information criterion (WAIC) ...: 289.43
Effective number of parameters .................: 3.10
Marginal log-Likelihood: -160.46
is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
<- head(wd_60_8022, nrow(wd_60_8022) - 40)
wd_60_8022 %>%
wd_60_8022 filter(epidemic == 0)
= wd_60_8022 %>%
wd_0_203 ::select(-epidemic)
dplyr
= bru(epidemic ~T2M + RH2M,
inla_0_20 data = wd_60_8022,
family = "binomial")
= wd_b90_bio %>%
wd_f90 ::mutate(epidemic = ifelse(mean_sev >= 0.25, 1, 0))
dplyr
= wd_f90 %>%
wd_0_203 ::select(-epidemic) dplyr
#set.seed(1234)
= predict(object= inla_0_20, newdata = wd_0_203, formula = ~ c(pred = Intercept + T2M + RH2M), n.samples = 1000)
t
#write_xlsx(t,"data/t.xlsx")
= read_xlsx("data/t.xlsx")
t
$mean = plogis(t$mean)
wd_f90
= wd_f90 %>%
wd_60_8 ::select(epidemic,mean) %>%
dplyrmutate(
ID = nrow(epidemic)
)
= as.data.frame(wd_60_8)
wd_60_8
<- data.frame(1, wd_f90$epidemic, plogis(t$mean))
dat_lasso optimal.thresholds(dat_lasso)
auc.roc.plot(dat_lasso)
= confusionMatrix(data = as.factor(as.numeric(wd_f90$mean > 0.78)), mode= "everything", reference = as.factor(wd_f90$epidemic))
cm_rf_052 cm_rf_052
Confusion Matrix and Statistics
Reference
Prediction 0 1
0 13 5
1 3 19
Accuracy : 0.8
95% CI : (0.6435, 0.9095)
No Information Rate : 0.6
P-Value [Acc > NIR] : 0.006065
Kappa : 0.5918
Mcnemar's Test P-Value : 0.723674
Sensitivity : 0.8125
Specificity : 0.7917
Pos Pred Value : 0.7222
Neg Pred Value : 0.8636
Precision : 0.7222
Recall : 0.8125
F1 : 0.7647
Prevalence : 0.4000
Detection Rate : 0.3250
Detection Prevalence : 0.4500
Balanced Accuracy : 0.8021
'Positive' Class : 0