## -----------------------------------------------------------------------------
#| include: false
library(methods)
if (requireNamespace("lme4", quietly = TRUE)) library(lme4)
if (requireNamespace("lmerTest", quietly = TRUE)) library(lmerTest)
load_book_data <- function(name) {
  load(file.path("..", "data", paste0(name, ".RData")), envir = parent.frame())
}
for (dataset_name in c("ex121", "ex124", "ex125", "ex127", "ex31", "ex32", "ex33")) {
  load_book_data(dataset_name)
}


## -----------------------------------------------------------------------------
data.frame(
  dataset = c("ex121", "ex124", "ex125", "ex127", "ex31", "ex32", "ex33"),
  rows = c(
    nrow(ex121), nrow(ex124), nrow(ex125), nrow(ex127),
    nrow(ex31), nrow(ex32), nrow(ex33)
  ),
  columns = c(
    ncol(ex121), ncol(ex124), ncol(ex125), ncol(ex127),
    ncol(ex31), ncol(ex32), ncol(ex33)
  )
)


## -----------------------------------------------------------------------------
fit_ex2217 <- stats::aov(PCVdiff ~ dose, data = ex121)
if (requireNamespace("report", quietly = TRUE)) {
  report::report(fit_ex2217)
}
stats::anova(fit_ex2217)


## -----------------------------------------------------------------------------
if (requireNamespace("ggplot2", quietly = TRUE)) {
  ggplot2::ggplot(ex121, ggplot2::aes(x = dose, y = PCVdiff)) +
    ggplot2::geom_point(size = 2) +
    ggplot2::stat_summary(
      fun = mean,
      geom = "point",
      size = 3,
      shape = 18,
      color = "#1f78b4"
    ) +
    ggplot2::labs(
      x = "Dose",
      y = "Change in packed cell volume",
      title = "Packed cell volume response by dose"
    ) +
    ggplot2::theme_minimal()
}

