library(purrr)
library(ggplot2)
# Data
df <- data.frame(
xi = simplify(
map(
c(.1,.08,.05,.1,.13,.14,.14,.09,.25),
~ rbinom(50,1,.x))),
p0 = simplify(
map(
c(.1,.1,.1,.1,.1,.1,.1,.15,.2),
~ rnorm(50,.x,.03))),
by = rep(
factor(paste('Subject', c('A','B','C'))),
times = c(150,150,150))
)
# Create CUSUM plot
cusum_ome(
xi = df$xi,
p0 = df$p0,
by = df$by
) |>
ggplot(aes(x = i, y = cusum)) +
geom_hline(yintercept = 0, linetype = 6, linewidth = 0.5) +
geom_step() +
ylab("Cumulative Observed Minus Expected Failures") +
xlab("Case Number") +
facet_wrap(~ by) +
theme_bw()
Run the code above in your browser using DataLab