## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.height = 4,
  dpi = 96
)

## ----setup--------------------------------------------------------------------
library(freqTLS)

## ----data---------------------------------------------------------------------
data(aphid_tdt)
aphids <- subset(aphid_tdt, branch == "heat" & age == "6")
table(aphids$species)

## ----standardize--------------------------------------------------------------
std <- standardize_data(
  aphids,
  temp = "temp", duration = "duration_min",
  n_total = "n_total", n_surv = "n_surv",
  duration_unit = "minutes"
)

## ----fit----------------------------------------------------------------------
fit <- suppressWarnings(fit_4pl(
  std,
  ctmax = ~ 0 + species,
  z     = ~ 0 + species,
  t_ref = 60,
  family = "beta_binomial"
))
ax <- tls(fit, by = "species", method = "wald")
ax$summary

## ----ranking, echo = FALSE----------------------------------------------------
ct <- ax$summary[ax$summary$quantity == "CTmax", ]
ct <- ct[order(ct$median), ]

## ----eye-ctmax, fig.height = 4.5, fig.alt = "Confidence Eyes for cereal-aphid CTmax by species: three pale confidence lenses with hollow point estimates, one per species, ordered along the temperature axis."----
plot_confidence_eye(fit, parm = get_ctmax(fit)$parameter, method = "wald")

## ----eye-z, fig.height = 4.5, fig.alt = "Confidence Eyes for cereal-aphid z (thermal sensitivity) by species: three pale confidence lenses with hollow point estimates."----
plot_confidence_eye(fit, parm = get_z(fit)$parameter, method = "wald")

## ----survival, fig.height = 4.5, fig.alt = "Fitted cereal-aphid survival curves by species: probability of survival declining with exposure duration, one curve per assay temperature, the three species overlaid."----
plot_survival_curves(fit)

