[英][R]loops for to find the intervals in the graph and use them for the final formula and plot
這是我的代碼:
Y<-V40 # variable of my dataset (includes 0 and 1)
X<-V18 # other variable of my dataset
plot(X,Y)
# loops for to find the intervals in the graph and use them for the final formula and plot
for (i in 1: X) {
if(X[i]<40){
AN[i]# Here I would like to find the first interval
AN[i]<- 14 # if x is equal to 40 I would like to first take the interval from 0 to 10 and count the numbers of 0 and 1(dots) that are in the plot
AP[i]<-16 # same speech and i count 1
N[i]<-AN[i] + AP[i] #N
MAX[i]=AP[i] * log(AP[i]/N[i]) + AN[i] *log(AN[i]/N[i]) # formula for entering new data
print(MAX[i])
lines(Y~X,ADD=MAX[i], xlab='CBO', ylab='Fault-Proneness')
}
if(X[i]>40) # otherwise examine the other interval
{
AN[i]<- 1 # if x is equal to 40 I would like to first take the interval from 0 to 10 and count the numbers of 0 and 1(dots) that are in the plot
AP[i]<-3 # same speech and i count 1
N[i]<-AN[i] + AP[i] #tot
MAX[i]=AP[i] * log(AP[i]/N[i]) + AN[i] *log(AN[i]/N[i]) # formula for entering new data #print
print(MAX[i]) #print
lines(Y~X,ADD=MAX[i], xlab='CBO', ylab='Fault-Proneness')
}
}
這是我的情節: 情節
這些是指令: 指令
這些是情節: PlotExample
我想知道是否有可能在特定間隔內計算該圖的0和1的數量,並使用找到的值找到MAX並將其添加到圖中。
我認為您不需要從第一個代碼開始循環:
x<-c(23,45,65,46,86,54,78,65,4,3,23,43,65,21,34)
y<-c(0,1,1,0,1,0,1,0,1,1,0,1,1,0,0)
plot(x,y)
xPos1 <- sum(y[x<=40]==1)
xNeg1 <- sum(y[x<=40]==0)
xPos2 <- sum(y[x>40]==1)
xNeg2 <- sum(y[x>40]==0)
NumebrTot1 <- xPos1+xNeg1
NumebrTot2 <- xPos2+xNeg2
Max1 <- xPos1 * log(xPos1/NumebrTot1) + xNeg1 *log(xNeg1/NumebrTot1)
Max2 <- xPos2 * log(xPos2/NumebrTot2) + xNeg2 *log(xNeg2/NumebrTot2)
然后,由於構造,我看不到要繪制的內容,最大值將為負...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.