官网教程
https://rdrr.io/cran/givitiR/man/logit.html
用的是包自带的测试数据,这个包只能对于二分类变量做出校准曲线了
library(givitiR)
data("icuData")
cb <- givitiCalibrationBelt(o = icuData$outcome, #最终结果,二分类金标准
e = icuData$probSaps,#预测概率
devel = "external",#是验证集还是模型训练集
nPoints = 200)#绘制的点数
plot(cb,#返回对象
main = "SAPSII calibration",#图名称
xlab = "SAPSII predicted probability",#x轴名称
ylab = "Observed mortality",#y轴名称
pvalueString =T,#是否显示P值
nString= T,#是否显示样本量
polynomialString =T,#是否显示分类数量
table = T,#是否显示右下角图表
xlim = c(0,1), ylim = c(0,1))#横纵坐标范围
#构建公式
formulaSAPS <- formula(outcome ~ relevel(adm,'schSurg') + relevel(chronic,'noChronDis') +
relevel(age,'<40') + relevel(gcs,'14-15') +
relevel(BP,'100-199') + relevel(HR,'70-119') +
relevel(temp,'<39') + relevel(urine,'>=1') +
relevel(urea,'<0.60') + relevel(WBC,'1-19') +
relevel(potassium,'3-4.9') + relevel(sodium,'125-144') +
relevel(HCO3,'>=20') + relevel(bili,'<4') +
relevel(paFiIfVent,'noVent') )
#进行逻辑回归
refittedSaps <- glm(formula = formulaSAPS,
family=binomial(link='logit'),
na.action = na.exclude,
data = icuData)
#计算预测值
icuData$probRefittedSaps <- predict(refittedSaps, type = "response")
#进行校准曲线分析
cbInternal <- givitiCalibrationBelt(o = icuData$outcome, icuData$probRefittedSaps,
devel = "internal")
#绘制图表
plot(cbInternal, main = "Refitted SAPSII calibration",
xlab = "Refitted SAPSII predicted probability",
ylab = "Observed mortality")