> heart_failure_clinical <-read.csv(file.choose(),header = TRUE)
> heart_failure_clinical
id age anaemia creatinine_phosphokinase diabetes ejection_fraction high_blood_pressure platelets
1 1 75 0 582 0 20 1 265000
2 2 55 0 7861 0 38 0 263358
3 3 65 0 146 0 20 0 162000
4 4 50 1 111 0 20 0 210000
5 5 65 1 160 1 20 0 327000
6 6 90 1 47 0 40 1 204000
7 7 75 1 246 0 15 0 127000
8 8 60 1 315 1 60 0 454000
9 9 65 0 157 0 65 0 263358
10 10 80 1 123 0 35 1 388000
11 11 75 1 81 0 38 1 368000
12 12 62 0 231 0 25 1 253000
13 13 45 1 981 0 30 0 136000
14 14 50 1 168 0 38 1 276000
15 15 49 1 80 0 30 1 427000
16 16 82 1 379 0 50 0 47000
17 17 87 1 149 0 38 0 262000
18 18 45 0 582 0 14 0 166000
19 19 70 1 125 0 25 1 237000
20 20 48 1 582 1 55 0 87000
21 21 65 1 52 0 25 1 276000
22 22 65 1 128 1 30 1 297000
23 23 68 1 220 0 35 1 289000
24 24 53 0 63 1 60 0 368000
25 25 75 0 582 1 30 1 263358
26 26 80 0 148 1 38 0 149000
27 27 95 1 112 0 40 1 196000
28 28 70 0 122 1 45 1 284000
29 29 58 1 60 0 38 0 153000
30 30 82 0 70 1 30 0 200000
31 31 94 0 582 1 38 1 263358
32 32 85 0 23 0 45 0 360000
33 33 50 1 249 1 35 1 319000
34 34 50 1 159 1 30 0 302000
35 35 65 0 94 1 50 1 188000
36 36 69 0 582 1 35 0 228000
37 37 90 1 60 1 50 0 226000
38 38 82 1 855 1 50 1 321000
39 39 60 0 2656 1 30 0 305000
40 40 60 0 235 1 38 0 329000
41 41 70 0 582 0 20 1 263358
42 42 50 0 124 1 30 1 153000
43 43 70 0 571 1 45 1 185000
44 44 72 0 127 1 50 1 218000
45 45 60 1 588 1 60 0 194000
46 46 50 0 582 1 38 0 310000
47 47 51 0 1380 0 25 1 271000
48 48 60 0 582 1 38 1 451000
49 49 80 1 553 0 20 1 140000
50 50 57 1 129 0 30 0 395000
51 51 68 1 577 0 25 1 166000
52 52 53 1 91 0 20 1 418000
53 53 60 0 3964 1 62 0 263358
54 54 70 1 69 1 50 1 351000
55 55 60 1 260 1 38 0 255000
56 56 95 1 371 0 30 0 461000
57 57 70 1 75 0 35 0 223000
58 58 60 1 607 0 40 0 216000
59 59 49 0 789 0 20 1 319000
60 60 72 0 364 1 20 1 254000
61 61 45 0 7702 1 25 1 390000
62 62 50 0 318 0 40 1 216000
63 63 55 0 109 0 35 0 254000
64 64 45 0 582 0 35 0 385000
65 65 45 0 582 0 80 0 263358
66 66 60 0 68 0 20 0 119000
67 67 42 1 250 1 15 0 213000
68 68 72 1 110 0 25 0 274000
69 69 70 0 161 0 25 0 244000
70 70 65 0 113 1 25 0 497000
71 71 41 0 148 0 40 0 374000
serum_creatinine serum_sodium gender smoking time DEATH_EVENT
1 1.90 130 1 0 4 1
2 1.10 136 1 0 6 1
3 1.30 129 1 1 7 1
4 1.90 137 1 0 7 1
5 2.70 116 0 0 8 1
6 2.10 132 1 1 8 1
7 1.20 137 1 0 10 1
8 1.10 131 1 1 10 1
9 1.50 138 0 0 10 1
10 9.40 133 1 1 10 1
11 4.00 131 1 1 10 1
12 0.90 140 1 1 10 1
13 1.10 137 1 0 11 1
14 1.10 137 1 0 11 1
15 1.00 138 0 0 12 0
16 1.30 136 1 0 13 1
17 0.90 140 1 0 14 1
18 0.80 127 1 0 14 1
19 1.00 140 0 0 15 1
20 1.90 121 0 0 15 1
21 1.30 137 0 0 16 0
22 1.60 136 0 0 20 1
23 0.90 140 1 1 20 1
24 0.80 135 1 0 22 0
25 1.83 134 0 0 23 1
26 1.90 144 1 1 23 1
27 1.00 138 0 0 24 1
28 1.30 136 1 1 26 1
29 5.80 134 1 0 26 1
30 1.20 132 1 1 26 1
31 1.83 134 1 0 27 1
32 3.00 132 1 0 28 1
33 1.00 128 0 0 28 1
34 1.20 138 0 0 29 0
35 1.00 140 1 0 29 1
36 3.50 134 1 0 30 1
37 1.00 134 1 0 30 1
38 1.00 145 0 0 30 1
39 2.30 137 1 0 30 0
40 3.00 142 0 0 30 1
41 1.83 134 1 1 31 1
42 1.20 136 0 1 32 1
43 1.20 139 1 1 33 1
44 1.00 134 1 0 33 0
45 1.10 142 0 0 33 1
46 1.90 135 1 1 35 1
47 0.90 130 1 0 38 1
48 0.60 138 1 1 40 1
49 4.40 133 1 0 41 1
50 1.00 140 0 0 42 1
51 1.00 138 1 0 43 1
52 1.40 139 0 0 43 1
53 6.80 146 0 0 43 1
54 1.00 134 0 0 44 1
55 2.20 132 0 1 45 1
56 2.00 132 1 0 50 1
57 2.70 138 1 1 54 0
58 0.60 138 1 1 54 0
59 1.10 136 1 1 55 1
60 1.30 136 1 1 59 1
61 1.00 139 1 0 60 1
62 2.30 131 0 0 60 1
63 1.10 139 1 1 60 0
64 1.00 145 1 0 61 1
65 1.18 137 0 0 63 0
66 2.90 127 1 1 64 1
67 1.30 136 0 0 65 1
68 1.00 140 1 1 65 1
69 1.20 142 0 0 66 1
70 1.83 135 1 0 67 1
71 0.80 140 1 1 68 0
[ reached 'max' / getOption("max.print") -- omitted 228 rows ]
>
> # Show data types
> str(heart_failure_clinical)
'data.frame': 299 obs. of 14 variables:
$ id : int 1 2 3 4 5 6 7 8 9 10 ...
$ age : int 75 55 65 50 65 90 75 60 65 80 ...
$ anaemia : int 0 0 0 1 1 1 1 1 0 1 ...
$ creatinine_phosphokinase: int 582 7861 146 111 160 47 246 315 157 123 ...
$ diabetes : int 0 0 0 0 1 0 0 1 0 0 ...
$ ejection_fraction : int 20 38 20 20 20 40 15 60 65 35 ...
$ high_blood_pressure : int 1 0 0 0 0 1 0 0 0 1 ...
$ platelets : num 265000 263358 162000 210000 327000 ...
$ serum_creatinine : num 1.9 1.1 1.3 1.9 2.7 2.1 1.2 1.1 1.5 9.4 ...
$ serum_sodium : int 130 136 129 137 116 132 137 131 138 133 ...
$ gender : int 1 1 1 1 0 1 1 1 0 1 ...
$ smoking : int 0 0 1 0 0 1 0 1 0 1 ...
$ time : int 4 6 7 7 8 8 10 10 10 10 ...
$ DEATH_EVENT : int 1 1 1 1 1 1 1 1 1 1 ...
>
> # Descriptive Statistic
> summary(heart_failure_clinical)
id age anaemia creatinine_phosphokinase diabetes
Min. : 1.0 Min. :40.00 Min. :0.0000 Min. : 23.0 Min. :0.0000
1st Qu.: 75.5 1st Qu.:51.00 1st Qu.:0.0000 1st Qu.: 116.5 1st Qu.:0.0000
Median :150.0 Median :60.00 Median :0.0000 Median : 250.0 Median :0.0000
Mean :150.0 Mean :60.84 Mean :0.4314 Mean : 581.8 Mean :0.4181
3rd Qu.:224.5 3rd Qu.:70.00 3rd Qu.:1.0000 3rd Qu.: 582.0 3rd Qu.:1.0000
Max. :299.0 Max. :95.00 Max. :1.0000 Max. :7861.0 Max. :1.0000
ejection_fraction high_blood_pressure platelets serum_creatinine serum_sodium
Min. :14.00 Min. :0.0000 Min. : 25100 Min. :0.500 Min. :113.0
1st Qu.:30.00 1st Qu.:0.0000 1st Qu.:212500 1st Qu.:0.900 1st Qu.:134.0
Median :38.00 Median :0.0000 Median :262000 Median :1.100 Median :137.0
Mean :38.08 Mean :0.3512 Mean :263358 Mean :1.394 Mean :136.6
3rd Qu.:45.00 3rd Qu.:1.0000 3rd Qu.:303500 3rd Qu.:1.400 3rd Qu.:140.0
Max. :80.00 Max. :1.0000 Max. :850000 Max. :9.400 Max. :148.0
gender smoking time DEATH_EVENT
Min. :0.0000 Min. :0.0000 Min. : 4.0 Min. :0.0000
1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.: 73.0 1st Qu.:0.0000
Median :1.0000 Median :0.0000 Median :115.0 Median :0.0000
Mean :0.6488 Mean :0.3211 Mean :130.3 Mean :0.3211
3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:203.0 3rd Qu.:1.0000
Max. :1.0000 Max. :1.0000 Max. :285.0 Max. :1.0000
> library(LongCART)
Loading required package: nlme
Loading required package: rpart
Loading required package: survival
Loading required package: magic
Loading required package: abind
Loading required package: survminer
Loading required package: ggplot2
Loading required package: ggpubr
Attaching package: ‘survminer’
The following object is masked from ‘package:survival’:
myeloma
> heart_failure_clinical$subjid<- 1:nrow(heart_failure_clinical)
>
> # Run SurvCART() with time-to-event distribution: exponential, censoring distribution: None
> out<- SurvCART(data=heart_failure_clinical, patid = "id", censorvar="DEATH_EVENT",
+ timevar="time", event.ind=0, gvars=c('anaemia', 'creatinine_phosphokinase', 'diabetes', 'ejection_fraction', 'high_blood_pressure', 'platelets', 'serum_creatinine', 'serum_sodium', 'gender', 'smoking', 'age'), tgvars=c(0,1,0,1,0,1,1,1,0,0,1), alpha=0.05, minsplit=299, minbucket=150, print=TRUE)
------------------------------------------
ROOT NODE: NODE 1
------------------------------------------
No. of subjects in root node: 299
#of subjects at risk :299
#of events :203
Event (%) :67.89
Summary (event time) :106186215
Summary (censoring time):100NANA
Testing splitting variable: anaemia
Stability Test for Categorical grouping variable
Test.statistic= 0.302, Adj. p-value= 0.583
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: creatinine_phosphokinase
Stability Test for Continuous grouping variable
Test.statistic= 0.676, Adj. p-value= 0.751
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: diabetes
Stability Test for Categorical grouping variable
Test.statistic= 0.071, Adj. p-value= 0.79
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: ejection_fraction
Stability Test for Continuous grouping variable
Test.statistic= 1.052, Adj. p-value= 0.218
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: high_blood_pressure
Stability Test for Categorical grouping variable
Test.statistic= 0.787, Adj. p-value= 0.375
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: platelets
Stability Test for Continuous grouping variable
Test.statistic= 0.557, Adj. p-value= 0.916
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: serum_creatinine
Stability Test for Continuous grouping variable
Test.statistic= 1.15, Adj. p-value= 0.142
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: serum_sodium
Stability Test for Continuous grouping variable
Test.statistic= 0.883, Adj. p-value= 0.417
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: gender
Stability Test for Categorical grouping variable
Test.statistic= 0.03, Adj. p-value= 0.861
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: smoking
Stability Test for Categorical grouping variable
Test.statistic= 0.101, Adj. p-value= 0.751
Greater evidence of heterogeneity in time-to-event distribution
Testing splitting variable: age
Stability Test for Continuous grouping variable
Test.statistic= 0.414, Adj. p-value= 0.995
Greater evidence of heterogeneity in time-to-event distribution
***Selected Splitting variable:serum_creatinine***
DECISION: NO more splitting required
ID n D Q1.T median.T Q3.T Q1.C median.C Q3.C yval loglik AIC var index
1 1 299 203 106 186 215 100 NA NA 186 -1270.1 2542.3 serum_creatinine NA
p (Instability) improve Terminal
1 0.995 NA TRUE
logLikelihood (root)=-1270.1 logLikelihood (tree)=-1270.1
AIC (root)=2542.3 AIC (tree)=2542.3
> par(mfrow=c(1,1))
> par(xpd = TRUE)
> plot(compress = TRUE)
Error in plot.default(compress = TRUE) :
argument "x" is missing, with no default
>
The
plot()
function doesn't know what to plot because you haven't provided it with the object to plot, that's the "argument x is missing" error. Assuming you want to plot the output of SurvCART()
, you'd need to pass that to plot()
, so in your case plot(out)
.
I only know that the SurCART model serves merely as a root node, not as the single survival trees—just like the rpart or ctree models. Thank you.
> plot(out)
Error in plot.rpart(x = x, uniform = uniform, branch = branch, compress = compress, :
fit is not a tree, just a root
You might want to post an issue to the maintainer of the package on github.
You will increase your chances of someone being able to help you out further if you turn your example into a reprex, a reproducible example. The reprex package is very handy for this and its website has more info on the why and how of reprexes.
Thank you very much.