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

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

## -----------------------------------------------------------------------------
fit_imr <- shewhart_i_mr(bottle_fill, value = ml, index = observation)
fit_imr

## ----eval = FALSE-------------------------------------------------------------
# autoplot(fit_imr)

## -----------------------------------------------------------------------------
fit_xbar <- shewhart_xbar_r(tablet_weight,
                            value    = weight,
                            subgroup = subgroup)
broom::glance(fit_xbar)

## -----------------------------------------------------------------------------
fit_c <- shewhart_c(pcb_solder, defects = defects, index = board)
broom::tidy(fit_c)

## -----------------------------------------------------------------------------
fit_c_exact <- shewhart_c(pcb_solder, defects = defects, index = board,
                          limits = "poisson")
broom::tidy(fit_c_exact)

## -----------------------------------------------------------------------------
broom::tidy(fit_imr)            # control-limit summary
broom::glance(fit_imr)          # one-row diagnostic
head(broom::augment(fit_imr))   # per-observation results

## -----------------------------------------------------------------------------
# Suppose the first 60 bottles are our calibration baseline,
# and the next 40 are new data we want to monitor.
baseline <- bottle_fill[1:60, ]
new_obs  <- bottle_fill[61:100, ]

calib  <- calibrate(baseline, value = ml, index = observation,
                    chart = "i_mr")
alarms <- monitor(new_obs, calib)
alarms$violations

