多行R控制图 [英] R control chart with multiple lines

查看:110
本文介绍了多行R控制图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与医生合作开展一个项目,以监测对正确剂量抗生素的依从性。为了跟踪不符合事件的比例,医生喜欢使用 P图表

I'm working with physicians on a project to monitor compliance to proper dosage of antibiotics. To track the proportion of events that are not compliant, physicians like to use P charts

我想生成一个在中心线上方和下方具有 3条极限线(对应于1、2和3个SD)的P图。我还没有找到一种方法来做到这一点。我还希望该图有几个中断,可以将数据分成几个时间段,可以在qicharts程序包中执行此操作,但不能在其他程序包中执行。

I would like to generate a P-Chart with 3 limit lines (corresponding to 1, 2, and 3 SDs) above and below the central line. I have not found a way to do this. I would also like the plot to have several breaks that separate the data into several time periods, which I can do in the qicharts package but not in other packages.

有R的几个软件包,用于生成P图表。我最喜欢的是qicharts。 qicharts的标准P图表以及我见过的所有其他软件包都生成了一个图,其中有一个中心线,一个控制上限和一个控制下限,分别位于中心线的+3和-3 SD处。

There are several packages for R for generating P Charts. The one I like most is qicharts. The standard P-Chart from qicharts, and all of the other packages I've seen, generates a plot with a Central Line and an Upper Control Limit and a Lower Control Limit at +3 and -3 SD from the central line.

我想弄清楚如何在同一图上生成额外的+ 1,+ 2和-1,-2的SD控制线。某些选项,例如

I would like to figure out how to generate additional +1, +2, and -1, -2 SD control lines on the same plot. Some option such as

LimitLines = c(1, 2, 3) where the default is LimitlLines = 3

这是从 r项目,用于生成数据,创建图表并包含两个中断:

Here is the code, modified from r-projects, to generate data, create the chart, and include two breaks:

# Setup parameters
m.beds       <- 300
m.stay       <- 4
m.days       <- m.beds * 7
m.discharges <- m.days / m.stay
p.pu         <- 0.08

# Simulate data
discharges  <- rpois(24, lambda = m.discharges)
patientdays <- round(rnorm(24, mean = m.days, sd = 100))
n.pu        <- rpois(24, lambda = m.discharges * p.pu * 1.5)
n.pat.pu    <- rbinom(24, size = discharges, prob = p.pu)
week        <- seq(as.Date('2014-1-1'),
               length.out = 24, 
               by         = 'week') 

# Combine data into a data frame
d <- data.frame(week, discharges, patientdays,n.pu, n.pat.pu)

# Create a P-chart to measure the number of patients with pressure ulcers (n.pat.pu) each week (week) as a proportion of all discharges (discharges) with breaks one third (8) and two thirds (16) of the way through the data

qic(n.pat.pu,
n        = discharges,
x        = week,
data     = d,
chart    = 'p',
multiply = 100,
breaks   = c(8,16),
main     = 'Hospital acquired pressure ulcers (P chart)',
ylab     = 'Percent patients',
xlab     = 'Week')


推荐答案

如果仅需要显示数据,则可以轻松地自己创建图表。可以根据需要随意修改该功能,以使其更容易。

If you simply need to present the data, it is easy to create the chart yourself. Feel free to modify the function to your needs to make it easier.

数据:

Groups <- c(120, 110, 150, 110, 140, 160, 100, 150, 100, 130, 130, 100, 120, 110, 130, 110, 150, 110, 110)
Errors <- c(4, 3, 3, 3, 0, 6, 2, 2, 1, 5, 1, 5, 1, 1, 0, 1, 4, 0, 0)
Week <- length(Groups) #optional: input vector of week numbers
PchartData <- data.frame(Week,Groups,Errors)

功能:

Shewhart.P.Chart <- function(Groups, Errors, Week)
{
## Create from scratch
# p value
p <- Errors/Groups
# pbar
pbar <- mean(p)
# calculate control limits
UCL3 <- pbar+3*sqrt((pbar * ( 1 - pbar))/Groups)
UCL2 <- pbar+2*sqrt((pbar * ( 1 - pbar))/Groups)
UCL1 <- pbar+1*sqrt((pbar * ( 1 - pbar))/Groups)
LCL1 <- pbar-1*sqrt((pbar * ( 1 - pbar))/Groups)
LCL2 <- pbar-2*sqrt((pbar * ( 1 - pbar))/Groups)
LCL3 <- pbar-3*sqrt((pbar * ( 1 - pbar))/Groups)
## adjust the minimal value of the LCL to 0
LCL3[LCL3 < 0] <- 0
LCL2[LCL2 < 0] <- 0
LCL1[LCL1 < 0] <- 0
# plot pvalues
plot(c(1:length(Groups)),p, ylim = c(min(LCL3,p),max(UCL3,p)),
    main = "p Chart \n for Prescription Errors", xlab = "weeks", 
    ylab = 'Proportion nonconforming', col = "green", pch = 20,
    lty = 1, type = "b")
# add centerline reference
abline(h = pbar, col = "red")
# plot control limits at ±1s, 2s, and 3s
lines(c(1:length(Groups)),UCL1, col = "blue", lty = 2)
lines(c(1:length(Groups)),UCL2, col = "blue", lty = 2)
lines(c(1:length(Groups)),UCL3, col = "blue", lty = 2)
lines(c(1:length(Groups)),LCL3, col = "blue", lty = 2)
lines(c(1:length(Groups)),LCL2, col = "blue", lty = 2)
lines(c(1:length(Groups)),LCL1, col = "blue", lty = 2)
}

可以轻松地将中断添加到上述内容中,您只需要相应地隔离数据即可。但是请记住,如果您使用的流程没有任何变化,则不应更改限值的计算,您的流程可能完全不受统计控制,需要标准化。

Breaks can easily be added into the forgoing, you would just need to segregate your data accordingly. It should be remembered though, if you do not have a change in the process used, the calculation for the limits should not be changed and your process may simply be out of statistical control and in need of standardization.

这篇关于多行R控制图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆