# control

    library(ham)

# Shewhart Control Charts

The following sections show options to create the classic Shewhart control charts: X-bar charts, p-charts, and u-charts.

# 1. Introduction

Calculate statistics that can be used to produce X-bar charts, p-charts, and u-charts. This includes producing means for center lines, 3-sigma upper and lower control limits. Users can also calculate values before and after an intervention to see if a change in the control process happened. Values are returned in a data frame.

# 2. \(\bar{X}\) charts

Hospital LOS. View your output.

    spc_x <- control(x="los", time="month", data=hosprog, type="x", n.equal=TRUE)
    print(spc_x)
    #>    month      los   agr_sd agr_n        c4       SD  N       MOC     Mean
    #> 1      1 4.575018 2.352310    51 0.9950128 1.937359 60 0.7540967 4.439575
    #> 2      2 4.213063 1.795740    63 0.9959760 1.937359 60 0.7533674 4.439575
    #> 3      3 4.998275 2.321623    49 0.9948056 1.937359 60 0.7542538 4.439575
    #> 4      4 4.393394 1.853836    66 0.9961614 1.937359 60 0.7532272 4.439575
    #> 5      5 4.174968 2.043365    65 0.9961015 1.937359 60 0.7532725 4.439575
    #> 6      6 4.283090 1.683121    60 0.9957719 1.937359 60 0.7535219 4.439575
    #> 7      7 4.295917 1.520956    50 0.9949113 1.937359 60 0.7541736 4.439575
    #> 8      8 4.275860 1.620757    52 0.9951103 1.937359 60 0.7540228 4.439575
    #> 9      9 4.418855 1.675656    65 0.9961015 1.937359 60 0.7532725 4.439575
    #> 10    10 4.262903 1.702403    71 0.9964351 1.937359 60 0.7530203 4.439575
    #> 11    11 4.488335 1.828521    67 0.9962194 1.937359 60 0.7531833 4.439575
    #> 12    12 4.895228 2.850019    61 0.9958422 1.937359 60 0.7534687 4.439575
    #>         LCL      UCL type
    #> 1  3.685479 5.193672    x
    #> 2  3.686208 5.192943    x
    #> 3  3.685322 5.193829    x
    #> 4  3.686348 5.192803    x
    #> 5  3.686303 5.192848    x
    #> 6  3.686054 5.193097    x
    #> 7  3.685402 5.193749    x
    #> 8  3.685553 5.193598    x
    #> 9  3.686303 5.192848    x
    #> 10 3.686555 5.192596    x
    #> 11 3.686392 5.192759    x
    #> 12 3.686107 5.193044    x

Basic X-bar chart.

    plot(spc_x)

# 3. p-chart

Hospital readmissions.

p-chart, using only the numerator (i.e., y=NULL). Specify unequal sample sizes.

    spc_p <- control(x="rdm30", time="month", data=hosprog, type="p", n.equal=FALSE)

p-chart, adding specification target and time point lines.

    plot(spc_p, tgt=c(0,.25), tgtcol="green", ylim=c(0,0.4), tpline=c(4,8),
    tpcol= c("yellow","black"))

# 4. u-chart

u-chart for infection rates with an intervention.

    spc_u <- control(x="HAI", y="PatientDays", time="Month", data=infections,
    type="u", n.equal=FALSE, intervention=22)

u-chart with trend lines, various graphing options, x.axis start at 2nd year and y.axis changed to show HAIs per 1,000 patient days.

    plot(spc_u, main="u-Chart: HAI per 1,000 Patient Days Pre/Post Intervention",
    col=c("green","dodgerblue"), trend=TRUE, trcol="red", x.axis=c((1:41+12)), round.c=1,
    y.axis=seq(min(spc_u$HAI)*1000, max(spc_u$HAI)*1000, length.out=nrow(spc_u)),
    xlab="Months (starting at year 2)", icol="gray", lwd=2, cex=2,
    cex.axis=1.1, cex.main=1.25, cex.text=1.25)

One thing that is helpful in ham’s chart options is the ordinary least squares trend line arrows in optional red above. It can show the trend line, especially helpful in out-of-control processes.