library(lme4)
library(tidyverse)
library(ggthemes)
library(stringr)
library(bbplot)
library(stringi)
Res_Slope <- readRDS("~/RStudio/wildfire/Model_Resultas_Slope.rds")
Res_Slopeintercept <- readRDS("~/RStudio/wildfire/Model_ Slope and Intercept Resultas_Slopeintercept.rds")
Res_intercept <- readRDS("~/RStudio/wildfire/Model_ only Intercept Resultas_intercept.rds")
Res_intercept_tripol<- readRDS("~/RStudio/wildfire/Model_ only Intercept_tripoluente_ncontroleambiental Resultas_intercept_tri_semcontroleambiental.rds")
Res_intercept_bruto$model %>% unique()
[1] "only Intercept" "only Intercept_tripoluente_ncontroleambiental"
[3] "only Intercept - Bruto"
summary(Res)
Intercept_rand slope SE_Intercept_rand fator efeito_fixo
Min. :-120.0 Min. :-0.8254018 Min. : 0.00018 AC : 110 Min. :-0.0836193
1st Qu.: 52.5 1st Qu.:-0.0344626 1st Qu.: 0.13988 AL : 110 1st Qu.:-0.0200132
Median : 123.7 Median :-0.0050080 Median : 0.33555 AM : 110 Median :-0.0045848
Mean : 162.3 Mean :-0.0114387 Mean : 3.54978 AP : 110 Mean :-0.0114387
3rd Qu.: 253.5 3rd Qu.:-0.0000017 3rd Qu.: 1.14723 BA : 110 3rd Qu.: 0.0005658
Max. : 552.5 Max. : 1.3142168 Max. :77.51901 CE : 110 Max. : 0.0707353
(Other):2228
nota poluente subset amostragem
score_Essay :1471 airpol_no2 : 472 overall :378 Min. :40404489
Score_General_Subjects:1417 airpol_o3 : 472 Female :324 1st Qu.:40404489
airpol_pm25: 472 Male :324 Median :40404489
Tripol :1472 pós-2008 :324 Mean :40404489
School management: Private:324 3rd Qu.:40404489
School management: Public :324 Max. :40404489
(Other) :890
N_grupos lowerCI_efx upperCI_efx pvalue_efx variance_slope_efx
Min. :21.00 Min. :-0.1675699 Min. :-0.070926 Min. :0.00000 Min. : 3021
1st Qu.:27.00 1st Qu.:-0.0533947 1st Qu.:-0.007949 1st Qu.:0.00000 1st Qu.: 9280
Median :27.00 Median :-0.0073926 Median :-0.000567 Median :0.00000 Median :17557
Mean :26.39 Mean :-0.0336410 Mean : 0.010763 Mean :0.14246 Mean :21149
3rd Qu.:27.00 3rd Qu.:-0.0007607 3rd Qu.: 0.002015 3rd Qu.:0.05126 3rd Qu.:19982
Max. :27.00 Max. : 0.0035341 Max. : 0.250736 Max. :0.99113 Max. :91642
teste modelo
airpol_pm25.score_Essay.1 : 354 airpol_pm25.score_Essay : 354
airpol_pm25.Score_General_Subjects.1 : 300 airpol_pm25.Score_General_Subjects : 300
airpol_pm25.Female.score_Essay.1 : 108 airpol_pm25.Female.score_Essay : 108
airpol_pm25.Female.Score_General_Subjects.1: 108 airpol_pm25.Female.Score_General_Subjects: 108
airpol_pm25.Male.score_Essay.1 : 108 airpol_pm25.Male.score_Essay : 108
airpol_pm25.Male.Score_General_Subjects.1 : 108 airpol_pm25.Male.Score_General_Subjects : 108
(Other) :1802 (Other) :1802
formula
samp_sub[[y]] ~ wildfire + (1 | UF_Home) : 420
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (0 + wildfire | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + Location: 324
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Location + gender : 324
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + gender : 318
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + Location + gender : 288
samp[[y]] ~ wildfire + samp[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + Location + gender : 162
(Other) :1052
model
only Intercept :1888
only Intercept - Bruto : 528
only Intercept_tripoluente_ncontroleambiental: 472
levels(Res$subset)
[1] "Female" "Male" "overall"
[4] "pós-2008" "pré-2008" "Rural"
[7] "School management: Private" "School management: Public" "Urban"
Res$subset <- recode_factor(
Res$subset,
"Female" ="Gender: Female",
"Male" ="Gender: Male",
"overall" ="Primary",
"pós-2008"="Period: After 2008",
"pré-2008"="Period: Before 2008",
"Rural" ="Location: Rural",
"School management: Private" ="Management: Private",
"School management: Public" ="Management: Public",
"Urban" ="Location: Urban")
levels(Res$subset)
[1] "Gender: Female" "Gender: Male" "Primary" "Period: After 2008" "Period: Before 2008"
[6] "Location: Rural" "Management: Private" "Management: Public" "Location: Urban"
Res$region_state[Res$fator=="AC"]<-"North - AC"
Res$region_state[Res$fator=="AP"]<-"North - AP"
Res$region_state[Res$fator=="TO"]<-"North - TO"
Res$region_state[Res$fator=="AM"]<-"North - AM"
Res$region_state[Res$fator=="RO"]<-"North - RO"
Res$region_state[Res$fator=="RR"]<-"North - RR"
Res$region_state[Res$fator=="PA"]<-"North - PA"
Res$region_state[Res$fator=="AL"]<-"Northeast - AL"
Res$region_state[Res$fator=="BA"]<-"Northeast - BA"
Res$region_state[Res$fator=="RN"]<-"Northeast - RN"
Res$region_state[Res$fator=="PB"]<-"Northeast - PB"
Res$region_state[Res$fator=="SE"]<-"Northeast - SE"
Res$region_state[Res$fator=="PE"]<-"Northeast - PE"
Res$region_state[Res$fator=="PI"]<-"Northeast - PI"
Res$region_state[Res$fator=="CE"]<-"Northeast - CE"
Res$region_state[Res$fator=="MA"]<-"Northeast - MA"
Res$region_state[Res$fator=="DF"]<-"Central-West - DF"
Res$region_state[Res$fator=="MT"]<-"Central-West - MT"
Res$region_state[Res$fator=="MS"]<-"Central-West - MS"
Res$region_state[Res$fator=="GO"]<-"Central-West - GO"
Res$region_state[Res$fator=="MG"]<-"Southeast - MG"
Res$region_state[Res$fator=="RJ"]<-"Southeast - RJ"
Res$region_state[Res$fator=="ES"]<-"Southeast - ES"
Res$region_state[Res$fator=="SP"]<-"Southeast - SP"
Res$region_state[Res$fator=="SC"]<-"South - SC"
Res$region_state[Res$fator=="RS"]<-"South - RS"
Res$region_state[Res$fator=="PR"]<-"South - PR"
Res$region_state<- as.factor(Res$region_state)
Res$region<- str_split(Res$region_state, "-", simplify = TRUE)
Res$region<-as.factor(Res$region[,1])
unique(Res$region)
[1] North Northeast Central Southeast South
Levels: Central North Northeast South Southeast
Res$poluente <- recode_factor(
Res$poluente,
"airpol_no2" ="NO²",
"airpol_o3" ="O³",
"airpol_pm25" ="PM25",
"tripol"="Tri_Pol")
levels(Res$poluente)
[1] "NO²" "O³" "PM25" "Tripol"
Res$nota <- recode_factor(
Res$nota,
"Score_General_Subjects" ="General subjects",
"score_Essay" ="Essay")
levels(Res$nota)
[1] "General subjects" "Essay"
Res$poluente[Res$model=="only Intercept - Bruto"]<-"NA"
Warning in `[<-.factor`(`*tmp*`, Res$model == "only Intercept - Bruto", :
nível de fator inválido, NA gerado
R <-Res %>%
mutate(lowerCI_rand_Intercept=Intercept_rand-1.96*as.numeric(SE_Intercept_rand),
upperCI_rand_Intercept=Intercept_rand+1.96*as.numeric(SE_Intercept_rand)) %>%
mutate(sinal_rand_Intercept=as.factor(ifelse(lowerCI_rand_Intercept>0,"Positivo",
ifelse(upperCI_rand_Intercept<0,"Negativo","null")))) %>%
#mutate(lowerCI_rand_slope=slope-1.96*SE_Slope_rand,
# upperCI_rand_slope=slope+1.96*SE_Slope_rand) %>%
#mutate(sinal_rand_slope=as.factor(ifelse(lowerCI_rand_slope>0,"Positivo",
# ifelse(upperCI_rand_slope<0,"Negativo","null")))) %>%
mutate(sinal_fixed=as.factor(ifelse(lowerCI_efx>0,
"Positivo",
ifelse(upperCI_efx<0,"Negativo","null"))))
summary(R)
Intercept_rand slope SE_Intercept_rand fator efeito_fixo
Min. :-120.0 Min. :-0.8254018 Min. : 0.00018 AC : 110 Min. :-0.0836193
1st Qu.: 52.5 1st Qu.:-0.0344626 1st Qu.: 0.13988 AL : 110 1st Qu.:-0.0200132
Median : 123.7 Median :-0.0050080 Median : 0.33555 AM : 110 Median :-0.0045848
Mean : 162.3 Mean :-0.0114387 Mean : 3.54978 AP : 110 Mean :-0.0114387
3rd Qu.: 253.5 3rd Qu.:-0.0000017 3rd Qu.: 1.14723 BA : 110 3rd Qu.: 0.0005658
Max. : 552.5 Max. : 1.3142168 Max. :77.51901 CE : 110 Max. : 0.0707353
(Other):2228
nota poluente subset amostragem N_grupos
General subjects:1417 NO² :472 Primary :378 Min. :40404489 Min. :21.00
Essay :1471 O³ :472 Gender: Female :324 1st Qu.:40404489 1st Qu.:27.00
PM25 :472 Gender: Male :324 Median :40404489 Median :27.00
Tripol:944 Period: After 2008 :324 Mean :40404489 Mean :26.39
NA's :528 Management: Private:324 3rd Qu.:40404489 3rd Qu.:27.00
Management: Public :324 Max. :40404489 Max. :27.00
(Other) :890
lowerCI_efx upperCI_efx pvalue_efx variance_slope_efx
Min. :-0.1675699 Min. :-0.070926 Min. :0.00000 Min. : 3021
1st Qu.:-0.0533947 1st Qu.:-0.007949 1st Qu.:0.00000 1st Qu.: 9280
Median :-0.0073926 Median :-0.000567 Median :0.00000 Median :17557
Mean :-0.0336410 Mean : 0.010763 Mean :0.14246 Mean :21149
3rd Qu.:-0.0007607 3rd Qu.: 0.002015 3rd Qu.:0.05126 3rd Qu.:19982
Max. : 0.0035341 Max. : 0.250736 Max. :0.99113 Max. :91642
teste modelo
airpol_pm25.score_Essay.1 : 354 airpol_pm25.score_Essay : 354
airpol_pm25.Score_General_Subjects.1 : 300 airpol_pm25.Score_General_Subjects : 300
airpol_pm25.Female.score_Essay.1 : 108 airpol_pm25.Female.score_Essay : 108
airpol_pm25.Female.Score_General_Subjects.1: 108 airpol_pm25.Female.Score_General_Subjects: 108
airpol_pm25.Male.score_Essay.1 : 108 airpol_pm25.Male.score_Essay : 108
airpol_pm25.Male.Score_General_Subjects.1 : 108 airpol_pm25.Male.Score_General_Subjects : 108
(Other) :1802 (Other) :1802
formula
samp_sub[[y]] ~ wildfire + (1 | UF_Home) : 420
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (0 + wildfire | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + Location: 324
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Location + gender : 324
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + gender : 318
samp_sub[[y]] ~ wildfire + samp_sub[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + Location + gender : 288
samp[[y]] ~ wildfire + samp[[x]] + (1 | UF_Home) + bs(as.numeric(year)) + preciptation + Wind_speed + Educ_mother + income + Munc_HDI + Manegement + Location + gender : 162
(Other) :1052
model region_state region lowerCI_rand_Intercept
only Intercept :1888 North - AC: 110 Central :382 Min. :-172.56
only Intercept - Bruto : 528 North - AM: 110 North :770 1st Qu.: 48.47
only Intercept_tripoluente_ncontroleambiental: 472 North - AP: 110 Northeast :966 Median : 110.23
North - PA: 110 South :330 Mean : 155.34
North - RO: 110 Southeast :440 3rd Qu.: 252.35
North - RR: 110 Max. : 552.22
(Other) :2228
upperCI_rand_Intercept sinal_rand_Intercept sinal_fixed
Min. :-111.33 Negativo: 139 Negativo:1655
1st Qu.: 57.53 null : 130 null : 723
Median : 145.31 Positivo:2619 Positivo: 510
Mean : 169.25
3rd Qu.: 260.11
Max. : 552.71
font <- "Helvetica"
#R$subset %>% unique()
R %>% filter(subset=="Primary") %>%
ggplot(aes(Intercept_rand, xmin=lowerCI_rand_Intercept,xmax=upperCI_rand_Intercept,
nota,
col=sinal_rand_Intercept))+
geom_vline(xintercept = 0,color="black", size=0.5,alpha=0.7)+
geom_pointrange()+
facet_grid(region*fator~model*poluente, scales = "free")+
bbc_style()+
theme(legend.position="none",
strip.text.x = element_text(family = font,angle = 0, hjust = 0.5),
strip.text.y = element_text(family = font,size=12,angle = 0, hjust = 0.5,),
axis.text.y = element_text(family = font,size=12),
axis.text.x = element_text(family = font,size=12),
panel.spacing = unit(1.5, "lines"),
panel.grid.major = element_line(linetype = "dotted",size = 1),
plot.margin = unit(c(0.5,0.5,0.5,0.5), "cm"),
#plot.title = element_text(hjust= 0.5, vjust= 0.5, face = 'bold', size = 25),
axis.title.x = element_text(family = font, size = 14,color = "black"))+
scale_color_manual(values=c("red", "#767676","blue"))+
xlab("Intercept Coefficient of Wildfire")
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
font <- "Helvetica"
#R$subset %>% unique()
R %>% filter(subset=="Primary") %>%
ggplot(aes(slope, xmin=lowerCI_rand_slope,xmax=upperCI_rand_slope,
nota,
col=sinal_rand_slope))+
geom_vline(xintercept = 0,color="black", size=0.5,alpha=0.7)+
geom_pointrange()+
facet_grid(region*fator~model*poluente,scales = "free")+
bbc_style()+
theme(legend.position="none",
strip.text.x = element_text(family = font,angle = 0, hjust = 0.5),
strip.text.y = element_text(family = font,size=12,angle = 0, hjust = 0.5,),
axis.text.y = element_text(family = font,size=12),
axis.text.x = element_text(family = font,size=12),
panel.spacing = unit(1.5, "lines"),
panel.grid.major = element_line(linetype = "dotted",size = 1),
plot.margin = unit(c(0.5,0.5,0.5,0.5), "cm"),
#plot.title = element_text(hjust= 0.5, vjust= 0.5, face = 'bold', size = 25),
axis.title.x = element_text(family = font, size = 14,color = "black"))+
scale_color_manual(values=c("red", "#767676","blue"))+
xlab("Coefficients of Wildfire")
Error in `geom_pointrange()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 2nd layer.
Caused by error in `FUN()`:
! object 'lowerCI_rand_slope' not found
Backtrace:
1. base (local) `<fn>`(x)
2. ggplot2:::print.ggplot(x)
4. ggplot2:::ggplot_build.ggplot(x)
5. ggplot2:::by_layer(...)
12. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
13. l$compute_aesthetics(d, plot)
14. ggplot2 (local) compute_aesthetics(..., self = self)
15. base::lapply(aesthetics, eval_tidy, data = data, env = env)
16. rlang (local) FUN(X[[i]], ...)
font <- "Helvetica"
R$fator %>% unique()
[1] AC AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO
Levels: AC AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO
R %>% filter(fator=="AC") %>% #filter(model=="only Intercept") %>%
ggplot(aes(efeito_fixo, xmin=lowerCI_efx,xmax=upperCI_efx,
subset,
col=sinal_fixed))+
geom_vline(xintercept = 0,color="black", size=0.5,alpha=0.7)+
geom_pointrange()+
facet_grid(nota~model*poluente,scales = "free")
bbc_style()+
theme(legend.position="none",
strip.text.x = element_text(family = font,angle = 0, hjust = 0.5),
strip.text.y = element_text(family = font,size=12,angle = 0, hjust = 0.5,),
axis.text.y = element_text(family = font,size=12),
axis.text.x = element_text(family = font,size=12),
panel.spacing = unit(1.5, "lines"),
panel.grid.major = element_line(linetype = "dotted",size = 1),
plot.margin = unit(c(0.5,0.5,0.5,0.5), "cm"),
#plot.title = element_text(hjust= 0.5, vjust= 0.5, face = 'bold', size = 25),
axis.title.x = element_text(family = font, size = 12,color = "black"))+
scale_color_manual(values=c("red", "#767676","blue"))+
xlab("Coefficients of Wildfire")
Error in `+.gg`:
! Can't add `scale_color_manual(values = c("red", "#767676", "blue"))` to a theme object.
Backtrace:
1. ggplot2:::`+.gg`(...)