Problems with using plotCalibration() from the predictABEL package in R

时间:2016-04-15 14:56:27

标签: r statistics predict calibration

I’ve been having some trouble with the plotCalibration() function, I have managed to get it to work before, but recently whilst working with another dataset (here is a link to the .Rda data file), I have been unable to shake off an error message which keeps cropping up:

> plotCalibration(data = data, cOutcome = 2, predRisk = data$sortmort)

Error in plotCalibration(data = data, cOutcome = 2, predRisk = data$sortmort) : The specified outcome is not a binary variable.`

When I’ve tried to set the cOutcome column to factors or to logical, it still doesn’t work.

I’ve looked at the source of the function and the only time the error message comes up is in the first if()else{} statement:

if (length(unique(y))!=2) {stop(" The specified outcome is not a binary variable.\n")} 
else{

But I have checked that the length(unique(y)) is indeed ==2, and so don’t understand why the error message still crops up!

3 个答案:

答案 0 :(得分:0)

请尝试使用plotCalibration查看数据集结果变量的级别数。

当结果是二元变量(两个级别)时,函数operator.abs将执行。

答案 1 :(得分:0)

使用您之前发送的数据,我看不到任何错误:

产生以下输出以及校准曲线:

> library(PredictABEL)
> plotCalibration(data = data, cOutcome = 2, predRisk = data$sortmort)
$Table_HLtest
               total meanpred meanobs predicted observed
[0.000632,0.00129)   340    0.001   0.000      0.31        0
0.001287             198    0.001   0.000      0.25        0
[0.001374,0.00201)   283    0.002   0.004      0.53        1
0.002009             310    0.002   0.000      0.62        0
[0.002505,0.00409)   154    0.003   0.000      0.52        0
[0.004086,0.00793)   251    0.006   0.000      1.42        0
[0.007931,0.00998)   116    0.008   0.009      0.96        1
[0.009981,0.19545]   181    0.024   0.011      4.40        2

$Chi_square

[1] 4.906

$df

[1] 8

$p_value

[1] 0.7676

答案 2 :(得分:0)

确保将数据帧传递给PlotCalibration。传递dplyr信号可能会导致此错误。使用普通的as.data.frame()进行转换对我有用。