% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/control.R
\name{control}
\alias{control}
\title{Statistics for Shewhart control charts}
\usage{
control(
  x,
  y = NULL,
  time,
  data,
  type = "x",
  subset = NULL,
  n.equal = TRUE,
  intervention = NULL
)
}
\arguments{
\item{x}{character outcome variable in X bar charts or numerator variable name for u-charts or p-charts (when p-chart data is aggregated).}

\item{y}{character variable name for u-charts or p-charts (when p-chart data is aggregated). When y is present, it becomes the
denominator for a rate calculated as x/y. Default is NULL.}

\item{time}{time variable name.}

\item{data}{name of data frame object.}

\item{type}{indicate what type of control chart is needed. Options for the X-bar, p-, and u-charts should be listed as
'x', 'p', and 'u'. Default is the 'x' chart.}

\item{subset}{an expression defining a subset of the observations to use in the grouping. The default
is NULL, thereby using all observations. Specify, for example, data$hospital == "NY" or c(1:100,200:300) respectively to
use just those observations.}

\item{n.equal}{whether there are or we assume equal subgroup (sample) sizes. If n.equal=TRUE, control limits are calculated using the overall
mean n value. If n.equal=FALSE, control limits are based on each subgroup's sample size. Default is TRUE.}

\item{intervention}{a single numeric value for the time when an intervention begins (e.g., intervention=25;
intervention begins on the 25th day). Separate means and control limits are calculated pre- and post-intervention.
Default is NULL.}
}
\value{
data frame of control chart statistics for X-bar charts, p-charts, and u-charts. Includes means,
standard deviations, and 3-sigma upper and lower control limit values.
}
\description{
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.
}
\examples{
## Hospital LOS and readmissions ##
# X-bar chart statistics
spc_x <- control(x="los", time="month", data=hosprog, type="x", n.equal=TRUE)
print(spc_x) # get data frame output

# X-bar chart statistics not assuming equal sample sizes, subsetting for females
spc_x <- control(x="los", time="month", data=hosprog, type="x", n.equal=FALSE,
  subset=hosprog$female==1)
print(spc_x) # get data frame output

# p-chart statistics, 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)
print(spc_p) # get data frame output

# u-chart for infection rates with an intervention at the 22nd month
spc_u <- control(x="HAI", y="PatientDays", time="Month", data=infections,
type="u", n.equal=FALSE, intervention=22)
print(spc_u) # get data frame output
}
\references{
Ryan, T. (2011). Statistical Methods for Quality Improvement, Third Edition.
New Jersey: John Wiley & Sons, Inc. ISBN: 978-0-470-59074-4.
}
