我在R中创建了一个qcc图表,并希望将qcc图表中的特殊原因变化保存在变量中,以供在其他地方使用。
我试图提取图表“数字超出限制”和“数字违规运行”的特殊原因,但没有成功。所以我试着重新计算特殊的原因,以“七分不断增加”为起点。
Q1。我的for循环有什么问题,它的目的是检测“七个点不断增加”。错误消息:
Error in incremnt : object 'incremnt' not foundQ2。怎样才能让gcc图表在x轴上显示日期?
我在这个项目中使用的有用链接:
https://improvement.nhs.uk/documents/2171/statistical-process-control.pdf https://www.r-bloggers.com/xmr-chart-step-by-step-guide-by-hand-and-with-r/
SPC - Control Charts by Group in R
....R
install.packages("qcc")
install.packages("ggQC")
library(qcc)
library(ggQC)
exampl_data <- data.frame(
# ScrewID = as.factor(1:20),
ScrewID = seq(as.Date("2000/1/1"), by = "month", length.out = 20),
Length = c(
2.92, 3.16, 2.88, 2.90, 2.92,
2.94, 2.96, 2.98, 3.02, 2.67,
3.09, 3.07, 3.04, 3.06, 3.05,
3.03, 3.07, 2.91, 3.07, 3.30
)
)
qcc_chart <- qcc(exampl_data$Length, type = "xbar.one", plot = FALSE)
# add warning limits at 2 and 3 std. deviations
(warn.limits <- limits.xbar(qcc_chart$center, qcc_chart$std.dev, qcc_chart$sizes, 1))
(warn.limits2 <- limits.xbar(qcc_chart$center, qcc_chart$std.dev, qcc_chart$sizes, 2)
)
plot(qcc_chart, restore.par = TRUE)
abline(h = warn.limits, lty = 3, col = "gray")
abline(h = warn.limits2, lty = 3, col = "gray")
# Not working: My attempt at loop to identify 7 row of incresing values
for (i in 1:length(exampl_data$Length))
{
increment <- 0
while (exampl_data$Length[i + increment] <= exampl_data$Length[(i + increment) +
1] & increment < 8)
{
if (incremnt == 7)
{
print(exampl_data$Length[i + increment])
break()
}
increment <- increment + 1
}
}
....发布于 2019-07-31 16:25:17
这是我在这篇文章的帮助下得出的结论,Longest run of changes for each dataframe in a list
用于识别连续升序的七个点的代码如下。
# Test one, identify a run of seven values increasing
library(tidyverse)
increment_run <- rep('False', time = length(exampl_data$Length))
for (i in 1:length(exampl_data$Length))
{
if(exampl_data$Length[i+1] >= exampl_data$Length[i] & i < 20)
{
increment_run[i+1] = 'Ture'
print(paste(i+1,' Ture', sep=" ")) # debug
}else if (i < 20){ print(paste(i+1,' False', sep=" ")) #debug
}
}
exampl_data <- exampl_data %>%
mutate(streak = sequence(rle(as.character(increment_run))$lengths))
exampl_data %>%
#select(values)%>%
filter(streak > 5)如果有人有更好的办法,那就分享吧?
https://stackoverflow.com/questions/57251839
复制相似问题