I'm doing a validation study of an ordinal logistic regression model that was made with the lrm function of the rms package in R. How can I plot the calibration curve for the model when applied to new data? I want to create the cal1 and cal2 plots below (without bootstrapping), but using a new sample:
library(rms)
library(heplots)
data(Diabetes)
d = Diabetes
id = 1:145
d$id = id
training = d[sample(1:nrow(d), 75, replace = F),]
testing = d[-training$id,]
dd <- datadist(training)
options(datadist = "dd")
mod = lrm(group ~ glufast, data = training, x = T, y = T)
# normal is reference level, Chemical_Diabetic is middle level, and then Overt_Diabetic
cal1 = plot(calibrate(mod, kint = 1)) # plot for group >= Chemical_Diabetic
cal2 = plot(calibrate(mod, kint = 2)) # plot for group >= Overt_Diabetic
I have previously used the val.prob function to calibrate a new sample with a binary response, but this function doesn't take an ordinal outcome. I tried changing my response to be binary for each level (y >= Chemical_Diabetic and y >= Overt_Diabetic), but it seems incorrect:
pred.test = as.data.frame(predict(mod, testing, type = "fitted"))
chemical.pred = pred.test[,1] # select predictions for >= Chemical_Diabetic
overt.pred = pred.test[,2] # select predictions for >= Overt_Diabetic
y = as.numeric(testing$group)
y.chemical <- replace(y, y==3, 2) # set Overt_Diabetic to Chemical_Diabetic
y.overt <- replace(y, y==2, 1) # set Chemical_Diabetic to Normal
val.prob(chemical.pred, y.chemical, logistic.cal = F, smooth = T) # trying to be cal1
val.prob(overt.pred, y.overt, logistic.cal = F, smooth = T) # trying to be cal2
lrm
is for binary or ordinal $Y$. Your $Y$ is nominal/multinomial/polytomous. $\endgroup$predict
, then useval.prob
to validate that against actual Y >= cutoff binary variable. $\endgroup$