-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysis.R
More file actions
437 lines (310 loc) · 16.6 KB
/
Analysis.R
File metadata and controls
437 lines (310 loc) · 16.6 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# install.packages(c("tidyverse", "data.table", "scales", "drc", "lme4"))
library(tidyverse)
library(data.table)
library(scales)
library(drc)
library(lme4)
###########################################################################################################
###########################################################################################################
## Load files
file_path_4C = "../4C Toxicity Data for review/csv files/"
unionid_4C <- fread(paste0(file_path_4C,
"Unionid assessment 4C trial for review.csv"), na.strings = ".")
ZBM_lw_4C <- fread(paste0(file_path_4C,
"ZBM weights and length 4 C trial for review.csv"), na.strings = ".")
zebra_mussel_4C <- fread(paste0(file_path_4C,
"/Zebra Mussel assessment 4 C trial for review.csv"), na.strings = ".")
file_path_20C = "../20C Toxicity Data for review/csv files/"
list.files(file_path_20C)
unionid_20C <- fread(paste0(file_path_20C,
"Unionid Mussel Assessment 20C for review.csv"), na.strings = ".")
ZBM_lw_20C <- fread(paste0(file_path_20C,
"ZBM weights and length 20 C trial for review.csv"), na.strings = ".")
zebra_mussel_20C <- fread(paste0(file_path_20C,
"/Zebra Mussel assessment 20C trial for review.csv"), na.strings = ".")
###########################################################################################################
###########################################################################################################
## Check and Format files
## Fix what is not by renaming or deleting phantom columns
## (N.B., ":= NULL" is how data.table deletes columns)
## Add in Temp as a new column
## and then merge together across trials
colnames(unionid_20C)
colnames(unionid_4C)
unionid_4C[ , V10 := NULL]
setnames(unionid_4C, "TrtGroup", "Trtgroup")
unionid_20C[ , Temp := 20]
unionid_4C[ , Temp := 4]
unionid <- rbind(unionid_20C, unionid_4C)
colnames(ZBM_lw_4C)
colnames(ZBM_lw_20C)
setnames(ZBM_lw_20C, "Expdur(h)", "ExpDur(h)")
colnames(ZBM_lw_4C) == colnames(ZBM_lw_20C)
ZBM_lw_20C[ , Temp := 20]
ZBM_lw_4C[ , Temp := 4]
ZBM_lw = rbind(ZBM_lw_20C, ZBM_lw_4C)
ZBM_lw
colnames(zebra_mussel_20C)
colnames(zebra_mussel_4C)
zebra_mussel_4C[ , c('V17', 'V18', 'V19') := NULL]
colnames(zebra_mussel_20C) == colnames(zebra_mussel_4C)
zebra_mussel_20C[ , Temp := 20]
zebra_mussel_4C[ , Temp := 4]
zebra_mussel <- rbind(zebra_mussel_20C, zebra_mussel_4C)
###########################################################################################################
###########################################################################################################
## Examine unionid survival data
summary(unionid)
unionid[ , Tank := factor(Tank)]
unionidPlot <- ggplot(unionid[ TimeCode == 7, ], aes(x = mpCO2, y = Alive)) + geom_jitter(width = 0, height = 0.05) +
facet_grid( . ~ Temp,
labeller = label_bquote(
cols = .(Temp)*degree*"C"),
scales = "free_x") +
theme_minimal() +
xlab(expression(mu*"atm"~CO[2])) +
scale_x_continuous(label = comma) +
stat_smooth(method = 'glm', method.args = list(family = 'binomial') )
unionidPlot
ggsave("uninidPlotSurvival.pdf", unionidPlot)
## We can only run a glm on the 7hr, 20C data becaues it is the only one with a partial response
unionid[ , pCO2 := mpCO2 / 1000.0]
summary(unionid[ , .(pCO2, mpCO2, Tank)])
unoidByTank <- unionid[ , .(Alive = sum(Alive, na.rm = TRUE),
Byssus = sum(Byssus, na.rm = TRUE),
pCO2 = mean(pCO2), mpCO2 = mean(mpCO2),
pCOSD = sd(pCO2), .N),
by = .(Tank, TimeCode, Temp)]
unoidByTank[ , Dead := N - Alive]
unoidByTank[ , pAlive := Alive/N]
unoidByTank[ , pByssus := Byssus / N]
unoidByTank[ TimeCode == 7 & Temp == 20, ]
## Fit dose-response curve and estiamte LC end points
unoidDRC <- drm(pAlive ~ pCO2, weights = N, data = unoidByTank[ TimeCode == 7 & Temp == 20, ],
fct = LL.2(), type = 'binomial')
unoidDRC
plot(unoidDRC)
ED(unoidDRC, respLev = c( 50, 20, 1, 99), interval = 'delta')
## look at unionid Byssus
summary(unionid)
unionid[ , TimeCode2 := factor(TimeCode)]
levels(unionid$TimeCode2) <- c("7 day", "96 hr")
unionid[ , TimeCode2 := factor(TimeCode2, levels = c( "96 hr", "7 day"))]
unionidPlotByssus <- ggplot(unionid, aes(x = mpCO2, y = Byssus)) +
geom_jitter(width = 0, height = 0.05) +
facet_grid( TimeCode2 ~ Temp,
labeller = label_bquote(
cols = .(Temp)*degree*"C"),
scales = "free_x") +
theme_minimal() +
xlab(expression("mP"~CO[2])) +
scale_x_continuous(label = comma) +
stat_smooth(method = 'glm', method.args = list(family = 'binomial') )
unionidPlotByssus
ggsave("uninidPlotByssus.pdf", unionidPlotByssus)
## Fit dose-response curve and estiamte LC end points
## unoidDRC_byssus_7_20 <- drm(pByssus ~ pCO2, weights = N,
## data = unoidByTank[ TimeCode == 7 & Temp == 20, ],
## fct = LL.2(), type = 'binomial')
unoidDRC_byssus_96_20 <- drm(pByssus ~ pCO2, weights = N,
data = unoidByTank[ TimeCode == 96 & Temp == 20, ],
fct = LL.2(), type = 'binomial')
unoidDRC_byssus_96_20
plot(unoidDRC_byssus_96_20)
ED(unoidDRC_byssus_96_20, respLev = c( 50, 20, 1, 99), interval = 'delta')
unoidDRC_byssus_96_4 <- drm(pByssus ~ pCO2, weights = N,
data = unoidByTank[ TimeCode == 96 & Temp == 4, ],
fct = LL.2(), type = 'binomial')
unoidDRC_byssus_96_4
plot(unoidDRC_byssus_96_4)
ED(unoidDRC_byssus_96_4, respLev = c( 50, 20, 1, 99), interval = 'delta')
unoidDRC_byssus_7_4 <- drm(pByssus ~ pCO2, weights = N,
data = unoidByTank[ TimeCode == 7 & Temp == 4, ],
fct = LL.2(), type = 'binomial')
unoidDRC_byssus_7_4
plot(unoidDRC_byssus_7_4)
##ED(unoidDRC_byssus_7_4, respLev = c( 50, 1, 99), interval = 'delta')
###########################################################################################################
###########################################################################################################
## Analyze Zebra Mussel length and weight data
setnames(ZBM_lw, gsub(" |\\(|\\)", "", colnames(ZBM_lw)))
ZBM_lw[ , TempFactor := factor(Temp)]
## Group B is not different
summary(ZBM_lw[ grep("Control", TrtGroup), lm(Nettissdrywtg/Lengthmm ~ TrtGroup)])
ggplot(ZBM_lw, aes(x = ExpDurh, y = Lengthmm, fill = TrtGroup)) + geom_boxplot() +
facet_grid( Size ~ Temp, scale = "free_y", labeller = label_bquote(cols = "Temperature"~ .(Temp) *degree*"C")) +
scale_fill_manual(values = c("blue", "red", "orange")) +
theme_minimal() +
ylab("Length (mm)") +
xlab("Exposure duration")
summary(lm(Lengthmm ~ TrtGroup* Size + Temp, data = ZBM_lw[ ExpDurh == '72h', ]))
summary(ZBM_lw[ grep("Control", TrtGroup), lm(Nettissdrywtg/Lengthmm ~ factor(Temp) + ExpDurh)])
ggplot(ZBM_lw[ grep("Control", TrtGroup), ], aes(x = factor(Temp), y = Nettissdrywtg/Lengthmm )) +
geom_boxplot(notch = TRUE) + theme_minimal() + xlab("Temperature") + ylab("Condition") +
facet_grid(~ ExpDurh)
###########################################################################################################
###########################################################################################################
## Analyze Zebra Mussel mortality data
setnames(zebra_mussel, "ExpDur(h)", "ExpDur")
zebra_mussel[ , pCO2 := mpCO2/ 1000 ]
zebra_mussel[ , pAlive := Alive / Total ]
zebra_mussel
zmAlivePlot <-
ggplot(data = zebra_mussel[ TimeCode == 7], aes(x = mpCO2, y = pAlive, weight = Total)) +
geom_jitter(width = 0, height = 0.05) +
facet_grid( Size ~ Temp,
labeller = label_bquote(
rows = "Size: "~.(Size),
cols = .(Temp)*degree*"C"),
scales = "free_x") +
theme_minimal() +
xlab(expression("mP"~CO[2])) +
scale_x_continuous(label = comma, trans = 'log10') +
stat_smooth(method = 'glm', method.args = list(family = 'binomial'))
zmAlivePlot
zebra_mussel_DRM_7_A_4 <- drm(pAlive ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "A" & Temp == 4, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_A_4
plot(zebra_mussel_DRM_7_A_4)
ED(zebra_mussel_DRM_7_A_4, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_7_A_20 <- drm(pAlive ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "A" & Temp == 20, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_A_20
plot(zebra_mussel_DRM_7_A_20)
ED(zebra_mussel_DRM_7_A_20, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_7_S_4 <- drm(pAlive ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "S" & Temp == 4, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_S_4
plot(zebra_mussel_DRM_7_S_4)
ED(zebra_mussel_DRM_7_S_4, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_7_S_20 <- drm(pAlive ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "S" & Temp == 20, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_S_20
plot(zebra_mussel_DRM_7_S_20)
ED(zebra_mussel_DRM_7_S_20, respLev = c( 50, 1, 99), interval = 'delta')
###########################################################################################################
###########################################################################################################
## Attached Zebra Mussel mortality data
zebra_mussel[ , pAttached := Attached / Total ]
zmA <- zebra_mussel[ TimeCode != 0,]
zmAttachedPlot <-
ggplot(data = zmA, aes(x = mpCO2, y = pAttached, weight = Total, color = factor(TimeCode) )) +
geom_jitter(width = 0, height = 0.05) +
facet_grid( Size ~ Temp,
labeller = label_bquote(
rows = "Size: "~.(Size),
cols = .(Temp)*degree*"C"),
scales = "free_x") +
theme_minimal() +
xlab(expression("mP"~CO[2])) +
scale_x_continuous(label = comma, trans = 'log10') +
stat_smooth(method = 'glm', method.args = list(family = 'binomial')) +
scale_color_manual("Observation day", values = c("red", "blue", "seagreen"))
zmAttachedPlot
zebra_mussel_DRM_7_A_4_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "A" & Temp == 4, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_A_4_attached
plot(zebra_mussel_DRM_7_A_4_attached)
ED(zebra_mussel_DRM_7_A_4_attached, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_7_S_4_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "S" & Temp == 4, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_S_4_attached
plot(zebra_mussel_DRM_7_S_4_attached)
ED(zebra_mussel_DRM_7_S_4_attached, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_7_A_20_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "A" & Temp == 20, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_A_20_attached
plot(zebra_mussel_DRM_7_A_20_attached)
ED(zebra_mussel_DRM_7_A_20_attached, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_7_S_20_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 7 & Size == "S" & Temp == 20, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_7_S_20_attached
plot(zebra_mussel_DRM_7_S_20_attached)
ED(zebra_mussel_DRM_7_S_20_attached, respLev = c(50, 1, 99), interval = 'delta')
## Look at 1
zebra_mussel_DRM_1_A_4_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 1 & Size == "A" & Temp == 4, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_1_A_4_attached
plot(zebra_mussel_DRM_1_A_4_attached)
ED(zebra_mussel_DRM_1_A_4_attached, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_1_S_4_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 1 & Size == "S" & Temp == 4, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_1_S_4_attached
plot(zebra_mussel_DRM_1_S_4_attached)
ED(zebra_mussel_DRM_1_S_4_attached, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_1_A_20_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 1 & Size == "A" & Temp == 20, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_1_A_20_attached
plot(zebra_mussel_DRM_1_A_20_attached)
ED(zebra_mussel_DRM_1_A_20_attached, respLev = c( 50, 1, 99), interval = 'delta')
zebra_mussel_DRM_1_S_20_attached <- drm(pAttached ~ pCO2 , weights = Total,
data = zebra_mussel[ TimeCode == 1 & Size == "S" & Temp == 20, ] ,
fct = LL.2(), type = 'binomial')
zebra_mussel_DRM_1_S_20_attached
plot(zebra_mussel_DRM_1_S_20_attached)
ED(zebra_mussel_DRM_1_S_20_attached, respLev = c(50, 1, 99), interval = 'delta')
ED(zebra_mussel_DRM_1_S_4_attached, respLev = c(50, 1, 99), interval = 'delta')
ED(zebra_mussel_DRM_7_S_4_attached, respLev = c(50, 1, 99), interval = 'delta')
### Look at time to death
file_path_LT_4C_1 = "../LT100 4C Trial 1 Data for Review/csv files/"
ZM_LT_4C_1 <- fread(paste0(file_path_LT_4C_1, "Zebra Mussel Assessment LT100 4C trial 1 for review.csv"), na.strings = ".")
file_path_LT_4C_2 = "../LT100 4C Trial 2 Data for Review/csv files/"
ZM_LT_4C_2 <- fread(paste0(file_path_LT_4C_2, "Zebra Mussel Assessment LT100 4C trial 2 for review.csv"), na.strings = ".")
file_path_LT_12C = "../LT100 12C Data for Review/csv files/"
ZM_LT_12C <- fread(paste0(file_path_LT_12C, "Zebra Mussel Assessment LT100 12C for review.csv"), na.strings = ".")
file_path_LT_20C = "../LT100 20C Data for Review/csv files/"
ZM_LT_20C <- fread(paste0(file_path_LT_20C, "Zebra Mussel Assessment LT100 20C for review.csv"), na.strings = ".")
colnames(ZM_LT_4C_1) == colnames(ZM_LT_4C_2 )
colnames(ZM_LT_12C ) == colnames(ZM_LT_20C )
ZM_LT_4C_1[ , Temp := 4]
ZM_LT_4C_2[ , Temp := 4]
ZM_LT_4C_1[ , TempB := '4a']
ZM_LT_4C_2[ , TempB := '4b']
ZM_LT_12C[ , Temp := 12]
ZM_LT_20C[ , Temp := 20]
ZM_LT_12C[ , TempB := '12']
ZM_LT_20C[ , TempB := '20']
ZM_TL <- rbind(ZM_LT_4C_1, ZM_LT_4C_2, ZM_LT_12C, ZM_LT_20C)
setnames(ZM_TL, "Expdur (h)", "Duration")
ZM_TL[ is.na(Alive), ]
ZM_TL[ , pAlive := Alive / Total]
ZM_TL[ , Treatment := factor(ifelse(Tank <= 4, "Control", "Elevated")) ]
ggplot(ZM_TL[ TimeCode != 24, ], aes(x = Duration, y = pAlive, weight = Total, group = Tank)) +
geom_jitter(width = 0, height = 0.05) +
facet_grid( Treatment ~ Temp,
labeller = label_bquote(
cols = .(Temp)*degree*"C")) +
theme_minimal() +
xlab("Time after start (hr)") +
ylab("Survival") +
stat_smooth(method = 'glm', method.args = list(family = 'binomial'), se = FALSE)
ZM_TL_20 <- drm(pAlive ~ Duration , weights = Total,
data = ZM_TL[ TimeCode != 24 & Temp == 20 & Treatment == "Elevated", ] ,
fct = LL.2(), type = 'binomial')
ZM_TL_20
ED(ZM_TL_20, respLev = c(50, 1, 99), interval = 'delta')
ZM_TL_4 <- drm(pAlive ~ Duration , weights = Total,
data = ZM_TL[ TimeCode != 24 & Temp == 4 & Treatment == "Elevated", ] ,
fct = LL.2(), type = 'binomial')
ZM_TL_4
ED(ZM_TL_4, respLev = c(50, 1, 99), interval = 'delta')
ZM_TL_12 <- drm(pAlive ~ Duration , weights = Total,
data = ZM_TL[ TimeCode != 12 & Temp == 4 & Treatment == "Elevated", ] ,
fct = LL.2(), type = 'binomial')
ZM_TL_12
ED(ZM_TL_12, respLev = c(50, 1, 99), interval = 'delta')
### save session info
sink("SessionInfo.txt")
sessionInfo()
sink()