微信公眾號:醫學統計與R語言
Syntaxsetwd("C:/Users/mooshaa/Desktop")
library(rio)
surdata <- import("surdata.csv")
head(surdata)
install.packages("rms")
library(rms)
ddist <- datadist(surdata)
options(datadist="ddist")
outsur <- step(cph(Surv(time,status)~group+gender+age+cost+duration+complica+obstruct+size+stage+hb+stb+alt+ast+alp+rgt+wbc,data=surdata,surv=T))
surv <- Survival(outsur)
nom.cox <- nomogram(outsur,fun=list(function(x)surv(180,x),function(x)surv(360,x)),lp=T, funlabel = c("180-month sur.prob","360-month sur.prob"),
maxscale=10,fun.at=c(0.01,seq(0.1,0.9,by=0.2),0.95,0.99))
plot(nom.cox)
install.packages("nomogramEx")
library(nomogramEx)
nomogramEx(nomo=nom.cox ,np=2,digit=9)
$RESULT
[1] "The equation of each variable as follows:"
[[2]]
group
1 0.000000
2 3.861478
[[3]]
obstruct
3 1.446248
4 3.689368
5 0.000000
[[4]]
[1] "points = 0 * size ^3 + 0 * size ^2 + 0.055555556 * size + 0"
[[5]]
stage
16 0.000000
17 1.991769
18 3.983539
19 5.975308
[[6]]
[1] "points = 0 * hb ^2 + -0.035146398 * hb + 5.271959691"
[[7]]
[1] "points = -0.002038589 * alp + 3.669459597"
[[8]]
[1] "points = 0 * wbc ^2 + 0.259352786 * wbc + -0.518705573"
[[9]]
[1] "180-month sur.prob = 0.00182373 * points ^3 + -0.072857575 * points ^2 + 0.835068612 * points + -2.054766838"
[[10]]
[1] "360-month sur.prob = 0.002744276 * points ^3 + -0.083735863 * points ^2 + 0.711957358 * points + -1.072693718"
install.packages("nomogramFormula")
library(nomogramFormula)
results1 <- formula_lp(nom.cox)
points_cal(formula = results1$formula,lp=outsur$linear.predictors)
1 2 3 4 5 6 7 8 9
9.859898 13.314311 17.274773 7.992204 11.188754 8.358988 7.806365 11.019691 9.556878
10 11 12 13 14 15 16 17 18
7.462087 7.737870 8.410744 9.140369 8.652627 9.693196 12.159852 10.786064 10.054633
19 20 21 22 23 24 25 26 27
14.454590 11.853162 8.640914 12.876851 10.068351 11.955685 10.865594 12.645552 20.057451
28 29 30 31 32 33 34 35 36
14.687131 9.713998 14.707065 11.801318 9.215974 13.564127 9.557539 13.708097 12.048266
37 38 39 40 41 42 43 44 45
12.727346 9.996496 11.886226 11.426800 9.601091 12.680332 14.070316 10.581061 11.322002
46 47 48 49 50 51 52 53 54
10.707635 9.157288 17.099612 15.634357 13.413692 14.885511 8.875246 10.735390 11.214028
55 56 57 58 59 60 61 62 63
11.883628 11.727273 14.767096 14.041139 12.137165 12.334519 12.613590 17.533685 14.582680
64 65 66 67 68 69 70 71 72
14.297553 18.042575 15.586426 12.940264 19.370251 21.271664 12.835744 13.505391 14.630610
73 74 75 76 77 78 79 80 81
13.422057 14.865956 15.466658 16.309243 15.007258 21.449334 17.123930 16.756366 17.145820
82 83 84 85 86 87 88 89 90
12.659799 16.064209 21.027333 16.898428 18.357568 16.129465 15.820735 19.289935 19.376327
91 92 93 94 95
21.168455 14.413335 14.814703 14.386963 16.582671
results2 <- formula_rd( nom.cox )
points_cal(formula = results2$formula,rd=surdata )
[1] 9.859874 13.314265 17.274672 7.992178 11.188670 8.358874 7.806267 11.019633 9.556767
[10] 7.462074 7.737822 8.410320 9.140188 8.652492 9.693144 12.159673 10.786038 10.054525
[19] 14.454530 11.852923 8.640387 12.876741 10.067726 11.955555 10.865401 12.645487 20.057292
[28] 14.686475 9.713750 14.706997 11.801218 9.215486 13.564121 9.557072 13.708052 12.047862
[37] 12.727030 9.996349 11.886145 11.426711 9.601012 12.680112 14.070224 10.581009 11.321848
[46] 10.707304 9.157215 17.099599 15.634322 13.413579 14.885355 8.874845 10.735277 11.213895
[55] 11.883590 11.727165 14.767015 14.040920 12.137111 12.334393 12.613559 17.533074 14.582536
[64] 14.297095 18.042440 15.586406 12.940127 19.370123 21.271559 12.835547 13.504814 14.630514
[73] 13.421938 14.865578 15.466471 16.309118 15.007016 21.449177 17.123865 16.756232 17.145575
[82] 12.659742 16.064202 21.027290 16.897818 18.357327 16.129374 15.820606 19.289917 19.376174
[91] 21.168321 14.413062 14.814417 14.386910 16.582618
head(prob_cal(reg = outsur,times = c(180,360)))
linear.predictors P180 P360
1 -1.33552233 0.81497497 4.379768e-01
2 -0.01083272 0.46324637 4.482201e-02
3 1.50791520 0.02978032 6.950720e-07
4 -2.05174121 0.90486841 6.680583e-01
5 -0.82593599 0.71136179 2.530222e-01
6 -1.91108753 0.89130984 6.285746e-01
前文連結:
醫學統計與R語言:多列分組正態性檢驗
醫學統計與R語言:Cleveland dot plot
醫學統計與R語言:交互作用模型中分組效應及標準誤的計算
醫學統計與R語言:多條ROC曲線的AUC多重比較
醫學統計與R語言:來,今天學個散點圖!
醫學統計與R語言:一份簡單的數據整理分析
醫學統計與R語言:利用金字塔圖比較多個指標
醫學統計與R語言:點圖(dotplot)
醫學統計與R語言:幕後高手出馬!
醫學統計與R語言:Calibration plot with 置信區間
醫學統計與R語言:還說自己不會畫Calibration plot!
醫學統計與R語言:KS曲線,KS plot,lift plot
醫學統計與R語言:身體酸痛,醒來學個卡方檢驗
醫學統計與R語言:利用午睡幾分鐘,學習下Population Pyramid
醫學統計與R語言:有序Logistic回歸平行線檢驗(Test proportional odds assumption )
醫學統計與R語言:你的基金標書裡還少這幅圖!
醫學統計與R語言:這裡的坑你踩過幾回,有序多分類Logistic回歸(Ordinal Logistic Regression)
醫學統計與R語言:logsitc回歸校準曲線 Calibration curve
醫學統計與R語言:多分格相關係數(polychoric)多序列相關係數(polyserial)Coefficient Omega
醫學統計與R語言:Tobit回歸中的Marginal effect
醫學統計與R語言:定量變量的無監督離散化( unsupervised discretization)
醫學統計與R語言:Welch's ANOVA and Games-Howell post-hoc test
醫學統計與R語言:配對均值檢驗可視化加label
醫學統計與R語言:線性固定效應模型(Linear fix effect model )
醫學統計與R語言:Tobit回歸模型
函數醫學統計與R語言:隨機森林與Logistic預測(randomForest vs Logistic regression)
醫學統計與R語言:多重比較P值的可視化
醫學統計與R語言:腫瘤研究中的waterfall plot(瀑布圖)
醫學統計與R語言:多元方差分析與非參數多元方差分析
醫學統計與R語言:使用R語言實現Johnson-Neyman分析
醫學統計與R語言:多層線性模型圖示
醫學統計與R語言:多層線性模型(混合線性模型
醫學統計與R語言:best subset of inputs for the glm famil
醫學統計與R語言:多重線回歸自變量篩選的幾種方法
醫學統計與R語言:關聯規則Apriori算
醫學統計與R語言:列聯表可視化的4種方
醫學統計與R語言:盤它!什麼格式文件都可
醫學統計與R語言:離群值分析(Outlier Detection
醫學統計與R語言:決策樹CHAI
醫學統計與R語言:主成分分析(PCA)及可視
醫學統計與R語言:可能是最全R語言操作手冊(cheatsheets)
醫學統計與R語言:聽說你還在手動畫三線表!
醫學統計與R語言:合併多個Excel文
醫學統計與R語言:政策效果評價之合成控制
醫學統計與R語言:線性回歸模型假設條件驗證與診斷
醫學統計與R語言:想發表sci就畫這種Bland-Altman Plot