我正在与一个项目的医生合作,监测对抗生素适当剂量的依从性。为了跟踪不合规事件的比例,医生们喜欢使用P charts
我想在中心线的上方和下方生成一个带有 3个限制线(对应于1,2和3个SD)的P-Chart。我还没有办法做到这一点。我还希望这个情节有几个中断,将数据分成几个时间段,我可以在qicharts包中进行,但不能在其他包中进行。
R有几个包用于生成P图表。我最喜欢的是qicharts。来自qicharts的标准P-Chart以及我见过的所有其他软件包都生成了一条带有中心线和上限控制以及下限控制的图,中心线为+3和-3 SD。
我想弄清楚如何在同一个图上生成额外的+1,+ 2和-1,-2 SD控制线。一些选项,如
LimitLines = c(1, 2, 3) where the default is LimitlLines = 3
以下是从r-projects修改的代码,用于生成数据,创建图表以及包含两个中断:
# 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')
答案 0 :(得分:1)
如果您只需要提供数据,则可以轻松自行创建图表。随意修改功能以使其更容易。
数据:
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)
}
可以很容易地将断点添加到上述中,您只需要相应地隔离数据。但应该记住,如果您对所使用的过程没有变化,则不应更改限制的计算,并且您的过程可能只是不受统计控制而且需要标准化。