-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
131 lines (99 loc) · 6.03 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
title: "FMI330"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
> Example R scripts to create a dose-response curve and extract EC~X~-values.
## Installing and loading packages
Before the fun-part of dose-response modelling, a handful of add-on packages have to be installed. `tidyverse` and `readxl` provide functionalities for easy data handling and reading straight from .xlsx files, respectively. `drc` is used to perform dose-response modelling, and `lmtest` and `sandwich` provide additional functionalities for standard error and confidence interval estimations.
```{r,eval=FALSE}
install.packages(c("tidyverse", "multcomp", "drc", "lmtest", "sandwich"))
```
After succesful installation, the packages need to be loaded by using the `library()` functionality.
```{r,message=FALSE}
library(multcomp)
library(tidyverse)
library(readxl)
library(drc)
library(lmtest)
library(sandwich)
```
We are now ready to load the data!
## Loading and cleaning up the data
First, we load the raw data and inspect it.
```{r}
data <- read_xlsx(path = "Data/Diuron_DRC_Data_RevLee.xlsx", sheet = "Summary") %>%
select(-SampleName, -Replicate) %>%
rename(Concentration = concentration,
Fronds_number_inhibition = FN_Normalization_PERCENT,
Frond_size_inhibition = FS_Normalization_PERCENT,
Photosystem_II_inhibition = PSII_Normalization_PERCENT,
ROS_formation = `ROS_Formation_Fold increase`,
Chlorophyll_A_inhibition = `Chlorophyll a_inhibition_PERCENT`,
Chlorophyll_B_inhibition = `Chlorophyll b_inhibition_PERCENT`,
Carotenoids_inhibition = Carotenoids_inhibition_PERCENT) %>%
filter(!str_detect(Note, "CT")) %>%
select(-Note)
data
```
# Fronds number
## Visualizing the raw data
Let's take a look at the reproduction along the stressor gradient. Note that this plot is meant to help you understand the data, and is not part of your reports!
```{r}
data %>%
ggplot() +
geom_point(mapping = aes(x = Concentration, y = Fronds_number_inhibition), size = 2, alpha = 0.5) +
labs(x = "Diuron (mg/L)",
y = "Fronds number inhibition (%)") +
theme_light()
```
## LOEC and NOEC derivation
Based on the figure of the raw data, we can see that there is a strong decreasing trend in reproduction with increasing Concentration. To find out statistically significant differences, we need to run a ANOVA with Dunnett's *post hoc* test.
In the first step, we have to transfrom the `Concentration` from a numeric column to a (categorical) factor column; otherwise it is not possible to run a *post hoc* analysis. This happens inside the `mutate()` function. In the next step, we run a ANOVA. But instead of using a convenience function, we do it more manual, by fitting a linear model using `lm()`. Note that a ANOVA is nothing else than a linear model. Within the linear model, the contrast treatment specifies that Concentration `"0"` contains the control values. The linear model is then used in a generalized linear hypothesis test with the `glht()` function. Inside this function, the multiple comparison is set to Dunnett's contrasts (everything vs. the control), and variance-covariance matrix is updated using the sandwich estimator. In the final step, the *p*-values are adjusted for multiple comparisons using Holm's method.
```{r}
data %>%
mutate(Concentration = fct_relevel(as.character(Concentration), "0")) %>%
lm(formula = Fronds_number_inhibition ~ Concentration, data = ., contrasts = list(Concentration = "contr.treatment")) %>%
glht(linfct = mcp(Concentration = "Dunnett"), vcov = sandwich) %>%
summary(test = adjusted(type = "holm"))
```
From the results we can deduce that the LOEC has a concentration of 0.01 mg/L. As this is the lowest treatment concentration, the NOEC has to be < 0.01 mg/L.
## Dose-response model fitting
From the visualization of the raw data, we see a very clear monotonic dose-response pattern! Let's fit a four-parametric log-logistic model using the `drc` package. We then take a look at the results (i.e., the four parameters, or coefficients) using `coeftest` with adjusted variance-covariance matrix.
```{r}
fronds_number_inhibition.drm <- data %>%
drm(formula = Fronds_number_inhibition ~ Concentration, data = .,
fct = LL.4(names = c("Slope", "Lower Limit", "Upper Limit", "EC50")))
fronds_number_inhibition.drm %>%
coeftest(vcov. = sandwich)
```
The fitted values for the parameters seem to make sense. The lower and upper limit are in accordance with what we observe in the raw data, and the EC~50~ value is also realistic.
## EC~X~ derivation
Let's take a look at the corrected parameter estimates and the EC~5~, EC~10~, and EC~50~ values with 95% confidence limits.
```{r}
fronds_number_inhibition.drm %>%
ED(respLev = c(5, 10, 50), interval = "delta", vcov. = sandwich)
```
## Plotting of the dose-response curve
Now that we got all necessary information, let's plot the dose-response curve. This is *not* straight forward, as it requires advanced use of the `predict()` function, so feel free to copy-paste.
```{r}
data.frame(Concentration = seq(from = min(data$Concentration),
to = max(data$Concentration),
length.out = 1000)) %>%
mutate(fit = predict(fronds_number_inhibition.drm, newdata = .),
lwr = predict(fronds_number_inhibition.drm, newdata = ., interval = "confidence", vcov. = sandwich)[, 2],
upr = predict(fronds_number_inhibition.drm, newdata = ., interval = "confidence", vcov. = sandwich)[, 3]) %>%
ggplot() +
geom_ribbon(mapping = aes(x = Concentration, ymin = lwr, ymax = upr), alpha = 0.2) +
geom_line(mapping = aes(x = Concentration, y = fit), size = 1) +
geom_point(mapping = aes(x = Concentration, y = Fronds_number_inhibition), data = data, size = 2, alpha = 0.5) +
labs(x = "Diuron (mg/L)",
y = "Fronds number inhibition (%)") +
theme_light()
```
Looks good, so let's save the plot.
```{r}
ggsave("Figures/Fronds number inhibition.png", height = 5.25, width = 7, units = "in", dpi = 600, type = "cairo-png")
```