## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>",
                      fig.width = 7, fig.height = 4.2,
                      eval = FALSE)

## ----setup, message = FALSE---------------------------------------------------
# library(shewhartr)
# library(ggplot2)
# library(dplyr)

## -----------------------------------------------------------------------------
# set.seed(2025)
# shewhart_arl(
#   shift = 0,
#   rules = "nelson_1_beyond_3s",
#   n_sim = 5000,
#   max_run = 2000
# )

## -----------------------------------------------------------------------------
# set.seed(2025)
# shewhart_arl(
#   shift = 0,
#   rules = c("nelson_1_beyond_3s", "nelson_2_nine_same"),
#   n_sim = 5000
# )

## -----------------------------------------------------------------------------
# shifts <- seq(0, 3, by = 0.25)
# 
# set.seed(2025)
# arl_n1 <- shewhart_arl(shifts, "nelson_1_beyond_3s", n_sim = 2000)
# arl_n12 <- shewhart_arl(shifts,
#                         c("nelson_1_beyond_3s", "nelson_2_nine_same"),
#                         n_sim = 2000)
# 
# bind_rows(
#   arl_n1  |> mutate(rules = "Nelson 1 only"),
#   arl_n12 |> mutate(rules = "Nelson 1 + 2")
# ) |>
#   ggplot(aes(shift, arl, colour = rules)) +
#   geom_line(linewidth = 0.7) +
#   geom_ribbon(aes(ymin = arl_lower, ymax = arl_upper, fill = rules),
#               alpha = 0.12, colour = NA) +
#   scale_y_log10() +
#   scale_colour_manual(
#     values = c(`Nelson 1 only` = unname(shewhart_palette("signal")["in_control"]),
#                `Nelson 1 + 2`  = unname(shewhart_palette("family")["memory_based"]))) +
#   scale_fill_manual(
#     values = c(`Nelson 1 only` = unname(shewhart_palette("signal")["in_control"]),
#                `Nelson 1 + 2`  = unname(shewhart_palette("family")["memory_based"]))) +
#   labs(x = "Shift (sigma)", y = "ARL (log scale)",
#        title = "Operating characteristics") +
#   shewhart_theme()

## -----------------------------------------------------------------------------
# set.seed(2025)
# arl_we  <- shewhart_arl(0, "we_seven_same",       n_sim = 5000, max_run = 2000)
# arl_n2  <- shewhart_arl(0, "nelson_2_nine_same",  n_sim = 5000, max_run = 2000)
# arl_we
# arl_n2

## -----------------------------------------------------------------------------
# shewhart_regression(temperature_drift, value = temp_c, index = minute,
#                     phase_rule = "we_seven_same")        # legacy default
# shewhart_regression(temperature_drift, value = temp_c, index = minute,
#                     phase_rule = "nelson_2_nine_same")    # new default

