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

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

## -----------------------------------------------------------------------------
fit <- shewhart_p(claims_p, defects = defects, n = n, index = day)
broom::tidy(fit)

## -----------------------------------------------------------------------------
broom::augment(fit) |> head(10)

## ----eval = FALSE-------------------------------------------------------------
# shewhart_p(claims_p, defects = defects, n = n, index = day,
#            limits = "binomial")

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

## -----------------------------------------------------------------------------
small_means <- data.frame(unit = 1:50, defects = rpois(50, lambda = 2))
suppressWarnings(
  fit_low <- shewhart_c(small_means, defects = defects, index = unit)
)
broom::tidy(fit_low)

## -----------------------------------------------------------------------------
fit_low_exact <- shewhart_c(small_means, defects = defects, index = unit,
                            limits = "poisson")
broom::tidy(fit_low_exact)

## -----------------------------------------------------------------------------
fit_np <- shewhart_np(
  data.frame(day = 1:30, defects = rbinom(30, size = 200, prob = 0.04)),
  defects = defects,
  n       = 200,
  index   = day
)
broom::tidy(fit_np)

## -----------------------------------------------------------------------------
set.seed(1)
df_u <- data.frame(
  roll    = 1:25,
  defects = rpois(25, lambda = 4 * runif(25, 0.5, 1.5)),
  m2      = runif(25, 0.5, 1.5)
)
fit_u <- shewhart_u(df_u, defects = defects, exposure = m2, index = roll)
broom::tidy(fit_u)

