# NOT RUN {
head(lamprey_tox)
# within the dataframe used, control dose, unless produced a value
# during experimentation, are removed from the dataframe,
# as glm cannot handle values of infinite. Other statistical programs
# make note of the control dose but do not include within analysis
# calculate LC50 and LC99
m <- LC_probit((response / total) ~ log10(dose), p = c(50, 99),
weights = total,
data = lamprey_tox[lamprey_tox$nominal_dose != 0, ],
subset = c(month == "May"))
# view calculated LC50 and LC99 for seasonal toxicity of a pisicide,
# to lamprey in 2011
m
# dose-response curve can be plotted using 'ggplot2'
# library(ggplot2)
# lc_may <- subset(lamprey_tox, month %in% c("May"))
# p1 <- ggplot(data = lc_may[lc_may$nominal_dose != 0, ],
# aes(x = log10(dose), y = (response / total))) +
# geom_point() +
# geom_smooth(method = "glm",
# method.args = list(family = binomial(link = "probit")),
# aes(weight = total), colour = "#FF0000", se = TRUE)
# p1
# calculate LC50s and LC99s for multiple toxicity tests, June, August, and September
j <- LC_probit((response / total) ~ log10(dose), p = c(50, 99),
weights = total,
data = lamprey_tox[lamprey_tox$nominal_dose != 0, ],
subset = c(month == "June"))
a <- LC_probit((response / total) ~ log10(dose), p = c(50, 99),
weights = total,
data = lamprey_tox[lamprey_tox$nominal_dose != 0, ],
subset = c(month == "August"))
s <- LC_probit((response / total) ~ log10(dose), p = c(50, 99),
weights = total,
data = lamprey_tox[lamprey_tox$nominal_dose != 0, ],
subset = c(month == "September"))
# group results together in a dataframe to plot with 'ggplot2'
results <- rbind(m[, c(1, 3:8, 11)], j[,c(1, 3:8, 11)],
a[, c(1, 3:8, 11)], s[, c(1, 3:8, 11)])
results$month <- factor(c(rep("May", 2), rep("June", 2),
rep("August", 2), rep("September", 2)),
levels = c("May", "June", "August", "September"))
# p2 <- ggplot(data = results, aes(x = month, y = dose,
# group = factor(p), fill = factor(p))) +
# geom_col(position = position_dodge(width = 0.9), colour = "#000000") +
# geom_errorbar(aes(ymin = (dose - LCL_dis), ymax = (dose + UCL_dis)),
# size = 0.4, width = 0.06,
# position = position_dodge(width = 0.9))
# p2
# }
Run the code above in your browser using DataLab