我目前正在尝试解决喇叭曲线计算错误。基于 IEC 60601-2-24 : 1998 - 第 8 节 - 操作数据的准确性和针对危险输出的保护。这是我的 R 代码:
flow<-read.table("c:\\ciringe.txt",comment.char="#",header=TRUE)
#parameters
# setflow = 1
# P = 1,2,5,11,19,31
P1<-1
P2<-2
P5<-5
P11<-11
P19<- 19
P31<-31
P1m = ((60 - P1) / 0.5 ) + 1
P2m = ((60 - P2) / 0.5 ) + 1
P5m = ((60 - P5) / 0.5 ) + 1
P11m = ((60 - P11) / 0.5 ) + 1
P19m = ((60 - P19) / 0.5 ) + 1
P31m = ((60 - P31) / 0.5 ) + 1
setflow<-1
mQE1<-0.5
mQE2<-0.25
mQE5<-0.1
mQE11<-0.045
mQE19<-0.0263
mQE31<-0.0161
Q<-as.data.frame(c(0,(60*diff(flow$wt,1,1)/0.5*0.998))) # Q is used for flow in the standard
names(Q)<-"Q"
# Now combine them
l<-list(flow,Q)
dflow<-as.data.frame(l)
t1flow<-subset(dflow, dflow$secs>=3600 & dflow$secs<=7200) # require the second hour of the data
#overall
t1flow$QE<-(((t1flow$Q-setflow)/setflow)*100) # calculate the error
t1flow$QE1<-(((t1flow$Q-setflow)/setflow)*100) * mQE1 # calculate the error
t1flow$QE2<-(((t1flow$Q-setflow)/setflow)*100) * mQE2 # calculate the error
t1flow$QE5<-(((t1flow$Q-setflow)/setflow)*100) * mQE5 # calculate the error
t1flow$QE11<-(((t1flow$Q-setflow)/setflow)*100) * mQE11 # calculate the error
t1flow$QE19<-(((t1flow$Q-setflow)/setflow)*100) * mQE19 # calculate the error
t1flow$QE31<-(((t1flow$Q-setflow)/setflow)*100) * mQE31 # calculate the error
library(TTR) # use this for moving averages
#
# Avert your eyes! I know there must be a slicker way of doing this .....
#
# Calculate the moving average using a sample rate of every
# 4 readings (2 mins of 30sec readings)
# now for the 1 minute window
QE1<-SMA(t1flow$QE1,2)
minQE1<-min(QE1,na.rm=TRUE)
maxQE1<-max(QE1,na.rm=TRUE)
# now for the 2 minute window
QE2<-SMA(t1flow$QE2,4)
minQE2<-min(QE2,na.rm=TRUE)
maxQE2<-max(QE2,na.rm=TRUE)
# now for the 5 minute window
QE5<-SMA(t1flow$QE5,10)
minQE5<-min(QE5,na.rm=TRUE)
maxQE5<-max(QE5,na.rm=TRUE)
# Set window to 11 mins
QE11<-SMA(t1flow$QE11,22)
minQE11<-min(QE11,na.rm=TRUE)
maxQE11<-max(QE11,na.rm=TRUE)
# Set window to 19 mins
QE19<-SMA(t1flow$QE19,38)
minQE19<-min(QE19,na.rm=TRUE)
maxQE19<-max(QE19,na.rm=TRUE)
# Set window to 31 mins
QE31<-SMA(t1flow$QE31,62)
minQE31<-min(QE31,na.rm=TRUE)
maxQE31<-max(QE31,na.rm=TRUE)
#
# OK - you can look again :-)
#
# create a data frame from this data
trump<- data.frame(c(1,2,5,11,19,31),c(minQE1,minQE2,minQE5,minQE11,minQE19,minQE31), c(maxQE1,maxQE2,maxQE5,maxQE11,maxQE19,maxQE31))
names(trump)<-c("T","minE","maxE")
A<-mean(t1flow$QE) # calculate the overall mean percentage error
error_caption<-paste("overall percentage error = ",A,"%") # create the string to label the error line
# plot the graph
library(ggplot2)
ggplot(trump, aes(x = T, y = minE)) +
geom_line() +
geom_point(color="red") +
geom_line(aes(y = maxE)) +
geom_point(aes(y = maxE),colour="red") +
geom_hline(aes(yintercept = 0), linetype = "dashed") + # overall percentage error
geom_hline(aes(yintercept = A), linetype = "solid") + # set rate
xlab("Observation windows (in minutes)") +
ylab("% error") +
scale_x_continuous(breaks=c(0,2,5,11,19,31),limits=c(0,32)) + # label the x axis only at the window values
annotate("text", x = 10, y = A-0.5, label = error_caption) # add the error line label
实际上,我不理解 ISO 文档中所述的求和序列(百分比变化)