## ----include = FALSE----------------------------------------------------------
has_data <- requireNamespace("shewhartr", quietly = TRUE)
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4.5,
                      eval = has_data)

## ----setup--------------------------------------------------------------------
library(edetect)

## ----tablets------------------------------------------------------------------
tablets <- aggregate(weight ~ subgroup, shewhartr::tablet_weight, mean)
head(tablets, 3)

design <- edetect_design(arl = 370, class = "subgaussian", center = 250,
                         sigma = 1.5 / sqrt(5), direction = "both")
design
chart <- edetect_update(edetect_init(design), tablets$weight[13:25])
chart

## ----tablets-plot-------------------------------------------------------------
edetect_alarm(chart)
autoplot(chart)

## ----report-------------------------------------------------------------------
edetect_report(chart)
tidy(chart)

## ----bottles------------------------------------------------------------------
ml <- shewhartr::bottle_fill$ml
design <- edetect_design(arl = 370, class = "subgaussian", phase1 = ml[1:50],
                         direction = "up")
design
chart <- edetect_update(edetect_init(design), ml[51:100])
edetect_alarm(chart)
autoplot(chart)

## ----bottles-bounded----------------------------------------------------------
design_b <- edetect_design(arl = 370, class = "bounded", bounds = c(495, 505),
                           phase1 = ml[1:50], direction = "up")
edetect_alarm(edetect_update(edetect_init(design_b), ml[51:100]))

