R data analysis: practical operation of clinical prediction model, examples of calibration curve and DCA curve practice

I have written several very detailed analysis of the principles of the clinical prediction model for you before. This article continues the previous article and continues to write the practice. First of all, I still find a reference paper. Today our example article is an article from the Journal of the American Heart Association:

Zhang X, Yuan K, Wang H, Gong P, Jiang T, Xie Y, Sheng L, Liu D, Liu X, Xu G. Nomogram to Predict Mortality of Endovascular Thrombectomy for Ischemic Stroke Despite Successful Recanalization. J Am Heart Assoc. 2020 Feb 4;9(3):e014899. doi: 10.1161/JAHA.119.014899. Epub 2020 Jan 24. PMID: 31973604; PMCID: PMC7033899.

The original text is posted on it for everyone. What we have to do is to reproduce the statistical part of the article.

Review of the original text

The whole article is to develop a 3-month mortality risk nomogram for predicting cancer patients. What variables are considered and what population cohort is used. This article does not care about it. Interested students can read the original article by themselves. This article focuses on writing the macro approach. The model used by the author is Step-wise logistic regression.

In addition, for the overall model, the author also shows the calibration curve and decision curve of the model (see R data analysis for details on the meaning: the meaning and practice of the calibration curve and DCA curve in the clinical prediction model )

The calibration curve in the article looks like this:

And the decision curve looks like this:

Because the regression or has been written before, today I will write how to do a few pictures.

Practice

I currently have data as follows:

I want to make a prediction model with Y as the dependent variable, and display the nomogram, calibration curve, and decision curve at the same time. ROC has written in detail in the previous article, and I will skip it in this article.

First of all, I need to train my model first, which is a logistics model at this time, and I have to use the lrm function to fit it:

refit <- lrm(y > 3 ~ studage + lectage + service + dept, dat, x = TRUE, y = TRUE)

After the model is fitted to form a refit object, directly connect to the calibrate function, and then plot it:

plot(calibrate(refit, B = 400))

After running the above code, you can directly get the following figure, which basically does not need to be changed, and it is exactly the same as the published document structure:

The above is the method of the calibration curve. Let’s look at the method of the nomograph and the decision curve of the nomograph. Regarding the method of the nomograph, I remember that I wrote a very detailed tutorial document analysis before: The method of survival data and classification outcome nomogram is the most complete in history .

nom <- nomogram(refit, lp=F,fun=plogis, funlabel="Please follow Wechat Channel- Codewar")
plot(nom)

Next, continue to make the decision curve of the nomogram. The decision curve needs to use the dca function, and its basic usage is as follows:

If we do Univariate Decision Curve Analysis, just write the formula and put it in the first parameter. But in our example, we are doing Univariate Decision Curve Analysis. At this time, we need to put the predicted value of the multivariate model on the right side of the formula:

We wanted to examine the value of a statistical model that incorporates family history, age, and the marker. First we will build the logistic regression model with all three variables, and second we would have saved out the predicted probability of having cancer based on the model.

For our model, I need to use the predict function to get the predicted value of the model, and then use the dca function combined with plot to draw the DCA curve. The specific code is as follows:

dca(dat$y>3~Nomogram, dat, 
    thresholds = seq(0.25, 0.75, by = 0.01)
) %>%
  plot(smooth = TRUE,bty='n')

After running and making some adjustments, you can get the picture below. Of course, the picture below can be modified according to the needs, but it is basically the same. It seems to be better than the original text, hehe.

summary

Today, combined with the previous article, I will further introduce the actual practice of the calibration curve and the decision curve. Thank you for reading it patiently. My articles are very detailed, and the important codes are all in the original text. Please forward this article to Moments and reply to the "data link" to get all the data and the learning materials I collected. If it is useful to you, please remember to collect it first, and then like and share.

Everyone’s opinions and suggestions are also welcome. If you want to know any statistical methods, you can leave a message under the article. Maybe I will write a tutorial for you after seeing it. If you have any questions, please feel free to private message. If you have any cooperation intentions, please drop me directly.

Guess you like

Origin blog.csdn.net/tm_ggplot2/article/details/125776315