Nothing
## ----include=FALSE------------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7,
fig.height = 4.5, dpi = 96)
## ----setup--------------------------------------------------------------------
library(freqTLS)
data(aphid_tdt)
## ----data---------------------------------------------------------------------
aphid6 <- droplevels(subset(aphid_tdt, branch == "heat" & age == "6"))
aphid6$species <- factor(
aphid6$species,
levels = c("M_dirhodum", "R_padi", "S_avenae"),
labels = c("Metopolophium dirhodum", "Rhopalosiphum padi",
"Sitobion avenae")
)
aphid6_std <- standardize_data(
aphid6, temp = "temp", duration = "duration_min",
n_total = "n_total", n_surv = "n_surv", duration_unit = "minutes"
)
## ----fit----------------------------------------------------------------------
aphid6_fit <- fit_4pl(
aphid6_std,
ctmax = ~ 0 + species,
z = ~ 0 + species,
low = ~ 1,
up = ~ 1,
k = ~ temp_c,
family = "beta_binomial",
t_ref = 60,
method = "wald",
quiet = TRUE
)
diagnose_tdt_fit(aphid6_fit)
## ----quantities---------------------------------------------------------------
aphid6_tls <- tls(aphid6_fit, by = "species", lethal = FALSE, method = "wald")
aphid6_table <- aphid6_tls$summary
names(aphid6_table)[names(aphid6_table) == "median"] <- "estimate"
aphid6_table
## ----tdt, fig.alt="Thermal death-time curves for three cereal aphid species in the heat branch at age six."----
plot_tdt_curve(aphid6_fit)
## ----all-age------------------------------------------------------------------
aphid_all <- droplevels(subset(aphid_tdt, branch == "heat"))
aphid_all$species <- factor(
aphid_all$species,
levels = c("M_dirhodum", "R_padi", "S_avenae"),
labels = c("Metopolophium dirhodum", "Rhopalosiphum padi",
"Sitobion avenae")
)
aphid_all_std <- standardize_data(
aphid_all, temp = "temp", duration = "duration_min",
n_total = "n_total", n_surv = "n_surv", duration_unit = "minutes"
)
aphid_all_fit <- fit_4pl(
aphid_all_std,
ctmax = ~ 1 + species * age,
z = ~ 1 + species * age,
low = ~ 1,
up = ~ 1,
k = ~ temp_c,
family = "beta_binomial",
t_ref = 60,
method = "wald",
quiet = TRUE
)
diagnose_tdt_fit(aphid_all_fit)
## ----all-age-quantities-------------------------------------------------------
aphid_cells <- expand.grid(
species = levels(aphid_all$species),
age = levels(aphid_all$age),
temp = mean(aphid_all_std$temp),
KEEP.OUT.ATTRS = FALSE
)
aphid_cell_pars <- predict(aphid_all_fit, aphid_cells, type = "parameters")
cbind(aphid_cells[c("species", "age")],
aphid_cell_pars[c("CTmax", "z")])
## ----all-age-tdt, fig.alt="Thermal death-time curves for each cereal aphid species, faceted by age, from the all-age heat-branch model."----
aphid_tdt_grid <- merge(
expand.grid(
temp = seq(min(aphid_all_std$temp), max(aphid_all_std$temp), length.out = 60),
KEEP.OUT.ATTRS = FALSE
),
aphid_cells[c("species", "age")]
)
aphid_tdt_pars <- predict(aphid_all_fit, aphid_tdt_grid, type = "parameters")
aphid_tdt_grid$duration_50 <- 10^(
log10(60) - (aphid_tdt_grid$temp - aphid_tdt_pars$CTmax) / aphid_tdt_pars$z
)
ggplot2::ggplot(
aphid_tdt_grid,
ggplot2::aes(temp, duration_50, colour = species)
) +
ggplot2::geom_line(linewidth = 0.8) +
ggplot2::scale_y_log10() +
ggplot2::facet_wrap(~ age) +
ggplot2::labs(
x = "Temperature (°C)",
y = "Duration to 50% relative survival (minutes, log scale)",
colour = "Species"
) +
ggplot2::theme_minimal()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.