Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于分割概率的函数::ans中的错误[!测试和确定]<;-rep(否,length.out=length(ans))[!test&;:替换的长度为零_R_Statistics_Probability_Modeling_Glm - Fatal编程技术网

用于分割概率的函数::ans中的错误[!测试和确定]<;-rep(否,length.out=length(ans))[!test&;:替换的长度为零

用于分割概率的函数::ans中的错误[!测试和确定]<;-rep(否,length.out=length(ans))[!test&;:替换的长度为零,r,statistics,probability,modeling,glm,R,Statistics,Probability,Modeling,Glm,我试图将R中的逻辑回归“glm”模型中的概率划分为不同的名义类别 我有以下功能 nominal_score_test <- function(class_prob) { ifelse(class_prob >= 0.00 & class_prob <= 0.38, '2.Almost Certain', ifelse(class_prob > 0.38 & class_prob <= 0.8

我试图将R中的逻辑回归“glm”模型中的概率划分为不同的名义类别

我有以下功能

nominal_score_test <- function(class_prob) {
             ifelse(class_prob  >= 0.00 & class_prob <= 0.38, '2.Almost Certain',
                ifelse(class_prob > 0.38 & class_prob <= 0.85, '3.Likely',
                    ifelse(class_prob > 0.85 &  class_prob <= 0.91, '3.Likely',
                        ifelse(class_prob > 0.91 & class_prob <= 1.00, '2.Almost Certain',
                                 NULL
                   ))))

nominal\u score\u test=0.00&class\u prob 0.38&class\u prob 0.85&class\u prob 0.91&class\u prob您的函数需要一个double(class\u prob参数),但在调用
nominal\u score\u test(估计值\glm\u tbl$class\u prob)
时,您给它一个double向量,它会产生错误

您需要将
nominal_score_test
函数分别应用于向量的每个元素,并使用apply系列中的一个函数。要返回包含描述的新向量,请尝试


sapply(X=estimates\u glm\u tbl$class\u prob,FUN=nominal\u score\u test)
您的函数需要一个double(class\u prob参数),但在调用
nominal\u score\u test(estimates\u glm\u tbl$class\u prob)
时,您给它一个double向量,它会产生错误

您需要将
nominal_score_test
函数分别应用于向量的每个元素,并使用apply系列中的一个函数。要返回包含描述的新向量,请尝试

sapply(X=估计值\u glm\u tbl$class\u prob,FUN=名义分数\u测试)

nominal_score_test(estimates_glm_tbl$class_prob)

Error in ans[!test & ok] <- rep(no, length.out = length(ans))[!test & : 
replacement has length zero
In addition: Warning message:
In rep(no, length.out = length(ans)) :