在is.na(e2)中:is.na()应用于'NULL'类型的非(列表或向量)

时间:2015-09-21 06:57:20

标签: r

我试图在R中使用AUC package来获得特异性。但是我不行。我收到了这条警告信息:

1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
3: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'

这是我使用的命令

specificity(P_hat0[,3], DNew$outcome[DNew$visitmse==0])
$cutoffs
 [1] 1.00000000 1.00000000 0.97727273 0.95454545 0.93181818 0.90909091
 [7] 0.88636364 0.86363636 0.84090909 0.81818182 0.79545455 0.77272727
[13] 0.75000000 0.72727273 0.70454545 0.68181818 0.65909091 0.63636364
[19] 0.61363636 0.59090909 0.56818182 0.54545455 0.52272727 0.50000000
[25] 0.47727273 0.45454545 0.43181818 0.40909091 0.38636364 0.36363636
[31] 0.34090909 0.31818182 0.29545455 0.27272727 0.25000000 0.22727273
[37] 0.20454545 0.18181818 0.15909091 0.13636364 0.11363636 0.09090909
[43] 0.06818182 0.04545455 0.02272727 0.00000000

$measure
 [1] NaN  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
[20]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
[39]  NA  NA  NA  NA  NA  NA  NA   0

attr(,"class")
[1] "AUC"         "specificity"
Warning messages:
1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
3: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'

预测和标签是:

DNew$outcome
  [1] 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0
 [38] 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0
[112] 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1
> P_hat0[,3] 
[1] 0.1676221 0.5666334 0.5520391 0.3845506 0.5369669 0.4210906 0.6804216
 [8] 0.6000813 0.4258318 0.5299374 0.5847862 0.6261463 0.6789501 0.5840120
[15] 0.5413866 0.6426050 0.2822611 0.6945680 0.5959189 0.5231346 0.7052698
[22] 0.5514049 0.7207629 0.6405132 0.1620128 0.7349927 0.5567275 0.6423642
[29] 0.6075940 0.8023867 0.5030725 0.5373831 0.5846428 0.6648525 0.5833133
[36] 0.4888089 0.6430406 0.5713645 0.5366524 0.6193379 0.6407926 0.6624230
[43] 0.6429118 0.6719707 

你能否告诉我为什么这些措施是NAN or NA? 感谢

1 个答案:

答案 0 :(得分:0)

根据?specificity的说明,labels将是factor类。

  

标签:观察到的类标签(响应)的唯一因素             允许值{0,1}。

使用AUC factor'标签'的'churn'数据,specificity不会返回任何警告。

library(AUC)
data(churn)
res1 <-  specificity(churn$predictions,churn$labels)

如果我将'标签'更改为numeric

res2 <-  specificity(churn$predictions,as.numeric(churn$labels))
#Warning messages:
#1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
#2: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
#3: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'

因此,可能将OP的'结果'列更改为'因子'可能有效(假设长度相同)

specificity(P_hat0[,3], factor(DNew$outcome[DNew$visitmse==0]))