Learn R Programming

vlad (version 0.1.0)

eocusum_arloc_sim: Compute Out of Control ARLs of EO-CUSUM control charts using simulation

Description

Compute Out of Control ARLs of EO-CUSUM control charts using simulation.

Usage

eocusum_arloc_sim(r, k, h, df, coeff, coeff2, QS = 1, side = "low")

Arguments

r

int. Number of of simulation runs.

k

double. Reference value of the CUSUM control chart.

h

double. Decision interval (alarm limit, threshold) of the CUSUM control chart.

df

DataFrame. First column Parsonnet Score and second column outcome of each operation.

coeff

NumericVector. Estimated coefficients \(\alpha\) and \(\beta\) from the binary logistic regression model.

coeff2

NumericVector. Estimated coefficients \(\alpha\) and \(\beta\) from the binary logistic regression model of a resampled dataset.

QS

double. Defines the performance of a surgeon with the odds ratio ratio of death Q.

side

character. Default is "low" to calculate ARL for the upper arm of the V-mask. If side = "up", calculate the lower arm of the V-mask.

Value

Returns a single value which is the Run Length.

References

Steiner SH, Cook RJ, Farewell VT and Treasure T (2000). <U+201C>Monitoring surgical performance using risk-adjusted cumulative sum charts.<U+201D> Biostatistics, 1(4), pp. 441-452. doi: 10.1093/biostatistics/1.4.441.

Examples

Run this code
# NOT RUN {
library("vlad")
library("spcadjust")
## Datasets
data("cardiacsurgery")
s5000 <- dplyr::sample_n(cardiacsurgery, size=5000, replace=TRUE)
df1 <- subset(cardiacsurgery, select=c(Parsonnet, status))
df2 <- subset(s5000, select=c(Parsonnet, status))
## estimate coefficients from logit model
coeff1 <- round(coef(glm(status~Parsonnet, data=df1, family="binomial")), 3)
coeff2 <- round(coef(glm(status~Parsonnet, data=df2, family="binomial")), 3)

## Serial simulation
## set seed for reproducibility
RNGkind("L'Ecuyer-CMRG")
m <- 10^3
RLS <- do.call(c, lapply(1:m, eocusum_arloc_sim, h=4.498, k=0, df=df1, side="low", coeff=coeff1,
                         coeff2=coeff2))
data.frame(cbind("ARL"=mean(RLS), "ARLSE"=sd(RLS)/sqrt(m)))
## ARL=366.697; ARLSE=9.457748
## Parallel simulation (FORK)
## set seed for reproducibility
RNGkind("L'Ecuyer-CMRG")
RLS <- simplify2array(parallel::mclapply(1:m, eocusum_arloc_sim, h=4.498, k=0, df=df1, side="low",
                                         coeff=coeff1, coeff2=coeff2,
                                         mc.cores=parallel::detectCores()))
data.frame(cbind("ARL"=mean(RLS), "ARLSE"=sd(RLS)/sqrt(m)))

## Parallel simulation (PSOCK)
## set seed for reproducibility
RNGkind("L'Ecuyer-CMRG")
no_cores <- parallel::detectCores()
cl <- parallel::makeCluster(no_cores)
side <- 1
h_vec <- 4.498
QS_vec <- 1
m <- 10^3
k <- 0
parallel::clusterExport(cl, c("h_vec", "eocusum_arloc_sim", "df1", "coeff1", "coeff2",
                              "QS_vec", "side", "k"))
time <- system.time( {
RLS <- array(NA, dim=c( length(QS_vec), length(h_vec), m))
for (h in h_vec) {
  for (QS in QS_vec) {
    cat(h, " ", QS, "\n")
    RLS[which(QS_vec==QS), which(h==h_vec), ] <- parallel::parSapply(cl, 1:m, eocusum_arloc_sim,
                                                                     side=side, QS=QS, h=h, k=k,
                                                                     df=df1,  coeff=coeff1,
                                                                     coeff2=coeff2,
                                                                      USE.NAMES=FALSE)
    }
  }
} )
ARL <- apply(RLS, c(1, 2), mean)
ARLSE <- sqrt(apply(RLS, c(1, 2), var)/m)
print(list(ARL, ARLSE, time))
parallel::stopCluster(cl)
# }

Run the code above in your browser using DataLab