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

烈酒焚心 提交于 2021-01-28 06:33:15

问题


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!


回答1:


Using the data you sent earlier, I do not see any error though:

Following output were produced along with a calibration plot:

> 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:


Be sure you're passing a dataframe to PlotCalibration. Passing a dplyr tibble can cause this error. Converting with the normal as.data.frame() worked for me.




回答3:


Please try using table(data[,2],useNA = "ifany") to see the number of levels of the outcome variable of your dataset.

The function plotCalibration will execute when the outcome is a binary variable (two levels).



来源:https://stackoverflow.com/questions/36650517/problems-with-using-plotcalibration-from-the-predictabel-package-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!