library(tidyverse)
library(dplyr)
library(metafor)
library(ggplot2)
library(gsheet)
library(cowplot)
library(broom)
library(writexl)
library(readxl)
library(ggthemes)
library(minpack.lm)
Economic returns on fungicide use across soybean cultivars with varying tolerance to target spot
Package
Importation
<- gsheet2tbl("https://docs.google.com/spreadsheets/d/151DE26uSMN4WBS0PTQcjdw7BO56gXy_VilFZS3b9AAM/edit?usp=sharing")
ma
= read_xlsx("data/molina.xlsx") molina
unique(ma$cultivar)
[1] "M8210 IPRO" "CD 2728 IPRO" "BMX Potência RR" "NA 6700 IPRO"
[5] "NA 5909 RG" "TMG 803" "TMG 2181 IPRO" "M 9144RR"
[9] "8579 RSF IPRO" "M 8473 IPRO" "TEC 7849 IPRO" "BMX Garra RR"
[13] "63i64RSF IPRO" "8473RSF" "TMG 7067 IPRO" "P98Y70"
[17] "CD 2827 IPRO" "M 6410 IPRO" "Juruena" "GUAIA 7487 RR"
[21] "W791 RR" "Garra IPRO" "DM 75i76 IPRO" "74178 RSF IPRO"
[25] "M8349 IPRO" "M9144 RR" "GA 76 IPRO" "Ima 84114"
[29] "NS 8338 IPRO" "BS 2606 IPRO" "TMG 2383 IPRO" "DM73i75 IPRO"
[33] "C2827 IPRO" "TMG 2381 IPRO" "RK 7518 IPARO" "CZ48B32"
[37] "M8372" "M8210" "GA76 IPRO" "CZ58B28"
[41] "CZ 37B43 IPRO" "HO MARACAÍ IPRO" "77i79RSF IPRO" "BMX DOMINIO IPRO"
[45] NA "M5947 IPRO" "80182RSF IPRO" "M220i2X"
[49] "BÔNUS" "TMG 2285 IPRO"
|>
ma filter(!cultivar %in% c("63i64RSF IPRO","8579 RSF IPRO",
"CD 2728 IPRO","DM 75i76 IPRO","M8210 IPRO","TMG 2181 IPRO")) %>%
filter(!is.na(sev)) |>
ggplot(aes(sev))+
geom_histogram(fill = "black", color = "white")+
::theme_few()+
ggthemes#theme_minimal()+
#facet_wrap(~year)+
labs(x = "TS Severity (%)",
y = "Count")+
facet_wrap(~cultivar)+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
Cluster
= ma %>%
ma1 ::select(study, cultivar, sev,yld,block,ai,state,year)
dplyr
= molina %>%
molina1 ::select(study, cultivar, sev,yield,rep,fungic,state,year)
dplyr
colnames(molina1) = c("study","cultivar","sev","yld","block","ai","state","year")
= rbind(ma1,molina1)
ma_c
unique(ma_c$state)
[1] "MT" "GO" "MS" "TO" "BA" "PR" "DF"
= ma_c %>%
ma_c filter(!is.na(yld)) %>%
filter(!is.na(sev)) %>%
filter(!is.na(cultivar))
= ma_c %>%
ma_c_reg #dplyr::select(active_ingredient, block, sev,yld) %>%
group_by(cultivar) %>%
do(tidy(lm(.$yld ~ .$sev)))
ma_c_reg
= ma_c_reg |>
ma_c_reg filter(term %in% c("(Intercept)",".$sev"))
$term== "(Intercept)",c("parameters")] <- "Intercept"
ma_c_reg[ma_c_reg$term== ".$sev",c("parameters")] <- "Slope"
ma_c_reg[ma_c_reg
= ma_c_reg |>
b1_c ::filter(parameters == "Slope") |>
dplyr#filter(estimate < 0) %>%
::group_by(cultivar) |>
dplyrsummarise(
Slope = estimate
)
= ma_c_reg |>
b0_c filter(parameters == "Intercept") |>
group_by(cultivar) |>
summarise(
Intercept = estimate
)
= cbind(b1_c,b0_c)
parameters_c 3] = NULL
parameters_c[,
= parameters_c %>%
parameters_c filter(!cultivar %in% c("BÔNUS","M9144_RR","74178 RSF IPRO"))
= parameters_c %>%
dc_c group_by(cultivar) %>%
summarise(
DC = (Slope/Intercept)*-1,
b1= Intercept/1000,
DC = DC,
DC_perc = DC*100
)
set.seed(123)
<- model.matrix(~ cultivar - 1, data = dc_c)
dados_dummy
set.seed(123)
<- cbind(dados_dummy, DC = dc_c$DC)
dados_preparados
set.seed(123)
<- kmeans(dados_preparados, centers = 3) resultado_kmeans
library(factoextra)
= fviz_cluster(resultado_kmeans, data = dados_preparados, label = NULL,geom = "point",pointsize = 3, shape = 20)
p = p + theme_few() +
p2 scale_color_manual(values = c('#9ccb86','#cf597e','steelblue'))+
scale_fill_manual(values = c('#9ccb86','#cf597e','steelblue'))+
theme(
text = element_text(size = 14, face = "bold"),
axis.title = element_text(size = 14),
axis.text = element_text(size = 14),
legend.title = element_text(size = 14),
legend.text = element_text(size = 14)) +
labs(
title = "",
x = "PC1",
y = "PC2")+
theme(legend.position = "none")
p2
ggsave("fig/k-means.png", dpi = 600, width = 8, height = 6)
$Cluster <- resultado_kmeans$cluster
dc_c
%>%
dc_c ggplot(aes(DC))+
geom_histogram(color = "white",fill = "steelblue")+
facet_wrap(~Cluster)+
#scale_x_continuous(breaks = c(0, 0.1, 0.2, 0.3), limits = c(0, 0.3))+
theme_minimal()+
theme(text= element_text(size = 14, face = "bold"))
= dc_c %>%
c_01 filter(Cluster == 1)
= dc_c %>%
c_02 filter(Cluster == 2)
= dc_c %>%
c_03 filter(Cluster == 3)
$cultivar c_01
[1] "80182RSF IPRO" "8579 RSF IPRO" "AS3730_IPRO" "BMX DOMINIO IPRO"
[5] "BMX_Ativa_RR" "BRSGO_9160_RR" "C2827 IPRO" "CZ58B28"
[9] "GA76 IPRO" "Garra IPRO" "HO MARACAÍ IPRO" "Juruena"
[13] "M8210" "M8210 IPRO" "M8210_IPRO" "M8372"
[17] "NA 6700 IPRO" "RK 7518 IPARO" "TMG 2383 IPRO" "TMG2281_IPRO"
[21] "TMG803" "W791 RR"
$cultivar c_02
[1] "BRSGO_8151_RR" "BRSGO_8661_RR" "GA 76 IPRO" "M 9144RR"
[5] "M8349 IPRO" "M9144 RR" "Syn1180_RR" "TMG 2285 IPRO"
$cultivar c_03
[1] "5G830_RR" "63i64RSF IPRO" "77i79RSF IPRO" "8473RSF"
[5] "BMX Garra RR" "BMX Potência RR" "BMX_Potencia_RR" "BS 2606 IPRO"
[9] "CD 2728 IPRO" "CD 2827 IPRO" "CZ 37B43 IPRO" "CZ48B32"
[13] "DM 75i76 IPRO" "DM73i75 IPRO" "GUAIA 7487 RR" "Ima 84114"
[17] "M 6410 IPRO" "M 8473 IPRO" "M220i2X" "M5947 IPRO"
[21] "M8336_RR" "NA 5909 RG" "NA_5909_RG" "NS 8338 IPRO"
[25] "TEC 7849 IPRO" "TMG 2181 IPRO" "TMG 2381 IPRO" "TMG 7067 IPRO"
[29] "TMG 803" "TMG1179_RR" "TMG1180_RR"
Number of trials by cultivar
<- ma_c %>%
study_counts filter(!cultivar %in% c("BÔNUS","74178 RSF IPRO")) %>%
group_by(cultivar,year) %>%
summarise(n_study = n_distinct(study)) %>%
group_by(cultivar) %>%
summarise(n_study = sum(n_study))
write_xlsx(study_counts,"data/study_counts.xlsx")
sum(study_counts$n_study)
[1] 173
Number of trials
= ma_c %>%
count_study #filter(!cultivar %in% c("BÔNUS","M9144_RR","74178 RSF IPRO")) %>%
group_by(study) %>%
summarise(n_study = n_distinct(year))
sum(count_study$n_study)
[1] 176
Descriptive analysis
Overall
= ma |>
sev filter(!is.na(sev)) |>
ggplot(aes(sev))+
geom_histogram(fill = "black", color = "white")+
#D2691E
::theme_few()+
ggthemes#theme_minimal()+
#facet_wrap(~year)+
labs(x = "TS Severity (%)",
y = "Count")+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
#00798C
#236E96
= ma |>
sev_log filter(!is.na(sev)) |>
ggplot(aes(log10(sev)))+
geom_histogram(fill = "black", color = "white")+
#theme_minimal()+
::theme_few()+
ggthemes#facet_wrap(~year)+
labs(x = "log10(TS severity)",
y = "Count")+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
= ma |>
yld filter(!is.na(yld)) |>
ggplot(aes(yld))+
geom_histogram(fill = "black", color = "white")+
#scale_y_continuous(breaks = c(0, 200, 400, 600,800), limits = c(0, 800))+
::theme_few()+
ggthemes#theme_minimal()+
#facet_wrap(~year)+
labs(x = "Yield (Kg/ha)",
y = "Count")+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
#FF9933
plot_grid(sev,sev_log,yld, labels = c("A","B","C"), nrow = 3, align = "V")
ggsave("fig/overall.png", bg = "white", dpi = 600, height = 9, width = 10)
Cultivar
Severity
= ma |>
sev_cultivar filter(ai == "_CHECK") %>%
filter(cultivar %in% c("63i64RSF IPRO","859 RSF IPRO",
"CD 2728 IPRO","DM 75i76 IPRO","M8210 IPRO","TMG 2181 IPRO","HO MARACAÍ IPRO")) %>%
filter(!is.na(sev)) |>
ggplot(aes(sev))+
geom_histogram(fill = "black", color = "white", bins = 10)+
#theme_minimal()+
::theme_few()+
ggthemes#facet_wrap(~year)+
labs(x = "TS severity",
y = "Count")+
#facet_wrap(~condition)+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
sev_cultivar
ggsave("fig/cultivar_severity.png", bg = "white", dpi = 600, height = 9, width = 10)
Yield
= ma |>
yld_cultivar filter(cultivar %in% c("63i64RSF IPRO","879 RSF IPRO",
"CD 2728 IPRO","DM 75i76 IPRO","M8210 IPRO","TMG 2181 IPRO","HO MARACAÍ IPRO")) %>%
filter(!is.na(yld)) |>
ggplot(aes(yld))+
geom_histogram(fill = "black", color = "white", bins = 10)+
#scale_y_continuous(breaks = c(0, 200, 400, 600,800), limits = c(0, 800))+
::theme_few()+
ggthemes#theme_minimal()+
#facet_wrap(~year)+
labs(x = "Yield (Kg/ha)",
y = "Count")+
#facet_wrap(~condition)+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
yld_cultivar
ggsave("fig/cultivar_yield.png", bg = "white", dpi = 600, height = 9, width = 10)
Active ingredients
Severity
= ma |>
sev_ai filter(ai %in% c("BIX+PROT+TRIFL","AZOX+TEBU+MANC","FLUX+PYRA","_CHECK")) %>%
filter(!is.na(sev)) |>
ggplot(aes(sev))+
geom_histogram(fill = "black", color = "white", bins = 10)+
#theme_minimal()+
::theme_few()+
ggthemes#facet_wrap(~year)+
labs(x = "TS severity",
y = "Count")+
facet_wrap(~ai)+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
sev_ai
ggsave("fig/ai_severity.png", bg = "white", dpi = 600, height = 9, width = 10)
Yield
= ma |>
yld_ai filter(ai %in% c("BIX+PROT+TRIFL",
"AZOX+TEBU+MANC","FLUX+PYRA","_CHECK")) %>%
filter(!is.na(yld)) |>
ggplot(aes(yld))+
geom_histogram(fill = "black", color = "white", bins = 15)+
#scale_y_continuous(breaks = c(0, 200, 400, 600,800), limits = c(0, 800))+
::theme_few()+
ggthemes#theme_minimal()+
#facet_wrap(~year)+
labs(x = "Yield (Kg/ha)",
y = "Count")+
facet_wrap(~ai)+
theme(axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
yld_ai
ggsave("fig/ai_yield.png", bg = "white", dpi = 600, height = 9, width = 10)
Cultivar x Active ingredients
Severity
= ma |>
sev_cultivar_ai filter(!is.na(sev)) %>%
filter(cultivar %in% c("63i64RSF IPRO","8579 RSF IPRO","CD 2728 IPRO", "DM 75i76 IPRO","M8210 IPRO","TMG 2181 IPRO")) %>%
filter(ai %in% c("BIX+PROT+TRIFL","AZOX+TEBU+MANC","FLUX+PYRA")) %>%
ggplot(aes(reorder(ai,+sev),sev))+
#geom_jitter(color = "black",alpha = .2, width = 0.09, size = 2)+
geom_boxplot(fill = NA, color = "steelblue",outlier.colour = NA,position = position_dodge(width = 0.95))+
theme_minimal()+
coord_flip()+
#facet_wrap(~condition)+
labs(x = "",
y = "TS Severity (%)")+
theme(strip.text = element_text(size = 12, face = "bold"),
axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
Yield
= ma |>
yld_cultivar_ai filter(!is.na(sev)) %>%
filter(cultivar %in% c("63i64RSF IPRO","8579 RSF IPRO","CD 2728 IPRO", "DM 75i76 IPRO","M8210 IPRO","TMG 2181 IPRO")) %>%
filter(ai %in% c("BIX+PROT+TRIFL","AZOX+TEBU+MANC","FLUX+PYRA")) %>%
ggplot(aes(reorder(ai,+yld),yld))+
#geom_jitter(color = "black",alpha = .2, width = 0.09, size = 2)+
geom_boxplot(fill = NA, color = "steelblue",outlier.colour = NA,position = position_dodge(width = 0.95))+
theme_minimal()+
coord_flip()+
#facet_wrap(~condition)+
labs(x = "",
y = "Yield (kg/ha)")+
theme(strip.text = element_text(size = 12, face = "bold"),
axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
Framework simulation
<-function(tamanho.amostra,correlacao,m1,m2,sigma1,sigma2)
gera.norm.bid.geral
{<-correlacao
ro<-tamanho.amostra
n<-matrix(0,n,2)
xfor (i in 1:n)
1]<-rnorm(1,m1,sigma1)
{x[i,2]<-rnorm(1,m2+ro*sigma1/sigma2*(x[i,1]-m1),sigma2*(sqrt(1-ro^2)))
x[i,
}return(x)
}
gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 2487387 132.9 4366044 233.2 4366044 233.2
Vcells 4919307 37.6 10146329 77.5 8387619 64.0
HIGH-TOLERANCE
= ma_c %>%
res filter(cultivar %in% c_03$cultivar)
unique(res$cultivar)
[1] "CD 2728 IPRO" "BMX Potência RR" "NA 5909 RG" "TMG 803"
[5] "TMG 2181 IPRO" "M 8473 IPRO" "TEC 7849 IPRO" "BMX Garra RR"
[9] "63i64RSF IPRO" "8473RSF" "TMG 7067 IPRO" "CD 2827 IPRO"
[13] "M 6410 IPRO" "GUAIA 7487 RR" "DM 75i76 IPRO" "Ima 84114"
[17] "NS 8338 IPRO" "BS 2606 IPRO" "DM73i75 IPRO" "TMG 2381 IPRO"
[21] "CZ48B32" "CZ 37B43 IPRO" "77i79RSF IPRO" "M5947 IPRO"
[25] "M220i2X" "5G830_RR" "BMX_Potencia_RR" "M8336_RR"
[29] "NA_5909_RG" "TMG1179_RR" "TMG1180_RR"
= res %>%
res_regression group_by(study) %>%
do(tidy(lm(.$yld ~ .$sev)))
= as.data.frame(res_regression)
res_regression res_regression
= res |>
res_severity filter(ai == "_CHECK") %>%
ggplot(aes(sev))+
geom_histogram(color = "white",fill = "steelblue", bins = 10)+
scale_x_continuous(limits = c(0, 100),
breaks = seq(0, 1000, by = 10))+
theme_bw()+
labs(x = "Severity (%)",
y = "Density")
= res |>
res_yield filter(ai == "_CHECK") %>%
ggplot(aes(yld))+
geom_histogram(color = "white",fill = "brown", bins = 10)+
scale_x_continuous(limits = c(2000, 7000),
breaks = seq(2000, 7000, by = 500))+
theme_bw()+
labs(x = "Yield (kg/ha)",
y = "")
plot_grid(res_severity,res_yield)
= res_regression |>
res_regression filter(term %in% c("(Intercept)",".$sev"))
$term== "(Intercept)",c("parameters")] <- "Intercept"
res_regression[res_regression$term== ".$sev",c("parameters")] <- "Slope"
res_regression[res_regression
= res_regression |>
res_b0 filter(parameters == "Intercept")
= res_regression %>%
res_b1filter(parameters == "Slope") %>%
filter(!estimate > 0)
mean(res_b0$estimate)
[1] 3902.37
sd(res_b0$estimate)
[1] 662.0473
mean(res_b1$estimate)
[1] -14.06671
sd(res_b1$estimate)
[1] 10.05459
Intercept
= res_regression |>
intercept_tss_res filter(parameters == "Intercept")
= mean(intercept_tss_res$estimate)
mean_intercept_res = sd(intercept_tss_res$estimate)
sd_intercept_res
plot(ecdf(intercept_tss_res$estimate))
curve(pnorm(x, mean_intercept_res,sd_intercept_res), add = T, col = "red")
Kolmogorov-Smirnov Test
= environment(ecdf(intercept_tss_res$estimate))$y
Fx_res_b0 = environment(ecdf(intercept_tss_res$estimate))$x
x_res_b0ks.test(Fx_res_b0, pnorm(x_res_b0, mean(intercept_tss_res$estimate), sd(intercept_tss_res$estimate)))
Exact two-sample Kolmogorov-Smirnov test
data: Fx_res_b0 and pnorm(x_res_b0, mean(intercept_tss_res$estimate), sd(intercept_tss_res$estimate))
D = 0.060606, p-value = 1
alternative hypothesis: two-sided
plot(Fx_res_b0, pnorm(x_res_b0, mean(intercept_tss_res$estimate), sd(intercept_tss_res$estimate)))
abline(a=0,b=1)
= intercept_tss_res %>%
intercep_plot_res ggplot(aes(estimate))+
geom_histogram(aes(y = ..density..), bins = 8,color = "white", fill = "#FF4917")+
#stat_function(fun=function(x) dnorm(x, mean_intercept_res, sd_intercept_res), color ="black", size =1.2)+
theme_bw()+
labs(x="Intercept (kg/ha)", y = "Density")
intercep_plot_res
Slope
= res_regression |>
slope_tss_res filter(parameters == "Slope") %>%
filter(!estimate > 0)
= mean(slope_tss_res$estimate)
mean_slope = sd(slope_tss_res$estimate)
sd_slope
plot(ecdf(slope_tss_res$estimate))
curve(pnorm(x, mean_slope, sd_slope), add = T, col = "red")
Kolmogorov-Smirnov Test
library(minpack.lm)
=environment(ecdf(-slope_tss_res$estimate))$y
Fx = environment(ecdf(-slope_tss_res$estimate))$x
x
= nlsLM(Fx ~ pgamma(x, shape, rate,log = FALSE) ,
slope_reg start = c(shape = 2.5, rate = 0.13),
control = nls.lm.control(maxiter = 1024))
summary(slope_reg)
Formula: Fx ~ pgamma(x, shape, rate, log = FALSE)
Parameters:
Estimate Std. Error t value Pr(>|t|)
shape 1.59411 0.18559 8.589 6.28e-09 ***
rate 0.10944 0.01482 7.382 9.85e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.05392 on 25 degrees of freedom
Number of iterations to convergence: 8
Achieved convergence tolerance: 1.49e-08
= summary(slope_reg)$coef[1]
shape_res = summary(slope_reg)$coef[2]
rate_res
=environment(ecdf(-slope_tss_res$estimate))$y
Fx = environment(ecdf(-slope_tss_res$estimate))$x
x ks.test(Fx, pgamma(x, shape_res, rate_res))
Exact two-sample Kolmogorov-Smirnov test
data: Fx and pgamma(x, shape_res, rate_res)
D = 0.14815, p-value = 0.9357
alternative hypothesis: two-sided
= summary(slope_reg)$coef[1]
shape_res = summary(slope_reg)$coef[2]
rate_res
= slope_tss_res %>%
slope_plot_res ggplot(aes(estimate))+
geom_histogram(aes(y = ..density..),bins = 20, color = "white", fill = "#159EE6")+
scale_x_continuous(breaks = c(-200,-150,-100,-50,0),
limits = c(-200,0))+
theme_bw()+
labs(x="Slope (kg/p.p.)", y = "Density")
slope_plot_res
Correlation
= res_regression |>
slope_coefficient_res ::filter(parameters == "Slope") |>
dplyr#filter(estimate < 0) %>%
::group_by(study) |>
dplyrsummarise(
Slope = estimate
)
1] = NULL
slope_coefficient_res[,
|>
slope_coefficient_res filter(!Slope == "NA") |>
summarise(
mean = mean(Slope))
= res_regression |>
intercept_coefficient_res filter(parameters == "Intercept") |>
group_by(study) |>
summarise(
Intercept = estimate
)
mean(intercept_coefficient_res$Intercept)
[1] 3902.37
sd(intercept_coefficient_res$Intercept)
[1] 662.0473
= cbind(slope_coefficient_res,intercept_coefficient_res)
regression_res = regression_res %>%
regression_res filter(Slope <0)
<- function(x, y) {
correlation if (length(x) != length(y)) {
stop("Os vetores 'x' e 'y' devem ter o mesmo comprimento")
}
<- cor(x, y, use = "complete.obs")
cor_result
return(cor_result)
}
correlation(regression_res$Slope, regression_res$Intercept)
[1] -0.518309
= regression_res %>%
corr_actual_plot_res mutate(alfa =(Slope/Intercept)*100) %>%
#filter(alfa > -3 & alfa < 0) %>%
ggplot(aes(Intercept,Slope))+
geom_point( size =2, color = "black")+
# geom_density_2d(color = "black")+
geom_smooth(method = lm, color = "red", se = F, size = 1.2)+
#scale_x_continuous(breaks = c(3500,4000,4500,5000,5500), limits = c(3500, 5500))+
scale_y_continuous(breaks = c(-160,-150,-140,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-160, 0))+
::theme_few()+
ggthemeslabs(y= "Slope",
x = "Intercept",
title = "Empirical: r = -0.518")+
theme(text = element_text(face = "bold"))
# coord_cartesian(
# xlim = c(0,10000))
corr_actual_plot_res
<-gera.norm.bid.geral(10000,0.51,0,0,1,1)
j_res
plot(j_res[,1],j_res[,2])
Severity
Kolmogorov-Smirnov Test
= ma_c %>%
sev_res filter(cultivar %in% c_03$cultivar) %>%
filter(ai %in% c("ZZ_CHECK","_CHECK"))
= sev_res$sev
sev_r = environment(ecdf(sev_r))$y
Fx_res = environment(ecdf(sev_r))$x/100
x_res
summary(nlsLM(Fx_res ~ pbeta(x_res, shape1, shape2, log = FALSE) ,
start = c(shape1 = 1, shape2 = 1),
control = nls.lm.control(maxiter = 100000)))
Formula: Fx_res ~ pbeta(x_res, shape1, shape2, log = FALSE)
Parameters:
Estimate Std. Error t value Pr(>|t|)
shape1 3.42200 0.09256 36.97 <2e-16 ***
shape2 4.75064 0.13386 35.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.03186 on 172 degrees of freedom
Number of iterations to convergence: 7
Achieved convergence tolerance: 1.49e-08
ks.test(Fx_res,pbeta(x_res,3.42200,4.75064))
Asymptotic two-sample Kolmogorov-Smirnov test
data: Fx_res and pbeta(x_res, 3.422, 4.75064)
D = 0.063218, p-value = 0.8777
alternative hypothesis: two-sided
Plot
plot(x_res,Fx_res)
curve(pbeta(x, 3.42200,4.75064),0,1, add = T)
= sev_res %>%
sev_dist_plot_res ggplot(aes(sev/100))+
geom_histogram(aes(y = ..density..),bins = 8, color = "white", fill = "darkgreen")+
scale_x_continuous(breaks = c(1.00,0.75,0.50,0.25,0.00),
limits = c(0.00,1.00))+
theme_bw()+
labs(x="Severity (proportion)", y = "Density")
sev_dist_plot_res
Relative yield loss
= regression_res %>%
empiric_ryl_resmutate(cc = (Slope/Intercept)*100)
# filter( cc > -3 & cc <0 )
head(empiric_ryl_res)
=empiric_ryl_res%>%
stat_emp_ryl_res summarise(data = "empirical",
mean = mean(cc),
median = median(cc),
variance = var(cc))
= empiric_ryl_res %>%
real_RYL_resggplot(aes(cc))+
geom_histogram(aes(y = ..density..), bins = 12, color = "white", fill = "black")+
# scale_y_continuous(limits = c(0,1.4),breaks = seq(0, 1.4,by = 0.4))+
geom_vline(data = stat_emp_ryl_res, aes(xintercept = mean, color = "Mean"),size =1)+
geom_vline(data = stat_emp_ryl_res, aes(xintercept = median, color = "Median"),size =1)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
::theme_few()+
ggthemesscale_color_calc()+
labs(x = "",
y = "Frequency",
color = "",
title = "Empirical | High")+
# xlim(-3,0.2)+
theme(legend.position = "none",
text = element_text(face = "bold"))
real_RYL_res
mean(res_b0$estimate)
[1] 3902.37
sd(res_b0$estimate)
[1] 662.0473
= pnorm(j_res[,2])
b0_res = qnorm(b0_res, 3902.37, 662*sqrt(33))
b0_t_res hist(b0_t_res, prob = T)
curve(dnorm(x, mean_intercept_res, sd_intercept_res), add = T)
mean(res_b0$estimate)
[1] 3902.37
sd(res_b0$estimate)
[1] 662.0473
= pnorm(j_res[,1])
b1_res = qgamma(b1_res, shape = shape_res, rate = rate_res)*-1
b1_t_res hist(b1_t_res, prob = T)
curve(dgamma(-x,shape=shape_res, rate = rate_res), add = T)
if(!require(devtools)) install.packages("devtools")
::install_github("kassambara/ggpubr")
devtools
correlation(b1_t_res, b0_t_res)
[1] -0.4762788
cor.test(b1_t_res, b0_t_res, method = "pearson")
Pearson's product-moment correlation
data: b1_t_res and b0_t_res
t = -54.161, df = 9998, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.4912926 -0.4609820
sample estimates:
cor
-0.4762788
= regression_res %>%
actual_cc_res mutate(cc = (Slope/Intercept)*100)
= data.frame(b0_t_res, b1_t_res,
simulated_cc_res cc = (b1_t_res/b0_t_res)*100)%>%
filter( cc > -3 & cc <0 )
ks.test(actual_cc_res$cc, simulated_cc_res$cc)
Asymptotic two-sample Kolmogorov-Smirnov test
data: actual_cc_res$cc and simulated_cc_res$cc
D = 0.14465, p-value = 0.6265
alternative hypothesis: two-sided
= environment(ecdf(actual_cc_res$cc))$y
fx_actual_res = environment(ecdf(simulated_cc_res$cc))$y
fx_simu_res ks.test((fx_actual_res),(fx_simu_res))
Asymptotic two-sample Kolmogorov-Smirnov test
data: (fx_actual_res) and (fx_simu_res)
D = 0.037033, p-value = 1
alternative hypothesis: two-sided
= ggplot()+
ecdf_damage_res stat_ecdf(aes(simulated_cc_res$cc,color = "Simulated"), size=1.2,geom = "step")+
stat_ecdf(aes(actual_cc_res$cc, color = "Empirical"), size=1.2,geom = "step")+
::theme_few()+
ggthemesscale_color_manual(values = c("black","orange"))+
labs(y = "Probability",
x = "Relative percent yield loss",
color ="",
title = "CDF | High")+
theme(legend.position = "top",
legend.background = element_blank(),
text = element_text(face = "bold"))
ecdf_damage_res
= data.frame(b0_t_res,b1_t_res) %>%
corr_sim_plot_res mutate(alfa =(b1_t_res/b0_t_res)*100 ) %>%
#filter(alfa > -3 & alfa < 0) %>%
ggplot(aes(b0_t_res,b1_t_res))+
geom_point( size =2, color = "orange", alpha =0.3)+
# geom_density_2d(color = "black")+
geom_smooth(method = lm, color = "red", se = F, size = 1.2)+
scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000), limits = c(0, 10000))+
scale_y_continuous(breaks = c(-160,-150,-140,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-160, 0))+
::theme_few()+
ggthemeslabs(y= "Slope",
x = "Intercept",
title = "Simulated: r = -0.476")+
coord_cartesian(
xlim = c(0,7000),
ylim = c(-160,0)
+
)theme(text = element_text(face = "bold"))
corr_sim_plot_res
MEDIUM-TOLERANCE
= ma_c %>%
m_sus filter(cultivar %in% c_01$cultivar)
unique(m_sus$cultivar)
[1] "M8210 IPRO" "NA 6700 IPRO" "8579 RSF IPRO" "Juruena"
[5] "W791 RR" "Garra IPRO" "TMG 2383 IPRO" "C2827 IPRO"
[9] "RK 7518 IPARO" "M8372" "M8210" "GA76 IPRO"
[13] "CZ58B28" "HO MARACAÍ IPRO" "BMX DOMINIO IPRO" "80182RSF IPRO"
[17] "TMG803" "BRSGO_9160_RR" "BMX_Ativa_RR" "AS3730_IPRO"
[21] "M8210_IPRO" "TMG2281_IPRO"
= m_sus %>%
m_sus_regression group_by(study) %>%
do(tidy(lm(.$yld ~ .$sev)))
= as.data.frame(m_sus_regression)
m_sus_regression m_sus_regression
= m_sus |>
m_sus_severity filter(ai == "_CHECK") %>%
ggplot(aes(sev))+
geom_histogram(color = "white",fill = "steelblue", bins = 10)+
scale_x_continuous(limits = c(0, 100),
breaks = seq(0, 1000, by = 10))+
theme_bw()+
labs(x = "Severity (%)",
y = "Density")
= m_sus |>
m_sus_yield filter(ai == "_CHECK") %>%
ggplot(aes(yld))+
geom_histogram(color = "white",fill = "brown", bins = 10)+
scale_x_continuous(limits = c(2000, 7000),
breaks = seq(2000, 7000, by = 500))+
theme_bw()+
labs(x = "Yield (kg/ha)",
y = "")
plot_grid(m_sus_severity,m_sus_yield)
= m_sus_regression |>
m_sus_regression filter(term %in% c("(Intercept)",".$sev"))
$term== "(Intercept)",c("parameters")] <- "Intercept"
m_sus_regression[m_sus_regression$term== ".$sev",c("parameters")] <- "Slope"
m_sus_regression[m_sus_regression
= m_sus_regression |>
m_sus_b0 filter(parameters == "Intercept")
= m_sus_regression |>
m_sus_b1 filter(parameters == "Slope") %>%
filter(!estimate >0)
mean(m_sus_b0$estimate)
[1] 4198.677
sd(m_sus_b0$estimate)
[1] 619.4013
mean(m_sus_b1$estimate)
[1] -32.01062
sd(m_sus_b1$estimate)
[1] 19.07879
Intercept
= m_sus_regression |>
intercept_tss_m_sus filter(parameters == "Intercept")
= mean(intercept_tss_m_sus$estimate)
mean_intercept_m_sus = sd(intercept_tss_m_sus$estimate)
sd_intercept_m_sus
plot(ecdf(intercept_tss_m_sus$estimate))
curve(pnorm(x, mean_intercept_m_sus,
add = T, col = "red") sd_intercept_m_sus),
Kolmogorov-Smirnov Test
= environment(ecdf(intercept_tss_m_sus$estimate))$y
Fx_m_sus_b0 = environment(ecdf(intercept_tss_m_sus$estimate))$x
x_m_sus_b0ks.test(Fx_m_sus_b0, pnorm(x_m_sus_b0, mean(intercept_tss_m_sus$estimate), sd(intercept_tss_m_sus$estimate)))
Exact two-sample Kolmogorov-Smirnov test
data: Fx_m_sus_b0 and pnorm(x_m_sus_b0, mean(intercept_tss_m_sus$estimate), sd(intercept_tss_m_sus$estimate))
D = 0.11111, p-value = 0.9974
alternative hypothesis: two-sided
plot(Fx_m_sus_b0, pnorm(x_m_sus_b0, mean(intercept_tss_m_sus$estimate), sd(intercept_tss_m_sus$estimate)))
abline(a=0,b=1)
= intercept_tss_m_sus %>%
intercep_plot_m_sus ggplot(aes(estimate))+
geom_histogram(aes(y = ..density..),bins = 8, color = "white", fill = "#FF4917")+
#stat_function(fun=function(x) dnorm(x, mean_intercept_m_sus, sd_intercept_m_sus), color ="black", size =1.2)+
theme_bw()+
labs(x="Intercept (kg/ha)", y = "Density")
intercep_plot_m_sus
Slope
= m_sus_regression |>
slope_tss_m_sus filter(parameters == "Slope") %>%
filter(!estimate > 0) %>%
filter(!estimate > -10)
= mean(slope_tss_m_sus$estimate)
mean_slope_m_sus = sd(slope_tss_m_sus$estimate)
sd_slope_m_sus
plot(ecdf(slope_tss_m_sus$estimate))
curve(pnorm(x, mean_slope_m_sus, sd_slope_m_sus), add = T, col = "red")
Kolmogorov-Smirnov Test
=environment(ecdf(-slope_tss_m_sus$estimate))$y
Fx_m_sus_b1 = environment(ecdf(-slope_tss_m_sus$estimate))$x
x_m_sus_b1
= nlsLM(Fx_m_sus_b1 ~ pgamma(x_m_sus_b1,
slope_m_sus log = FALSE) ,
shape, rate,start = c(shape = 2.5, rate = 0.13),
control = nls.lm.control(maxiter = 1024))
summary(slope_m_sus)
Formula: Fx_m_sus_b1 ~ pgamma(x_m_sus_b1, shape, rate, log = FALSE)
Parameters:
Estimate Std. Error t value Pr(>|t|)
shape 3.959797 0.186074 21.28 3.29e-15 ***
rate 0.117930 0.006016 19.60 1.58e-14 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.02042 on 20 degrees of freedom
Number of iterations to convergence: 6
Achieved convergence tolerance: 1.49e-08
= summary(slope_m_sus)$coef[1]
shape_m_sus = summary(slope_m_sus)$coef[2]
rate_m_sus
=environment(ecdf(-slope_tss_m_sus$estimate))$y
Fx_m_sus_b1 = environment(ecdf(-slope_tss_m_sus$estimate))$x
x_m_sus_b1 ks.test(Fx_m_sus_b1, pgamma(x_m_sus_b1, shape_m_sus, rate_m_sus))
Exact two-sample Kolmogorov-Smirnov test
data: Fx_m_sus_b1 and pgamma(x_m_sus_b1, shape_m_sus, rate_m_sus)
D = 0.045455, p-value = 1
alternative hypothesis: two-sided
= slope_tss_m_sus %>%
slope_plot_m_sus ggplot(aes(estimate))+
geom_histogram(aes(y = ..density..),bins = 8, color = "white", fill = "#159EE6")+
theme_bw()+
scale_x_continuous(breaks = c(-200,-150,-100,-50,0),
limits = c(-200,0))+
labs(x="Slope (kg/p.p.)", y = "Density")
slope_plot_m_sus
Correlation
= m_sus_regression |>
slope_coefficient_m_sus filter(parameters == "Slope") |>
#filter(estimate < 0) %>%
group_by(study) |>
summarise(
Slope = estimate
)
1] = NULL
slope_coefficient_m_sus[,
|>
slope_coefficient_m_sus filter(!Slope == "NA") |>
summarise(
mean = mean(Slope))
= m_sus_regression |>
intercept_coefficient_m_sus filter(parameters == "Intercept") |>
group_by(study) |>
summarise(
Intercept = estimate
)
mean(intercept_coefficient_m_sus$Intercept)
[1] 4198.677
sd(intercept_coefficient_m_sus$Intercept)
[1] 619.4013
= cbind(slope_coefficient_m_sus,intercept_coefficient_m_sus)
regression_m_sus
= regression_m_sus %>%
regression_m_sus filter(Slope <0)
correlation(regression_m_sus$Slope, regression_m_sus$Intercept)
[1] -0.7341185
= regression_m_sus %>%
corr_actual_plot_m_sus mutate(alfa =(Slope/Intercept)*100) %>%
#filter(alfa > -3 & alfa < 0) %>%
ggplot(aes(Intercept,Slope))+
geom_point( size =2, color = "black")+
# geom_density_2d(color = "black")+
geom_smooth(method = lm, color = "red", se = F, size = 1.2)+
# scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000), limits = c(0, 10000))+
scale_y_continuous(breaks = c(-160,-150,-140,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-160, 0))+
::theme_few()+
ggthemeslabs(y= "Slope",
x = "Intercept",
title = "Empirical: r = -0.734")+
theme(text = element_text(face = "bold"))
# coord_cartesian(
# xlim = c(0,10000))
corr_actual_plot_m_sus
plot_grid(corr_actual_plot_res,corr_actual_plot_m_sus,ncol = 2, labels = c("AUTO"))
<-gera.norm.bid.geral(10000,0.73,0,0,1,1)
j_m_sus
plot(j_m_sus[,1],j_m_sus[,2])
Severity
Kolmogorov-Smirnov Test
= ma_c %>%
sev_m_sus filter(cultivar %in% c_01$cultivar) %>%
filter(ai %in% c("ZZ_CHECK","_CHECK"))
= sev_m_sus$sev
sev_m_s = environment(ecdf(sev_m_s))$y
Fx_m_sus= environment(ecdf(sev_m_s))$x/100
x_m_sus
summary(nlsLM(Fx_m_sus ~ pbeta(x_m_sus, shape1, shape2, log = FALSE) ,
start = c(shape1 = 1, shape2 = 1),
control = nls.lm.control(maxiter = 100000)))
Formula: Fx_m_sus ~ pbeta(x_m_sus, shape1, shape2, log = FALSE)
Parameters:
Estimate Std. Error t value Pr(>|t|)
shape1 4.4564 0.1497 29.77 <2e-16 ***
shape2 7.8184 0.2690 29.07 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.03163 on 97 degrees of freedom
Number of iterations to convergence: 7
Achieved convergence tolerance: 1.49e-08
ks.test(Fx_m_sus,pbeta(x_m_sus,4.4564,7.8184))
Exact two-sample Kolmogorov-Smirnov test
data: Fx_m_sus and pbeta(x_m_sus, 4.4564, 7.8184)
D = 0.080808, p-value = 0.9053
alternative hypothesis: two-sided
Plot
plot(x_m_sus,Fx_m_sus)
curve(pbeta(x, 4.4564,7.8184),0,1, add = T)
= sev_m_sus %>%
sev_dist_plot_m_sus ggplot(aes(sev/100))+
geom_histogram(aes(y = ..density..), bins = 8, color = "white", fill = "darkgreen")+
scale_x_continuous(breaks = c(1.00,0.75,0.50,0.25,0.00),
limits = c(0.00,1.00))+
theme_bw()+
labs(x="Severity (proportion)", y = "Density")
sev_dist_plot_m_sus
Relative yield loss
= regression_m_sus %>%
empiric_ryl_m_susmutate(cc = (Slope/Intercept)*100)
# filter( cc > -3 & cc <0 )
head(empiric_ryl_m_sus)
=empiric_ryl_m_sus%>%
stat_emp_ryl_m_sus summarise(data = "empirical",
mean = mean(cc),
median = median(cc),
variance = var(cc))
= empiric_ryl_m_sus %>%
real_RYL_m_susggplot(aes(cc))+
geom_histogram(aes(y = ..density..), bins = 10, color = "white", fill = "black")+
# scale_y_continuous(limits = c(0,1.4),breaks = seq(0, 1.4,by = 0.4))+
geom_vline(data = stat_emp_ryl_m_sus, aes(xintercept = mean, color = "Mean"),size =1)+
geom_vline(data = stat_emp_ryl_m_sus, aes(xintercept = median, color = "Median"),size =1)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
::theme_few()+
ggthemesscale_color_calc()+
labs(x = "",
y = "",
color = "",
title = "Empirical | Medium")+
# xlim(-3,0.2)+
theme(legend.position = "none",
text = element_text(face = "bold"))
real_RYL_m_sus
mean(m_sus_b0$estimate)
[1] 4198.677
sd(m_sus_b0$estimate)
[1] 619.4013
= pnorm(j_m_sus[,2])
b0_m_sus = qnorm(b0_m_sus, 4198.677, 619*sqrt(27))
b0_t_m_sus hist(b0_t_m_sus, prob = T)
curve(dnorm(x, mean_intercept_m_sus, sd_intercept_m_sus), add = T)
= pnorm(j_m_sus[,1])
b1_m_sus = qgamma(b1_m_sus, shape = shape_m_sus, rate = rate_m_sus)*-1
b1_t_m_sus hist(b1_t_m_sus, prob = T)
curve(dgamma(-x,shape=shape_m_sus, rate = rate_m_sus), add = T)
correlation(b1_t_m_sus, b0_t_m_sus)
[1] -0.7118311
cor.test(b1_t_m_sus, b0_t_m_sus, method = "pearson")
Pearson's product-moment correlation
data: b1_t_m_sus and b0_t_m_sus
t = -101.34, df = 9998, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.7213667 -0.7020257
sample estimates:
cor
-0.7118311
= regression_m_sus %>%
actual_cc_m_sus mutate(cc = (Slope/Intercept)*100)
= data.frame(b0_t_m_sus, b1_t_m_sus,
simulated_cc_m_sus cc = (b1_t_m_sus/b0_t_m_sus)*100)%>%
filter( cc > -3 & cc <0 )
ks.test(actual_cc_m_sus$cc, simulated_cc_m_sus$cc)
Asymptotic two-sample Kolmogorov-Smirnov test
data: actual_cc_m_sus$cc and simulated_cc_m_sus$cc
D = 0.16419, p-value = 0.5123
alternative hypothesis: two-sided
= environment(ecdf(actual_cc_m_sus$cc))$y
fx_actual_m_sus = environment(ecdf(simulated_cc_m_sus$cc))$y
fx_simu_m_sus ks.test((fx_actual_m_sus),(fx_simu_m_sus))
Asymptotic two-sample Kolmogorov-Smirnov test
data: (fx_actual_m_sus) and (fx_simu_m_sus)
D = 0.039995, p-value = 1
alternative hypothesis: two-sided
= ggplot()+
ecdf_damage_m_sus stat_ecdf(aes(simulated_cc_m_sus$cc,color = "Simulated"), size=1.2,geom = "step")+
stat_ecdf(aes(actual_cc_m_sus$cc, color = "Empirical"), size=1.2,geom = "step")+
::theme_few()+
ggthemesscale_color_manual(values = c("black","orange"))+
labs(y = "",
x = "Relative percent yield loss",
color ="",
title = "CDF | Medium")+
theme(legend.position = "top",
legend.background = element_blank(),
text = element_text(face = "bold"))
ecdf_damage_m_sus
= data.frame(b0_t_m_sus,b1_t_m_sus) %>%
corr_sim_plot_m_sus mutate(alfa =(b0_t_m_sus/b1_t_m_sus)*100 ) %>%
#filter(alfa > -3 & alfa < 0) %>%
ggplot(aes(b0_t_m_sus,b1_t_m_sus))+
geom_point( size =2, color = "orange", alpha =0.3)+
# geom_density_2d(color = "black")+
geom_smooth(method = lm, color = "red", se = F, size = 1.2)+
scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000), limits = c(0, 10000))+
scale_y_continuous(breaks = c(-160,-150,-140,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-160, 0))+
::theme_few()+
ggthemeslabs(y= "Slope",
x = "Intercept",
title = "Simulated: r = -0.711")+
coord_cartesian(
xlim = c(0,7000),
ylim = c(-160,0))+
theme(text = element_text(face = "bold"))
corr_sim_plot_m_sus
plot_grid(corr_actual_plot_res,corr_actual_plot_m_sus,corr_sim_plot_res,corr_sim_plot_m_sus, ncol = 2, labels = c("AUTO"))
LOW-TOLERANCE
= ma_c %>%
susceptible filter(cultivar %in% c_02$cultivar)
= susceptible%>%
sus_regression group_by(study,block) %>%
do(tidy(lm(.$yld ~ .$sev)))
= as.data.frame(sus_regression)
sus_regression sus_regression
= susceptible |>
sus_severity # filter(ai == "_CHECK") %>%
ggplot(aes(sev))+
geom_histogram(color = "white",fill = "steelblue", bins = 15)+
scale_x_continuous(limits = c(0, 100),
breaks = seq(0, 1000, by = 10))+
theme_bw()+
labs(x = "Severity (%)",
y = "Density")
= susceptible |>
sus_yield #filter(ai == "_CHECK") %>%
ggplot(aes(yld))+
geom_histogram(color = "white",fill = "brown", bins = 10)+
scale_x_continuous(limits = c(2000, 7000),
breaks = seq(2000, 7000, by = 500))+
theme_bw()+
labs(x = "Yield (kg/ha)",
y = "")
plot_grid(sus_severity,sus_yield)
= sus_regression |>
sus_regression filter(term %in% c("(Intercept)",".$sev"))
$term== "(Intercept)",c("parameters")] <- "Intercept"
sus_regression[sus_regression$term== ".$sev",c("parameters")] <- "Slope"
sus_regression[sus_regression
= sus_regression |>
sus_b0 filter(parameters == "Intercept") %>%
filter(!estimate < 3000)
= sus_regression |>
sus_b1 filter(parameters == "Slope") %>%
filter(!estimate >0)
mean(sus_b0$estimate)
[1] 4818.456
sd(sus_b0$estimate)
[1] 426.985
mean(sus_b1$estimate)
[1] -76.35969
sd(sus_b1$estimate)
[1] 40.67328
Intercept
= sus_regression |>
intercept_tss_sus filter(parameters == "Intercept") %>%
filter(!estimate < 3000)
= mean(intercept_tss_sus$estimate)
mean_intercept_sus = sd(intercept_tss_sus$estimate)
sd_intercept_sus
plot(ecdf(intercept_tss_sus$estimate))
curve(pnorm(x, mean_intercept_sus,sd_intercept_sus), add = T, col = "red")
Kolmogorov-Smirnov Test
= environment(ecdf(intercept_tss_sus$estimate))$y
Fx_sus_b0 = environment(ecdf(intercept_tss_sus$estimate))$x
x_sus_b0ks.test(Fx_sus_b0, pnorm(x_sus_b0, mean(intercept_tss_sus$estimate), sd(intercept_tss_sus$estimate)))
Exact two-sample Kolmogorov-Smirnov test
data: Fx_sus_b0 and pnorm(x_sus_b0, mean(intercept_tss_sus$estimate), sd(intercept_tss_sus$estimate))
D = 0.2, p-value = 0.832
alternative hypothesis: two-sided
plot(Fx_sus_b0, pnorm(x_sus_b0, mean(intercept_tss_sus$estimate), sd(intercept_tss_sus$estimate)))
abline(a=0,b=1)
= intercept_tss_sus %>%
intercep_plot_sus ggplot(aes(estimate))+
geom_histogram(aes(y = ..density..),bins = 8, color = "white", fill = "#FF4917")+
# stat_function(fun=function(x) dnorm(x, mean_intercept_sus, sd_intercept_sus), color ="black", size =1.2)+
theme_bw()+
labs(x="Intercept (kg/ha)", y = "Density")
intercep_plot_sus
Slope
= sus_regression |>
slope_tss_sus filter(parameters == "Slope") %>%
filter(!estimate > 0)
= mean(slope_tss_sus$estimate)
mean_slope = sd(slope_tss_sus$estimate)
sd_slope
plot(ecdf(slope_tss_sus$estimate))
curve(pnorm(x, mean_slope, sd_slope), add = T, col = "red")
Kolmogorov-Smirnov Test
=environment(ecdf(-slope_tss_sus$estimate))$y
Fx = environment(ecdf(-slope_tss_sus$estimate))$x
x
= nlsLM(Fx ~ pgamma(x, shape, rate,log = FALSE) ,
slope_sus start = c(shape = 2.5, rate = 0.13),
control = nls.lm.control(maxiter = 1024))
summary(slope_sus)
Formula: Fx ~ pgamma(x, shape, rate, log = FALSE)
Parameters:
Estimate Std. Error t value Pr(>|t|)
shape 3.595815 0.174872 20.56 7.46e-16 ***
rate 0.048475 0.002561 18.93 4.21e-15 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.02137 on 22 degrees of freedom
Number of iterations to convergence: 6
Achieved convergence tolerance: 1.49e-08
= summary(slope_sus)$coef[1]
shape_sus = summary(slope_sus)$coef[2]
rate_sus
=environment(ecdf(-slope_tss_sus$estimate))$y
Fx = environment(ecdf(-slope_tss_sus$estimate))$x
x ks.test(Fx, pgamma(x, shape_sus, rate_sus))
Exact two-sample Kolmogorov-Smirnov test
data: Fx and pgamma(x, shape_sus, rate_sus)
D = 0.041667, p-value = 1
alternative hypothesis: two-sided
= summary(slope_sus)$coef[1]
shape_sus = summary(slope_sus)$coef[2]
rate_sus
= slope_tss_sus %>%
slope_plot_sus ggplot(aes(estimate))+
geom_histogram(aes(y = ..density..),bins = 8, color = "white", fill = "#159EE6")+
scale_x_continuous(breaks = c(-200,-150,-100,-50,0), limits = c(-200,0))+
theme_bw()+
labs(x="Slope (kg/p.p.)", y = "Density")
slope_plot_sus
Correlation
= sus_regression |>
slope_coefficient_sus filter(parameters == "Slope") |>
#filter(estimate < 0) %>%
group_by(block) |>
summarise(
Slope = estimate
)
1] = NULL
slope_coefficient_sus[,
|>
slope_coefficient_sus filter(!Slope == "NA") |>
summarise(
mean = mean(Slope))
= sus_regression |>
intercept_coefficient_sus filter(parameters == "Intercept") |>
group_by(block) |>
summarise(
Intercept = estimate
)
mean(intercept_coefficient_sus$Intercept)
[1] 4472.231
sd(intercept_coefficient_sus$Intercept)
[1] 882.7419
= cbind(slope_coefficient_sus,intercept_coefficient_sus)
regression_sus = regression_sus %>%
regression_sus filter(Slope <0)
correlation(regression_sus$Slope, regression_sus$Intercept)
[1] -0.5292833
= regression_sus %>%
corr_actual_plot_sus mutate(alfa =(Slope/Intercept)*100) %>%
#filter(alfa > -3 & alfa < 0) %>%
ggplot(aes(Intercept,Slope))+
geom_point( size =2, color = "black")+
# geom_density_2d(color = "black")+
geom_smooth(method = lm, color = "red", se = F, size = 1.2)+
# scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000), limits = c(0, 10000))+
scale_y_continuous(breaks = c(-160,-150,-140,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-160, 0))+
::theme_few()+
ggthemeslabs(y= "Slope",
x = "Intercept",
title = "Empirical: r = -0.529")+
theme(text = element_text(face = "bold"))
# coord_cartesian(
# xlim = c(0,10000))
corr_actual_plot_sus
<-gera.norm.bid.geral(10000,0.529,0,0,1,1)
j_sus
plot(j_sus[,1],j_sus[,2])
Severity
Kolmogorov-Smirnov Test
= ma_c %>%
sev_sus filter(cultivar %in% c_02$cultivar) %>%
filter(ai %in% c("ZZ_CHECK","_CHECK"))
= sev_sus$sev
sev_s = environment(ecdf(sev_s))$y
Fx_sus= environment(ecdf(sev_s))$x/100
x_sus
summary(nlsLM(Fx_sus ~ pbeta(x_sus, shape1, shape2, log = FALSE) ,
start = c(shape1 = 1, shape2 = 1),
control = nls.lm.control(maxiter = 100000)))
Formula: Fx_sus ~ pbeta(x_sus, shape1, shape2, log = FALSE)
Parameters:
Estimate Std. Error t value Pr(>|t|)
shape1 1.4193 0.1828 7.766 5.32e-08 ***
shape2 5.9858 0.9731 6.151 2.35e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.07092 on 24 degrees of freedom
Number of iterations to convergence: 7
Achieved convergence tolerance: 1.49e-08
ks.test(Fx_sus,pbeta(x_sus,1.4193,5.9858))
Exact two-sample Kolmogorov-Smirnov test
data: Fx_sus and pbeta(x_sus, 1.4193, 5.9858)
D = 0.15385, p-value = 0.926
alternative hypothesis: two-sided
Plot
plot(x_sus,Fx_sus)
curve(pbeta(x, 1.4193,5.9858),0,1, add = T)
= sev_sus %>%
sev_dist_plot_sus ggplot(aes(sev/100))+
geom_histogram(aes(y = ..density..), bins = 12, color = "white", fill = "darkgreen")+
scale_x_continuous(breaks = c(1.00,0.75,0.50,0.25,0.00),
limits = c(0.00,1.00))+
theme_bw()+
labs(x="Severity (proportion)", y = "Density")
sev_dist_plot_sus
Relative yield loss
= regression_sus %>%
empiric_ryl_susmutate(cc = (Slope/Intercept)*100)
# filter( cc > -3 & cc <0 )
head(empiric_ryl_sus)
=empiric_ryl_sus%>%
stat_emp_ryl_sus summarise(data = "empirical",
mean = mean(cc),
median = median(cc),
variance = var(cc))
= empiric_ryl_sus %>%
real_RYL_susggplot(aes(cc))+
geom_histogram(aes(y = ..density..), bins = 10, color = "white", fill = "black")+
# scale_y_continuous(limits = c(0,1.4),breaks = seq(0, 1.4,by = 0.4))+
geom_vline(data = stat_emp_ryl_sus, aes(xintercept = mean, color = "Mean"),size =1)+
geom_vline(data = stat_emp_ryl_sus, aes(xintercept = median, color = "Median"),size =1)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
::theme_few()+
ggthemesscale_color_calc()+
labs(x = "",
y = "",
color = "",
title = "Empirical | Low")+
# xlim(-3,0.2)+
theme(legend.position = "none",
text = element_text(face = "bold"))
real_RYL_sus
mean(sus_b0$estimate)
[1] 4818.456
sd(sus_b0$estimate)
[1] 426.985
= pnorm(j_sus[,2])
b0_sus = qnorm(b0_sus, 4818.456, 426*sqrt(24))
b0_t_sus hist(b0_t_sus, prob = T)
curve(dnorm(x, mean_intercept_sus, sd_intercept_sus), add = T)
= pnorm(j_sus[,1])
b1_sus = qgamma(b1_sus, shape = shape_sus, rate = rate_sus)*-1
b1_t_sus hist(b1_t_sus, prob = T)
curve(dgamma(-x,shape=shape_sus, rate = rate_sus), add = T)
correlation(b1_t_sus, b0_t_sus)
[1] -0.5110051
cor.test(b1_t_sus, b0_t_sus, method = "pearson")
Pearson's product-moment correlation
data: b1_t_sus and b0_t_sus
t = -59.442, df = 9998, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.5253435 -0.4963766
sample estimates:
cor
-0.5110051
= regression_sus %>%
actual_cc_sus mutate(cc = (Slope/Intercept)*100)
= data.frame(b0_t_sus, b1_t_sus, cc = (b1_t_sus/b0_t_sus)*100)%>%
simulated_cc_sus filter( cc > -3 & cc <0 )
ks.test(actual_cc_sus$cc, simulated_cc_sus$cc)
Asymptotic two-sample Kolmogorov-Smirnov test
data: actual_cc_sus$cc and simulated_cc_sus$cc
D = 0.14025, p-value = 0.7341
alternative hypothesis: two-sided
= environment(ecdf(actual_cc_sus$cc))$y
fx_actual_sus = environment(ecdf(simulated_cc_sus$cc))$y
fx_simu_sus ks.test((fx_actual_sus),(fx_simu_sus))
Asymptotic two-sample Kolmogorov-Smirnov test
data: (fx_actual_sus) and (fx_simu_sus)
D = 0.041657, p-value = 1
alternative hypothesis: two-sided
= ggplot()+
ecdf_damage_sus stat_ecdf(aes(simulated_cc_sus$cc,color = "Simulated"), size=1.2,geom = "step")+
stat_ecdf(aes(actual_cc_sus$cc, color = "Empirical"), size=1.2,geom = "step")+
::theme_few()+
ggthemesscale_color_manual(values = c("black","orange"))+
labs(y = "",
x = "Relative percent yield loss",
color ="",
title = "CDF | Low")+
theme(legend.position = "top",
legend.background = element_blank(),
text = element_text(face = "bold"))
ecdf_damage_sus
= data.frame(b0_t_sus,b1_t_sus) %>%
corr_sim_plot_sus mutate(alfa =(b1_t_sus/b0_t_sus)*100 ) %>%
#filter(alfa > -3 & alfa < 0) %>%
ggplot(aes(b0_t_sus,b1_t_sus))+
geom_point( size =2, color = "orange", alpha =0.3)+
# geom_density_2d(color = "black")+
geom_smooth(method = lm, color = "red", se = F, size = 1.2)+
scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000), limits = c(0, 10000))+
scale_y_continuous(breaks = c(-160,-150,-140,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-160, 0))+
::theme_few()+
ggthemeslabs(y= "Slope",
x = "Intercept",
title = "Simulated: r = -0.511")+
coord_cartesian(
xlim = c(0,7000),
ylim = c(-160,0))+
theme(text = element_text(face = "bold"))
corr_sim_plot_sus
plot_grid(corr_actual_plot_sus,corr_sim_plot_sus, ncol = 2, labels = c("AUTO"))
Joining
plot_grid(intercep_plot_res,intercep_plot_m_sus,intercep_plot_sus,slope_plot_res,slope_plot_m_sus,slope_plot_sus,sev_dist_plot_res,sev_dist_plot_m_sus,sev_dist_plot_sus, ncol = 3, labels = c("AUTO"))
ggsave("fig/empirical_distribution.png", bg = "white",
dpi = 600, width = 10, height = 8)
Soybean price
= gsheet2tbl("https://docs.google.com/spreadsheets/d/1-jQ9OgWdLQCb0iB0FqbrhuVi7LiNhqxvf9QU4-iuc3o/edit#gid=1085329359") soybean
= soybean %>%
sbr_price filter(year>=2018) %>%
mutate(price = (price/60)/4,
national_price = (national_price/60)/4)
sbr_price
mean(sbr_price$price)
[1] 0.2932792
sd(sbr_price$price)
[1] 0.02167031
Observed distribution
%>%
sbr_price ggplot(aes(price))+
geom_histogram(bins = 10, fill = "steelblue", color = "white")+
::theme_few()+
ggthemeslabs(x = "Soybean prince",
y = "Frequency")+
scale_x_continuous(breaks = seq(0,1,by=0.025))+
theme(text = element_text(size = 12, face = "bold"),
axis.title = element_text(size = 14, face = "bold"),
legend.position = "none")
hist((sbr_price$price), prob = T)
curve(dnorm(x, mean(sbr_price$price), sd(sbr_price$price)),0.15,0.35, add = T)
plot(ecdf(sbr_price$price))
curve(pnorm(x, mean(sbr_price$price), sd(sbr_price$price)),0.2,0.35, add = T)
mean(sbr_price$price)
[1] 0.2932792
median(sbr_price$price)
[1] 0.2935692
Shapiro
shapiro.test(sbr_price$price)
Shapiro-Wilk normality test
data: sbr_price$price
W = 0.99021, p-value = 0.6164
Kolmogorov-Smirnov Test
= environment(ecdf(sbr_price$price))$y
Fx = environment(ecdf(sbr_price$price))$x
xks.test(Fx, pnorm(x, mean(sbr_price$price), sd(sbr_price$price)))
Asymptotic two-sample Kolmogorov-Smirnov test
data: Fx and pnorm(x, mean(sbr_price$price), sd(sbr_price$price))
D = 0.054545, p-value = 0.9967
alternative hypothesis: two-sided
plot(Fx, pnorm(x, mean(sbr_price$price), sd(sbr_price$price)))
Vizualization
= sbr_price %>%
price_plot ggplot(aes(price))+
geom_histogram(aes(y = ..density..),bins = 10, color = "white", fill = "black")+ #"#1C8C20"
#stat_function(fun=function(x) dnorm(x, mean(sbr_price$price), sd(sbr_price$price)), color= "black", size = 1.2)+
::theme_few()+
ggthemeslabs(x="Soybean price (USD/kg)", y = "Frequency")+
scale_x_continuous(breaks = seq(0,1,by=0.025))+
theme(text = element_text(size = 12, face = "bold"),
axis.title = element_text(size = 14, face = "bold"),
legend.position = "none")
price_plot
ggsave("fig/soybean_price.png", bg = "white",
dpi = 600, height = 5, width = 6)
Simulated variables
#Soybean
= mean(sbr_price$price)
mean_price = sd(sbr_price$price)
sd_price
# High
= mean(intercept_coefficient_res$Intercept)
mean_intercept_res = sd(intercept_coefficient_res$Intercept)
sd_intercept_res = slope_coefficient_res %>%
slope_coefficient_res filter(!Slope < -40) %>%
filter(!Slope > 0)
= mean(slope_coefficient_res$Slope)
mean_res = sd(slope_coefficient_res$Slope)
sd_res
= 3.42200
s1_sev_res = 4.75064
s2_sev_res
# Medium
= mean(intercept_coefficient_m_sus$Intercept)
mean_intercept_m_sus = sd(intercept_coefficient_m_sus$Intercept)
sd_intercept_m_sus = slope_coefficient_m_sus %>%
slope_coefficient_m_sus filter(!Slope > 0) %>%
filter(!Slope > -10)
= mean(slope_coefficient_m_sus$Slope)
mean_m_sus = sd(slope_coefficient_m_sus$Slope)
sd_m_sus
= 4.4564
s1_sev_m_sus = 7.8184
s2_sev_m_sus
# Low
= mean(intercept_coefficient_sus$Intercept)
mean_intercept_sus = sd(intercept_coefficient_sus$Intercept)
sd_intercept_sus = slope_coefficient_sus
slope_coefficient_sus = mean(slope_coefficient_sus$Slope)
mean_sus = sd(slope_coefficient_sus$Slope)
sd_sus
= 1.4193
s1_sev_sus = 5.9858 s2_sev_sus
Monte Carlo simulation
set.seed(1)
=40000
n= seq(0,1, by=0.05)
lambda = seq(-10, 260, by=15)
fun_price = 1
n_aplication = 10
operational_cost
= as.matrix(data.table::CJ(lambda,fun_price))
comb_matrix colnames(comb_matrix) = c("lambda","fun_price")
= cbind(comb_matrix,operational_cost, n_aplication)
comb_matrix = comb_matrix[,"n_aplication"]*(comb_matrix[,"operational_cost"]+comb_matrix[,"fun_price"] )
C = cbind(comb_matrix,C)
comb_matrix
= length(comb_matrix[,1])*n
N = matrix(0, ncol = 24, nrow =N)
big_one 1] = rep(comb_matrix[,1],n)
big_one[,2] = rep(comb_matrix[,2],n)
big_one[,3] = rep(comb_matrix[,3],n)
big_one[,4] = rep(comb_matrix[,4],n)
big_one[,5] = rep(comb_matrix[,5],n)
big_one[,
set.seed(1)
#Moderate Resistant (MR)
= rbeta(N, s1_sev_res, s2_sev_res)
sn_res = sn_res*(1-big_one[,1])
sf_res
# Moderate Susceptible (MS)
= rbeta(N, s1_sev_m_sus, s2_sev_m_sus)
sn_m_sus = sn_m_sus*(1-big_one[,1])
sf_m_sus
# Susceptible (S)
= rbeta(N, s1_sev_sus, s2_sev_sus)
sn_sus = sn_sus*(1-big_one[,1])
sf_sus
# simulating the coeficientes
## Moderate Resistant (MR)
set.seed(1)
<-gera.norm.bid.geral(N,0.51,0,0,1,1)
normal_correlated_res= pnorm(normal_correlated_res[,2])
b0_n_res = pnorm(normal_correlated_res[,1])
b1_n_res = qnorm(b0_n_res, mean_intercept_res,sd_intercept_res)
b0_res = -qgamma(b1_n_res, shape_res, rate_res,)
b1_res rm(b0_n_res,b1_n_res,normal_correlated_res)
## Moderate Susceptible (MS)
set.seed(1)
<-gera.norm.bid.geral(N,0.73,0,0,1,1)
normal_correlated_m_sus= pnorm(normal_correlated_m_sus[,2])
b0_n_m_sus = pnorm(normal_correlated_m_sus[,1])
b1_n_m_sus = qnorm(b0_n_m_sus, mean_intercept_m_sus,sd_intercept_m_sus)
b0_m_sus = -qgamma(b1_n_m_sus, shape_m_sus, rate_m_sus,)
b1_m_sus rm(b0_n_m_sus,b1_n_m_sus,normal_correlated_m_sus)
## Susceptible (S)
set.seed(1)
<-gera.norm.bid.geral(N,0.52,0,0,1,1)
normal_correlated_sus= pnorm(normal_correlated_sus[,2])
b0_n_sus = pnorm(normal_correlated_sus[,1])
b1_n_sus = qnorm(b0_n_sus, mean_intercept_sus,sd_intercept_sus)
b0_sus = -qgamma(b1_n_sus, shape_sus, rate_sus,)
b1_sus rm(b0_n_sus,b1_n_sus,normal_correlated_sus)
# Calculating the alha coeficient
## Moderate Resistant (MR)
= (b1_res/b0_res)*100
alfa_res
## Moderate Susceptible (MS)
= (b1_m_sus/b0_m_sus)*100
alfa_m_sus
## Susceptible (S)
= (b1_sus/b0_sus)*100
alfa_sus
# Calculating yield gain
## Moderate Resistant (MR)
= b0_res - (-alfa_res*b0_res*sn_res)
yn_res = b0_res - (-alfa_res*b0_res*sf_res)
yf_res
## Moderate Susceptible (MS)
= b0_m_sus - (-alfa_m_sus*b0_m_sus*sn_m_sus)
yn_m_sus = b0_m_sus - (-alfa_m_sus*b0_m_sus*sf_m_sus)
yf_m_sus
## Susceptible (S)
= b0_sus - (-alfa_sus*b0_sus*sn_sus)
yn_sus = b0_sus - (-alfa_sus*b0_sus*sf_sus)
yf_sus
# Simulating soybean price
set.seed(1)
= rnorm(N, mean(sbr_price$price),sd(sbr_price$price))
soy_price
#income = yield_gain*soy_price # calculating the income
6] = yn_res
big_one[,7] = yf_res
big_one[,8] = yn_m_sus
big_one[,9] = yf_m_sus
big_one[,10] = yn_sus
big_one[,11] = yf_sus
big_one[,12] = soy_price
big_one[,13] = b1_res
big_one[,14] = b1_m_sus
big_one[,15] = b1_sus
big_one[,16] = alfa_res
big_one[,17] = alfa_m_sus
big_one[,18] = alfa_sus
big_one[,19] = b0_res
big_one[,20] = b0_m_sus
big_one[,21] = b0_sus
big_one[,22] = sn_res
big_one[,23] = sn_m_sus
big_one[,24] = sn_sus
big_one[,colnames(big_one) = c("lambda","fun_price","operational_cost","n_aplication","C","yn_res","yf_res","yn_m_sus","yf_m_sus","yn_sus","yf_sus","soy_price","b1_res","b1_m_sus","b1_sus","alfa_res","alfa_m_sus","alfa_sus","b0_res","b0_m_sus","b0_sus","sn_res","sn_m_sus" ,"sn_sus")
= as.data.frame(big_one) %>%
big_one_df filter(b0_res>=0) %>%
filter(b0_sus>=0) %>%
filter(yn_res>0) %>%
filter(yn_sus>0) %>%
filter(alfa_res > -3 & alfa_res < 0) %>%
filter(alfa_sus > -3 & alfa_sus < 0) %>%
mutate(yield_gain_res = yf_res-yn_res,
yield_gain_m_sus = yf_m_sus-yn_m_sus,
yield_gain_sus = yf_sus-yn_sus,
yield_gain_perc_res = ((yf_res/yn_res)-1)*100,
yield_gain_perc_m_sus = ((yf_m_sus/yn_m_sus)-1)*100,
yield_gain_perc_sus = ((yf_sus/yn_sus)-1)*100,
income_res = yield_gain_res*soy_price,
income_m_sus = yield_gain_m_sus*soy_price,
income_sus = yield_gain_sus*soy_price,
CP = C/soy_price,
profit_res = (income_res>=C)*1,
profit_m_sus = (income_m_sus>=C)*1,
profit_sus = (income_sus>=C)*1) %>%
filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60)
gc()
#write_csv(big_one_df,"data/big_one_df.csv")
= read_csv("data/big_one_df.csv") big_one_df
Plotting variables
= big_one_df %>%
sn_res_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(sn_res))+
geom_histogram(color = "white", fill = "steelblue", bins = 10, alpha= .5)+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(face = "bold",size = 16))+
labs(y = "Frequency",
x = "Target spot severity (%)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
sn_m_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(sn_m_sus))+
geom_histogram(color = "white", fill = "darkgreen", bins = 10, alpha= .5)+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Target spot severity (%)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
sn_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(sn_sus))+
geom_histogram(color = "white", fill = "brown", bins = 10, alpha= .5)+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Target spot severity (%)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
b0_res_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(b0_res))+
geom_histogram(color = "white", fill = "steelblue", bins = 10, alpha= .5)+
scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000), limits = c(0, 7000))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "Frequency",
x = "Intercept (kg/ha)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
b0_m_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(b0_m_sus))+
geom_histogram(color = "white", fill = "darkgreen", bins = 10, alpha= .5)+
scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000), limits = c(0, 7000))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Intercept (kg/ha)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
b0_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(b0_sus))+
geom_histogram(color = "white", fill = "brown", bins = 10, alpha= .5)+
scale_x_continuous(breaks = c(0,1000,2000,3000,4000,5000,6000,7000), limits = c(0, 7000))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Intercept (kg/ha)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
b1_res_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(b1_res))+
geom_histogram(color = "white", fill = "steelblue", bins = 10, alpha= .5)+
scale_x_continuous(breaks = c(-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-100,0))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "Frequency",
x = "Slope (kg/p.p.)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
b1_m_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(b1_m_sus))+
geom_histogram(color = "white", fill = "darkgreen", bins = 10, alpha= .5)+
scale_x_continuous(breaks = c(-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0), limits = c(-100,0))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Slope (kg/p.p.)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
b1_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(b1_sus))+
geom_histogram(color = "white", fill = "brown", bins = 10, alpha= .5)+
scale_x_continuous(breaks = c(-200,-180,-160,
-140,-120, -100,-80,-60,-40,-20,0), limits = c(-200,0))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Slope (kg/p.p.)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
alpha_res_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(alfa_res))+
geom_histogram(color = "white", fill = "black", bins = 10)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "Frequency",
x = "Yield loss (%/p.p.)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
alpha_m_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(alfa_m_sus))+
geom_histogram(color = "white", fill = "black", bins = 10)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Yield loss (%/p.p.)")+
::theme_few()
ggthemes
gc()
= big_one_df %>%
alpha_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(alfa_sus))+
geom_histogram(color = "white", fill = "black", bins = 10)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
theme(text = element_text(face = "bold", size = 14),
axis.title = element_text(size = 16, face = "bold"))+
labs(y = "",
x = "Yield loss (%/p.p.)")+
::theme_few()
ggthemes
gc()
#alpha_res_graphic,alpha_m_sus_graphic,alpha_sus_graphic,
plot_grid(sn_res_graphic,sn_m_sus_graphic,sn_sus_graphic,b0_res_graphic,b0_m_sus_graphic,b0_sus_graphic,b1_res_graphic,b1_m_sus_graphic,b1_sus_graphic, ncol = 3, labels = c("(a)", "(b)", "(c)", "(d)","(e)","(f)","(g)","(h)","(i)"),label_x = -0.03)
ggsave("fig/simulated_variables.png", dpi = 1000, bg = "white",
height = 8, width = 12)
Plotting RYL
= big_one_df %>%
stat_simu_ryl_res filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
summarise(data = "Simulated",
mean = mean(alfa_res),
median = median(alfa_res),
variance = var(alfa_res))
= big_one_df %>%
alpha_res_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(alfa_res))+
geom_histogram(color = "white", fill = "black", bins = 10)+
geom_vline(data = stat_simu_ryl_res, aes(xintercept = mean, color = "Mean"),size =1)+
geom_vline(data = stat_simu_ryl_res, aes(xintercept = median, color = "Median"),size =1)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
::theme_few()+
ggthemesscale_color_calc()+
labs(x = "Relative yield loss (%/p.p.)",
y = "Frequency",
color = "",
title = "Simulated | High")+
# xlim(-3,0.2)+
theme(legend.position = "none",
text = element_text(face = "bold"))
gc()
= big_one_df %>%
stat_simu_ryl_m_sus filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
summarise(data = "Simulated",
mean = mean(alfa_m_sus),
median = median(alfa_m_sus),
variance = var(alfa_m_sus))
= big_one_df %>%
alpha_m_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(alfa_m_sus))+
geom_histogram(color = "white", fill = "black", bins = 10)+
geom_vline(data = stat_simu_ryl_m_sus, aes(xintercept = mean, color = "Mean"),size =1)+
geom_vline(data = stat_simu_ryl_m_sus, aes(xintercept = median, color = "Median"),size =1)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
::theme_few()+
ggthemesscale_color_calc()+
labs(x = "Relative yield loss (%/p.p.)",
y = "",
color = "",
title = "Simulated | Medium")+
# xlim(-3,0.2)+
theme(legend.position = "none",
text = element_text(face = "bold"))
gc()
= big_one_df %>%
stat_simu_ryl_sus filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
summarise(data = "Simulated",
mean = mean(alfa_sus),
median = median(alfa_sus),
variance = var(alfa_sus))
= big_one_df %>%
alpha_sus_graphic filter(C <= 180) %>%
filter(lambda >= 0.4) %>%
filter(lambda <= 0.8) %>%
filter(C >= 60) %>%
ggplot(aes(alfa_sus))+
geom_histogram(color = "white", fill = "black", bins = 10)+
geom_vline(data = stat_simu_ryl_sus, aes(xintercept = mean, color = "Mean"),size =1)+
geom_vline(data = stat_simu_ryl_sus, aes(xintercept = median, color = "Median"),size =1)+
scale_x_continuous(breaks = c(-2.0,-1.75,-1.50,-1.25,-1.00,-0.75,-0.50,-0.25,0.0), limits = c(-2.0,0.0))+
::theme_few()+
ggthemesscale_color_calc()+
labs(x = "Relative yield loss (%/p.p.)",
y = "",
color = "",
title = "Simulated | Low")+
# xlim(-3,0.2)+
theme(legend.position = "none",
text = element_text(face = "bold"))
gc()
plot_grid(corr_actual_plot_res,corr_actual_plot_m_sus,corr_actual_plot_sus,corr_sim_plot_res,corr_sim_plot_m_sus,corr_sim_plot_sus,
real_RYL_res,real_RYL_m_sus,real_RYL_sus,alpha_res_graphic,alpha_m_sus_graphic,alpha_sus_graphic,
ecdf_damage_res,ecdf_damage_m_sus,ecdf_damage_sus,ncol = 3, labels = c("(a)", "(b)", "(c)", "(d)","(e)","(f)","(g)","(h)","(i)", "(j)","(k)","(l)","(m)","(n)","(o)"), label_x = -0.03,label_size = 24)
ggsave("fig/RYL.png", dpi = 600, height = 20, width = 18)