library(readxl)
library(drc)
## Loading required package: MASS
## 
## 'drc' has been loaded.
## Please cite R and 'drc' if used for a publication,
## for references type 'citation()' and 'citation('drc')'.
## 
## Attaching package: 'drc'
## The following objects are masked from 'package:stats':
## 
##     gaussian, getInitial
library(magrittr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
## 
##     select
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
library(broom)
library(ggplot2)
datosB <- read_excel("C:/Users/Heymdall/Documents/Paula/Echinochloa/Ensayo 6.1/14ddt 6.1.xlsx", sheet = "DRC", range = "A1:E82")
datos14 <- read_excel("C:/Users/Heymdall/Documents/Paula/Echinochloa/Ensayo 6.1/14ddt 6.1.xlsx", 
    sheet = "DRC", range = "A1:E70")
Datos <-datosB %>% 
  mutate_at(vars(ID, Dosis), as.factor) %>%
  as.data.frame()
head(Datos)
DatosDRC <-Datos %>% 
  as.data.frame()

ALTURA

## Altura MA
p1 <- Datos %>% 
  filter(ID == "MA") %>%
  ggplot(aes(x = Dosis, y = `Altura (cm)`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 50) +
  labs(title = "Altura MA",
       x = "Dosis (gr i.a)",
       y = "Altura (cm)")

## Altura UM
p2 <- Datos %>% 
  filter(ID == "UM") %>%
  ggplot(aes(x = Dosis, y = `Altura (cm)`)) + 
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 50) +
  labs(title = "Altura UM",
       x = "Dosis (gr i.a)",
       y = "Altura (cm)")

## Altura LP
p3 <- Datos %>% 
  filter(ID == "LP") %>%
  ggplot(aes(x = Dosis, y = `Altura (cm)`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 50) +
  labs(title = "Altura LP",
       x = "Dosis (gr i.a)",
       y = "Altura (cm)")

## Altura VE
p4 <- Datos %>% 
  filter(ID == "VE") %>%
  ggplot(aes(x = Dosis, y = `Altura (cm)`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 50) +
  labs(title = "Altura VE",
       x = "Dosis (gr i.a)",
       y = "Altura (cm)")

## Altura AR
p5 <- Datos %>% 
  filter(ID == "AR") %>%
  ggplot(aes(x = Dosis, y = `Altura (cm)`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 50) +
  labs(title = "Altura AR",
       x = "Dosis (gr i.a)",
       y = "Altura (cm)")

grid.arrange(p1, p2,p3, p4, p5, ncol = 2)

fct = LL.4(names=c(“Hill slope”,“Min”,“Max”,“EC50”)))

modelAlt <- drm(data=datos14, formula = `Altura (cm) ~Dosis, curveid = ID, fct = LL.4(names=c(“Hill slope”,“Min”,“Max”,“EC50”))) tidy(modelAlt)

plot(modelAlt, legendPos = c(3000,25))

ED (modelAlt, respLev = 50, interval = “delta”)

compParm(modelAlt,“e”,“-”)

modelFit(modelAlt)

% DAÑO

p1 <- Datos %>% 
  filter(ID == "MA") %>%
  ggplot(aes(x = Dosis, y = `% Daño`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Daño MA",
       x = "Dosis (gr i.a)",
       y = "% Daño")

## Altura UM
p2 <- Datos %>% 
  filter(ID == "UM") %>%
  ggplot(aes(x = Dosis, y = `% Daño`)) + 
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Daño UM",
       x = "Dosis (gr i.a)",
       y = "% Daño")

## Altura LP
p3 <- Datos %>% 
  filter(ID == "LP") %>%
  ggplot(aes(x = Dosis, y = `% Daño`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Daño LP",
       x = "Dosis (gr i.a)",
       y = "% Daño")

## Altura VE
p4 <- Datos %>% 
  filter(ID == "VE") %>%
  ggplot(aes(x = Dosis, y = `% Daño`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Daño VE",
       x = "Dosis (gr i.a)",
       y = "% Daño")

## Altura AR
p5 <- Datos %>% 
  filter(ID == "AR") %>%
  ggplot(aes(x = Dosis, y = `% Daño`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Daño AR",
       x = "Dosis (gr i.a)",
       y = "% Daño")

grid.arrange(p1, p2,p3, p4, p5, ncol = 2)

names=c(“Hill slope”,“Min”,“Max”,“EC50”)

modelDano <- drm(data=datos14[-(47:70),], 
           formula = `% Daño`~Dosis, 
           curveid = ID,
           fct = LL.4())
## Control measurements detected for level: AR
tidy(modelDano)
plot(modelDano, legendPos = c(50,140))

ED (modelDano, respLev = 50, interval = "delta")
## 
## Estimated effective doses
## 
##           Estimate Std. Error      Lower      Upper
## e:LP:50    1140.64     525.24      77.35    2203.93
## e:UM:50   21400.17   83315.58 -147263.41  190063.75
compParm(modelDano,"e","-")
## 
## Comparison of parameter 'e' 
## 
##       Estimate Std. Error t-value p-value
## UM-LP    20260      83317  0.2432  0.8092
modelFit(modelDano)

% SOBREVIVENCIA

p1 <- Datos %>% 
  filter(ID == "MA") %>%
  ggplot(aes(x = Dosis, y = `% Sobrevivencia`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Sobrevivencia MA",
       x = "Dosis (gr i.a)",
       y = "% Sobrevivencia")

## Altura UM
p2 <- Datos %>% 
  filter(ID == "UM") %>%
  ggplot(aes(x = Dosis, y = `% Sobrevivencia`)) + 
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Sobrevivencia UM",
       x = "Dosis (gr i.a)",
       y = "% Sobrevivencia")

## Altura LP
p3 <- Datos %>% 
  filter(ID == "LP") %>%
  ggplot(aes(x = Dosis, y = `% Sobrevivencia`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Sobrevivencia LP",
       x = "Dosis (gr i.a)",
       y = "% Sobrevivencia")

## Altura VE
p4 <- Datos %>% 
  filter(ID == "VE") %>%
  ggplot(aes(x = Dosis, y = `% Sobrevivencia`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Sobrevivencia VE",
       x = "Dosis (gr i.a)",
       y = "% Sobrevivencia")

## Altura AR
p5 <- Datos %>% 
  filter(ID == "AR") %>%
  ggplot(aes(x = Dosis, y = `% Sobrevivencia`)) +
  geom_boxplot() +
  scale_fill_manual(values = "black") + ylim(0, 100) +
  labs(title = "% Sobrevivencia AR",
       x = "Dosis (gr i.a)",
       y = "% Sobrevivencia")

grid.arrange(p1, p2,p3, p4, p5, ncol = 2)

(names=c(“Hill slope”,“Min”,“Max”,“EC50”)

modelSobr <- drm(data=datos14[-(47:70),], 
           formula = `% Sobrevivencia`~Dosis, 
           curveid = ID,
           fct = LL.4())
## Control measurements detected for level: AR
tidy(modelSobr)
plot(modelSobr, legendPos = c(50, 40))

ED (modelSobr, respLev = 50, interval = "delta")
## 
## Estimated effective doses
## 
##            Estimate  Std. Error       Lower       Upper
## e:LP:50  4.1887e+04  2.1418e+05 -3.9169e+05  4.7547e+05
## e:UM:50  1.2461e+03  6.1660e+02 -2.1114e+00  2.4944e+03
compParm(modelSobr,"e","-")
## 
## Comparison of parameter 'e' 
## 
##       Estimate Std. Error t-value p-value
## UM-LP   -40641     214179 -0.1898  0.8505
modelFit(modelSobr)