mortality = read.csv("Mortality.csv")
str(mortality)
## 'data.frame': 299 obs. of 13 variables:
## $ age : num 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 ...
## $ sex : 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 ...
#death = seq(1, 299)
#death
mortality$DEATH = NA
head(mortality)
## age anaemia creatinine_phosphokinase diabetes ejection_fraction
## 1 75 0 582 0 20
## 2 55 0 7861 0 38
## 3 65 0 146 0 20
## 4 50 1 111 0 20
## 5 65 1 160 1 20
## 6 90 1 47 0 40
## high_blood_pressure platelets serum_creatinine serum_sodium sex smoking time
## 1 1 265000 1.9 130 1 0 4
## 2 0 263358 1.1 136 1 0 6
## 3 0 162000 1.3 129 1 1 7
## 4 0 210000 1.9 137 1 0 7
## 5 0 327000 2.7 116 0 0 8
## 6 1 204000 2.1 132 1 1 8
## DEATH_EVENT DEATH
## 1 1 NA
## 2 1 NA
## 3 1 NA
## 4 1 NA
## 5 1 NA
## 6 1 NA
mortality$DEATH[mortality$DEATH_EVENT == 0] = 'no'
mortality$DEATH[mortality$DEATH_EVENT == 1] = 'yes'
mortality
## age anaemia creatinine_phosphokinase diabetes ejection_fraction
## 1 75.000 0 582 0 20
## 2 55.000 0 7861 0 38
## 3 65.000 0 146 0 20
## 4 50.000 1 111 0 20
## 5 65.000 1 160 1 20
## 6 90.000 1 47 0 40
## 7 75.000 1 246 0 15
## 8 60.000 1 315 1 60
## 9 65.000 0 157 0 65
## 10 80.000 1 123 0 35
## 11 75.000 1 81 0 38
## 12 62.000 0 231 0 25
## 13 45.000 1 981 0 30
## 14 50.000 1 168 0 38
## 15 49.000 1 80 0 30
## 16 82.000 1 379 0 50
## 17 87.000 1 149 0 38
## 18 45.000 0 582 0 14
## 19 70.000 1 125 0 25
## 20 48.000 1 582 1 55
## 21 65.000 1 52 0 25
## 22 65.000 1 128 1 30
## 23 68.000 1 220 0 35
## 24 53.000 0 63 1 60
## 25 75.000 0 582 1 30
## 26 80.000 0 148 1 38
## 27 95.000 1 112 0 40
## 28 70.000 0 122 1 45
## 29 58.000 1 60 0 38
## 30 82.000 0 70 1 30
## 31 94.000 0 582 1 38
## 32 85.000 0 23 0 45
## 33 50.000 1 249 1 35
## 34 50.000 1 159 1 30
## 35 65.000 0 94 1 50
## 36 69.000 0 582 1 35
## 37 90.000 1 60 1 50
## 38 82.000 1 855 1 50
## 39 60.000 0 2656 1 30
## 40 60.000 0 235 1 38
## 41 70.000 0 582 0 20
## 42 50.000 0 124 1 30
## 43 70.000 0 571 1 45
## 44 72.000 0 127 1 50
## 45 60.000 1 588 1 60
## 46 50.000 0 582 1 38
## 47 51.000 0 1380 0 25
## 48 60.000 0 582 1 38
## 49 80.000 1 553 0 20
## 50 57.000 1 129 0 30
## 51 68.000 1 577 0 25
## 52 53.000 1 91 0 20
## 53 60.000 0 3964 1 62
## 54 70.000 1 69 1 50
## 55 60.000 1 260 1 38
## 56 95.000 1 371 0 30
## 57 70.000 1 75 0 35
## 58 60.000 1 607 0 40
## 59 49.000 0 789 0 20
## 60 72.000 0 364 1 20
## 61 45.000 0 7702 1 25
## 62 50.000 0 318 0 40
## 63 55.000 0 109 0 35
## 64 45.000 0 582 0 35
## 65 45.000 0 582 0 80
## 66 60.000 0 68 0 20
## 67 42.000 1 250 1 15
## 68 72.000 1 110 0 25
## 69 70.000 0 161 0 25
## 70 65.000 0 113 1 25
## 71 41.000 0 148 0 40
## 72 58.000 0 582 1 35
## 73 85.000 0 5882 0 35
## 74 65.000 0 224 1 50
## 75 69.000 0 582 0 20
## 76 60.000 1 47 0 20
## 77 70.000 0 92 0 60
## 78 42.000 0 102 1 40
## 79 75.000 1 203 1 38
## 80 55.000 0 336 0 45
## 81 70.000 0 69 0 40
## 82 67.000 0 582 0 50
## 83 60.000 1 76 1 25
## 84 79.000 1 55 0 50
## 85 59.000 1 280 1 25
## 86 51.000 0 78 0 50
## 87 55.000 0 47 0 35
## 88 65.000 1 68 1 60
## 89 44.000 0 84 1 40
## 90 57.000 1 115 0 25
## 91 70.000 0 66 1 45
## 92 60.000 0 897 1 45
## 93 42.000 0 582 0 60
## 94 60.000 1 154 0 25
## 95 58.000 0 144 1 38
## 96 58.000 1 133 0 60
## 97 63.000 1 514 1 25
## 98 70.000 1 59 0 60
## 99 60.000 1 156 1 25
## 100 63.000 1 61 1 40
## 101 65.000 1 305 0 25
## 102 75.000 0 582 0 45
## 103 80.000 0 898 0 25
## 104 42.000 0 5209 0 30
## 105 60.000 0 53 0 50
## 106 72.000 1 328 0 30
## 107 55.000 0 748 0 45
## 108 45.000 1 1876 1 35
## 109 63.000 0 936 0 38
## 110 45.000 0 292 1 35
## 111 85.000 0 129 0 60
## 112 55.000 0 60 0 35
## 113 50.000 0 369 1 25
## 114 70.000 1 143 0 60
## 115 60.000 1 754 1 40
## 116 58.000 1 400 0 40
## 117 60.000 1 96 1 60
## 118 85.000 1 102 0 60
## 119 65.000 1 113 1 60
## 120 86.000 0 582 0 38
## 121 60.000 1 737 0 60
## 122 66.000 1 68 1 38
## 123 60.000 0 96 1 38
## 124 60.000 1 582 0 30
## 125 60.000 0 582 0 40
## 126 43.000 1 358 0 50
## 127 46.000 0 168 1 17
## 128 58.000 1 200 1 60
## 129 61.000 0 248 0 30
## 130 53.000 1 270 1 35
## 131 53.000 1 1808 0 60
## 132 60.000 1 1082 1 45
## 133 46.000 0 719 0 40
## 134 63.000 0 193 0 60
## 135 81.000 0 4540 0 35
## 136 75.000 0 582 0 40
## 137 65.000 1 59 1 60
## 138 68.000 1 646 0 25
## 139 62.000 0 281 1 35
## 140 50.000 0 1548 0 30
## 141 80.000 0 805 0 38
## 142 46.000 1 291 0 35
## 143 50.000 0 482 1 30
## 144 61.000 1 84 0 40
## 145 72.000 1 943 0 25
## 146 50.000 0 185 0 30
## 147 52.000 0 132 0 30
## 148 64.000 0 1610 0 60
## 149 75.000 1 582 0 30
## 150 60.000 0 2261 0 35
## 151 72.000 0 233 0 45
## 152 62.000 0 30 1 60
## 153 50.000 0 115 0 45
## 154 50.000 0 1846 1 35
## 155 65.000 1 335 0 35
## 156 60.000 1 231 1 25
## 157 52.000 1 58 0 35
## 158 50.000 0 250 0 25
## 159 85.000 1 910 0 50
## 160 59.000 1 129 0 45
## 161 66.000 1 72 0 40
## 162 45.000 1 130 0 35
## 163 63.000 1 582 0 40
## 164 50.000 1 2334 1 35
## 165 45.000 0 2442 1 30
## 166 80.000 0 776 1 38
## 167 53.000 0 196 0 60
## 168 59.000 0 66 1 20
## 169 65.000 0 582 1 40
## 170 70.000 0 835 0 35
## 171 51.000 1 582 1 35
## 172 52.000 0 3966 0 40
## 173 70.000 1 171 0 60
## 174 50.000 1 115 0 20
## 175 65.000 0 198 1 35
## 176 60.000 1 95 0 60
## 177 69.000 0 1419 0 40
## 178 49.000 1 69 0 50
## 179 63.000 1 122 1 60
## 180 55.000 0 835 0 40
## 181 40.000 0 478 1 30
## 182 59.000 1 176 1 25
## 183 65.000 0 395 1 25
## 184 75.000 0 99 0 38
## 185 58.000 1 145 0 25
## 186 60.667 1 104 1 30
## 187 50.000 0 582 0 50
## 188 60.000 0 1896 1 25
## 189 60.667 1 151 1 40
## 190 40.000 0 244 0 45
## 191 80.000 0 582 1 35
## 192 64.000 1 62 0 60
## 193 50.000 1 121 1 40
## 194 73.000 1 231 1 30
## 195 45.000 0 582 0 20
## 196 77.000 1 418 0 45
## 197 45.000 0 582 1 38
## 198 65.000 0 167 0 30
## 199 50.000 1 582 1 20
## 200 60.000 0 1211 1 35
## 201 63.000 1 1767 0 45
## 202 45.000 0 308 1 60
## 203 70.000 0 97 0 60
## 204 60.000 0 59 0 25
## 205 78.000 1 64 0 40
## 206 50.000 1 167 1 45
## 207 40.000 1 101 0 40
## 208 85.000 0 212 0 38
## 209 60.000 1 2281 1 40
## 210 49.000 0 972 1 35
## 211 70.000 0 212 1 17
## 212 50.000 0 582 0 62
## 213 78.000 0 224 0 50
## 214 48.000 1 131 1 30
## 215 65.000 1 135 0 35
## 216 73.000 0 582 0 35
## 217 70.000 0 1202 0 50
## 218 54.000 1 427 0 70
## 219 68.000 1 1021 1 35
## 220 55.000 0 582 1 35
## 221 73.000 0 582 0 20
## 222 65.000 0 118 0 50
## 223 42.000 1 86 0 35
## 224 47.000 0 582 0 25
## 225 58.000 0 582 1 25
## 226 75.000 0 675 1 60
## 227 58.000 1 57 0 25
## 228 55.000 1 2794 0 35
## 229 65.000 0 56 0 25
## 230 72.000 0 211 0 25
## 231 60.000 0 166 0 30
## 232 70.000 0 93 0 35
## 233 40.000 1 129 0 35
## 234 53.000 1 707 0 38
## 235 53.000 1 582 0 45
## 236 77.000 1 109 0 50
## 237 75.000 0 119 0 50
## 238 70.000 0 232 0 30
## 239 65.000 1 720 1 40
## 240 55.000 1 180 0 45
## 241 70.000 0 81 1 35
## 242 65.000 0 582 1 30
## 243 40.000 0 90 0 35
## 244 73.000 1 1185 0 40
## 245 54.000 0 582 1 38
## 246 61.000 1 80 1 38
## 247 55.000 0 2017 0 25
## 248 64.000 0 143 0 25
## 249 40.000 0 624 0 35
## 250 53.000 0 207 1 40
## 251 50.000 0 2522 0 30
## 252 55.000 0 572 1 35
## 253 50.000 0 245 0 45
## 254 70.000 0 88 1 35
## 255 53.000 1 446 0 60
## 256 52.000 1 191 1 30
## 257 65.000 0 326 0 38
## 258 58.000 0 132 1 38
## 259 45.000 1 66 1 25
## 260 53.000 0 56 0 50
## 261 55.000 0 66 0 40
## 262 62.000 1 655 0 40
## 263 65.000 1 258 1 25
## 264 68.000 1 157 1 60
## 265 61.000 0 582 1 38
## 266 50.000 1 298 0 35
## 267 55.000 0 1199 0 20
## 268 56.000 1 135 1 38
## 269 45.000 0 582 1 38
## 270 40.000 0 582 1 35
## 271 44.000 0 582 1 30
## 272 51.000 0 582 1 40
## 273 67.000 0 213 0 38
## 274 42.000 0 64 0 40
## 275 60.000 1 257 1 30
## 276 45.000 0 582 0 38
## 277 70.000 0 618 0 35
## 278 70.000 0 582 1 38
## 279 50.000 1 1051 1 30
## 280 55.000 0 84 1 38
## 281 70.000 0 2695 1 40
## 282 70.000 0 582 0 40
## 283 42.000 0 64 0 30
## 284 65.000 0 1688 0 38
## 285 50.000 1 54 0 40
## 286 55.000 1 170 1 40
## 287 60.000 0 253 0 35
## 288 45.000 0 582 1 55
## 289 65.000 0 892 1 35
## 290 90.000 1 337 0 38
## 291 45.000 0 615 1 55
## 292 60.000 0 320 0 35
## 293 52.000 0 190 1 38
## 294 63.000 1 103 1 35
## 295 62.000 0 61 1 38
## 296 55.000 0 1820 0 38
## 297 45.000 0 2060 1 60
## 298 45.000 0 2413 0 38
## 299 50.000 0 196 0 45
## high_blood_pressure platelets serum_creatinine serum_sodium sex smoking
## 1 1 265000 1.90 130 1 0
## 2 0 263358 1.10 136 1 0
## 3 0 162000 1.30 129 1 1
## 4 0 210000 1.90 137 1 0
## 5 0 327000 2.70 116 0 0
## 6 1 204000 2.10 132 1 1
## 7 0 127000 1.20 137 1 0
## 8 0 454000 1.10 131 1 1
## 9 0 263358 1.50 138 0 0
## 10 1 388000 9.40 133 1 1
## 11 1 368000 4.00 131 1 1
## 12 1 253000 0.90 140 1 1
## 13 0 136000 1.10 137 1 0
## 14 1 276000 1.10 137 1 0
## 15 1 427000 1.00 138 0 0
## 16 0 47000 1.30 136 1 0
## 17 0 262000 0.90 140 1 0
## 18 0 166000 0.80 127 1 0
## 19 1 237000 1.00 140 0 0
## 20 0 87000 1.90 121 0 0
## 21 1 276000 1.30 137 0 0
## 22 1 297000 1.60 136 0 0
## 23 1 289000 0.90 140 1 1
## 24 0 368000 0.80 135 1 0
## 25 1 263358 1.83 134 0 0
## 26 0 149000 1.90 144 1 1
## 27 1 196000 1.00 138 0 0
## 28 1 284000 1.30 136 1 1
## 29 0 153000 5.80 134 1 0
## 30 0 200000 1.20 132 1 1
## 31 1 263358 1.83 134 1 0
## 32 0 360000 3.00 132 1 0
## 33 1 319000 1.00 128 0 0
## 34 0 302000 1.20 138 0 0
## 35 1 188000 1.00 140 1 0
## 36 0 228000 3.50 134 1 0
## 37 0 226000 1.00 134 1 0
## 38 1 321000 1.00 145 0 0
## 39 0 305000 2.30 137 1 0
## 40 0 329000 3.00 142 0 0
## 41 1 263358 1.83 134 1 1
## 42 1 153000 1.20 136 0 1
## 43 1 185000 1.20 139 1 1
## 44 1 218000 1.00 134 1 0
## 45 0 194000 1.10 142 0 0
## 46 0 310000 1.90 135 1 1
## 47 1 271000 0.90 130 1 0
## 48 1 451000 0.60 138 1 1
## 49 1 140000 4.40 133 1 0
## 50 0 395000 1.00 140 0 0
## 51 1 166000 1.00 138 1 0
## 52 1 418000 1.40 139 0 0
## 53 0 263358 6.80 146 0 0
## 54 1 351000 1.00 134 0 0
## 55 0 255000 2.20 132 0 1
## 56 0 461000 2.00 132 1 0
## 57 0 223000 2.70 138 1 1
## 58 0 216000 0.60 138 1 1
## 59 1 319000 1.10 136 1 1
## 60 1 254000 1.30 136 1 1
## 61 1 390000 1.00 139 1 0
## 62 1 216000 2.30 131 0 0
## 63 0 254000 1.10 139 1 1
## 64 0 385000 1.00 145 1 0
## 65 0 263358 1.18 137 0 0
## 66 0 119000 2.90 127 1 1
## 67 0 213000 1.30 136 0 0
## 68 0 274000 1.00 140 1 1
## 69 0 244000 1.20 142 0 0
## 70 0 497000 1.83 135 1 0
## 71 0 374000 0.80 140 1 1
## 72 0 122000 0.90 139 1 1
## 73 0 243000 1.00 132 1 1
## 74 0 149000 1.30 137 1 1
## 75 0 266000 1.20 134 1 1
## 76 0 204000 0.70 139 1 1
## 77 1 317000 0.80 140 0 1
## 78 0 237000 1.20 140 1 0
## 79 1 283000 0.60 131 1 1
## 80 1 324000 0.90 140 0 0
## 81 0 293000 1.70 136 0 0
## 82 0 263358 1.18 137 1 1
## 83 0 196000 2.50 132 0 0
## 84 1 172000 1.80 133 1 0
## 85 1 302000 1.00 141 0 0
## 86 0 406000 0.70 140 1 0
## 87 1 173000 1.10 137 1 0
## 88 1 304000 0.80 140 1 0
## 89 1 235000 0.70 139 1 0
## 90 1 181000 1.10 144 1 0
## 91 0 249000 0.80 136 1 1
## 92 0 297000 1.00 133 1 0
## 93 0 263358 1.18 137 0 0
## 94 0 210000 1.70 135 1 0
## 95 1 327000 0.70 142 0 0
## 96 1 219000 1.00 141 1 0
## 97 1 254000 1.30 134 1 0
## 98 0 255000 1.10 136 0 0
## 99 1 318000 1.20 137 0 0
## 100 0 221000 1.10 140 0 0
## 101 0 298000 1.10 141 1 0
## 102 1 263358 1.18 137 1 0
## 103 0 149000 1.10 144 1 1
## 104 0 226000 1.00 140 1 1
## 105 1 286000 2.30 143 0 0
## 106 1 621000 1.70 138 0 1
## 107 0 263000 1.30 137 1 0
## 108 0 226000 0.90 138 1 0
## 109 0 304000 1.10 133 1 1
## 110 0 850000 1.30 142 1 1
## 111 0 306000 1.20 132 1 1
## 112 0 228000 1.20 135 1 1
## 113 0 252000 1.60 136 1 0
## 114 0 351000 1.30 137 0 0
## 115 1 328000 1.20 126 1 0
## 116 0 164000 1.00 139 0 0
## 117 1 271000 0.70 136 0 0
## 118 0 507000 3.20 138 0 0
## 119 1 203000 0.90 140 0 0
## 120 0 263358 1.83 134 0 0
## 121 1 210000 1.50 135 1 1
## 122 1 162000 1.00 136 0 0
## 123 0 228000 0.75 140 0 0
## 124 1 127000 0.90 145 0 0
## 125 0 217000 3.70 134 1 0
## 126 0 237000 1.30 135 0 0
## 127 1 271000 2.10 124 0 0
## 128 0 300000 0.80 137 0 0
## 129 1 267000 0.70 136 1 1
## 130 0 227000 3.40 145 1 0
## 131 1 249000 0.70 138 1 1
## 132 0 250000 6.10 131 1 0
## 133 1 263358 1.18 137 0 0
## 134 1 295000 1.30 145 1 1
## 135 0 231000 1.18 137 1 1
## 136 0 263358 1.18 137 1 0
## 137 0 172000 0.90 137 0 0
## 138 0 305000 2.10 130 1 0
## 139 0 221000 1.00 136 0 0
## 140 1 211000 0.80 138 1 0
## 141 0 263358 1.10 134 1 0
## 142 0 348000 0.90 140 0 0
## 143 0 329000 0.90 132 0 0
## 144 1 229000 0.90 141 0 0
## 145 1 338000 1.70 139 1 1
## 146 0 266000 0.70 141 1 1
## 147 0 218000 0.70 136 1 1
## 148 0 242000 1.00 137 1 0
## 149 0 225000 1.83 134 1 0
## 150 1 228000 0.90 136 1 0
## 151 1 235000 2.50 135 0 0
## 152 1 244000 0.90 139 1 0
## 153 1 184000 0.90 134 1 1
## 154 0 263358 1.18 137 1 1
## 155 1 235000 0.80 136 0 0
## 156 0 194000 1.70 140 1 0
## 157 0 277000 1.40 136 0 0
## 158 0 262000 1.00 136 1 1
## 159 0 235000 1.30 134 1 0
## 160 1 362000 1.10 139 1 1
## 161 1 242000 1.20 134 1 0
## 162 0 174000 0.80 139 1 1
## 163 0 448000 0.90 137 1 1
## 164 0 75000 0.90 142 0 0
## 165 0 334000 1.10 139 1 0
## 166 1 192000 1.30 135 0 0
## 167 0 220000 0.70 133 1 1
## 168 0 70000 2.40 134 1 0
## 169 0 270000 1.00 138 0 0
## 170 1 305000 0.80 133 0 0
## 171 0 263358 1.50 136 1 1
## 172 0 325000 0.90 140 1 1
## 173 1 176000 1.10 145 1 1
## 174 0 189000 0.80 139 1 0
## 175 1 281000 0.90 137 1 1
## 176 0 337000 1.00 138 1 1
## 177 0 105000 1.00 135 1 1
## 178 0 132000 1.00 140 0 0
## 179 0 267000 1.20 145 1 0
## 180 0 279000 0.70 140 1 1
## 181 0 303000 0.90 136 1 0
## 182 0 221000 1.00 136 1 1
## 183 0 265000 1.20 136 1 1
## 184 1 224000 2.50 134 1 0
## 185 0 219000 1.20 137 1 1
## 186 0 389000 1.50 136 1 0
## 187 0 153000 0.60 134 0 0
## 188 0 365000 2.10 144 0 0
## 189 1 201000 1.00 136 0 0
## 190 1 275000 0.90 140 0 0
## 191 0 350000 2.10 134 1 0
## 192 0 309000 1.50 135 0 0
## 193 0 260000 0.70 130 1 0
## 194 0 160000 1.18 142 1 1
## 195 1 126000 1.60 135 1 0
## 196 0 223000 1.80 145 1 0
## 197 1 263358 1.18 137 0 0
## 198 0 259000 0.80 138 0 0
## 199 1 279000 1.00 134 0 0
## 200 0 263358 1.80 113 1 1
## 201 0 73000 0.70 137 1 0
## 202 1 377000 1.00 136 1 0
## 203 1 220000 0.90 138 1 0
## 204 1 212000 3.50 136 1 1
## 205 0 277000 0.70 137 1 1
## 206 0 362000 1.00 136 0 0
## 207 0 226000 0.80 141 0 0
## 208 0 186000 0.90 136 1 0
## 209 0 283000 1.00 141 0 0
## 210 1 268000 0.80 130 0 0
## 211 1 389000 1.00 136 1 1
## 212 1 147000 0.80 140 1 1
## 213 0 481000 1.40 138 1 1
## 214 1 244000 1.60 130 0 0
## 215 1 290000 0.80 134 1 0
## 216 1 203000 1.30 134 1 0
## 217 1 358000 0.90 141 0 0
## 218 1 151000 9.00 137 0 0
## 219 0 271000 1.10 134 1 0
## 220 1 371000 0.70 140 0 0
## 221 0 263358 1.83 134 1 0
## 222 0 194000 1.10 145 1 1
## 223 0 365000 1.10 139 1 1
## 224 0 130000 0.80 134 1 0
## 225 0 504000 1.00 138 1 0
## 226 0 265000 1.40 125 0 0
## 227 0 189000 1.30 132 1 1
## 228 1 141000 1.00 140 1 0
## 229 0 237000 5.00 130 0 0
## 230 0 274000 1.20 134 0 0
## 231 0 62000 1.70 127 0 0
## 232 0 185000 1.10 134 1 1
## 233 0 255000 0.90 137 1 0
## 234 0 330000 1.40 137 1 1
## 235 0 305000 1.10 137 1 1
## 236 1 406000 1.10 137 1 0
## 237 1 248000 1.10 148 1 0
## 238 0 173000 1.20 132 1 0
## 239 0 257000 1.00 136 0 0
## 240 0 263358 1.18 137 1 1
## 241 1 533000 1.30 139 0 0
## 242 0 249000 1.30 136 1 1
## 243 0 255000 1.10 136 1 1
## 244 1 220000 0.90 141 0 0
## 245 0 264000 1.80 134 1 0
## 246 0 282000 1.40 137 1 0
## 247 0 314000 1.10 138 1 0
## 248 0 246000 2.40 135 1 0
## 249 0 301000 1.00 142 1 1
## 250 0 223000 1.20 130 0 0
## 251 1 404000 0.50 139 0 0
## 252 0 231000 0.80 143 0 0
## 253 1 274000 1.00 133 1 0
## 254 1 236000 1.20 132 0 0
## 255 1 263358 1.00 139 1 0
## 256 1 334000 1.00 142 1 1
## 257 0 294000 1.70 139 0 0
## 258 1 253000 1.00 139 1 0
## 259 0 233000 0.80 135 1 0
## 260 0 308000 0.70 135 1 1
## 261 0 203000 1.00 138 1 0
## 262 0 283000 0.70 133 0 0
## 263 0 198000 1.40 129 1 0
## 264 0 208000 1.00 140 0 0
## 265 0 147000 1.20 141 1 0
## 266 0 362000 0.90 140 1 1
## 267 0 263358 1.83 134 1 1
## 268 0 133000 1.70 140 1 0
## 269 0 302000 0.90 140 0 0
## 270 0 222000 1.00 132 1 0
## 271 1 263358 1.60 130 1 1
## 272 0 221000 0.90 134 0 0
## 273 0 215000 1.20 133 0 0
## 274 0 189000 0.70 140 1 0
## 275 0 150000 1.00 137 1 1
## 276 1 422000 0.80 137 0 0
## 277 0 327000 1.10 142 0 0
## 278 0 25100 1.10 140 1 0
## 279 0 232000 0.70 136 0 0
## 280 0 451000 1.30 136 0 0
## 281 0 241000 1.00 137 1 0
## 282 0 51000 2.70 136 1 1
## 283 0 215000 3.80 128 1 1
## 284 0 263358 1.10 138 1 1
## 285 0 279000 0.80 141 1 0
## 286 0 336000 1.20 135 1 0
## 287 0 279000 1.70 140 1 0
## 288 0 543000 1.00 132 0 0
## 289 0 263358 1.10 142 0 0
## 290 0 390000 0.90 144 0 0
## 291 0 222000 0.80 141 0 0
## 292 0 133000 1.40 139 1 0
## 293 0 382000 1.00 140 1 1
## 294 0 179000 0.90 136 1 1
## 295 1 155000 1.10 143 1 1
## 296 0 270000 1.20 139 0 0
## 297 0 742000 0.80 138 0 0
## 298 0 140000 1.40 140 1 1
## 299 0 395000 1.60 136 1 1
## time DEATH_EVENT DEATH
## 1 4 1 yes
## 2 6 1 yes
## 3 7 1 yes
## 4 7 1 yes
## 5 8 1 yes
## 6 8 1 yes
## 7 10 1 yes
## 8 10 1 yes
## 9 10 1 yes
## 10 10 1 yes
## 11 10 1 yes
## 12 10 1 yes
## 13 11 1 yes
## 14 11 1 yes
## 15 12 0 no
## 16 13 1 yes
## 17 14 1 yes
## 18 14 1 yes
## 19 15 1 yes
## 20 15 1 yes
## 21 16 0 no
## 22 20 1 yes
## 23 20 1 yes
## 24 22 0 no
## 25 23 1 yes
## 26 23 1 yes
## 27 24 1 yes
## 28 26 1 yes
## 29 26 1 yes
## 30 26 1 yes
## 31 27 1 yes
## 32 28 1 yes
## 33 28 1 yes
## 34 29 0 no
## 35 29 1 yes
## 36 30 1 yes
## 37 30 1 yes
## 38 30 1 yes
## 39 30 0 no
## 40 30 1 yes
## 41 31 1 yes
## 42 32 1 yes
## 43 33 1 yes
## 44 33 0 no
## 45 33 1 yes
## 46 35 1 yes
## 47 38 1 yes
## 48 40 1 yes
## 49 41 1 yes
## 50 42 1 yes
## 51 43 1 yes
## 52 43 1 yes
## 53 43 1 yes
## 54 44 1 yes
## 55 45 1 yes
## 56 50 1 yes
## 57 54 0 no
## 58 54 0 no
## 59 55 1 yes
## 60 59 1 yes
## 61 60 1 yes
## 62 60 1 yes
## 63 60 0 no
## 64 61 1 yes
## 65 63 0 no
## 66 64 1 yes
## 67 65 1 yes
## 68 65 1 yes
## 69 66 1 yes
## 70 67 1 yes
## 71 68 0 no
## 72 71 0 no
## 73 72 1 yes
## 74 72 0 no
## 75 73 1 yes
## 76 73 1 yes
## 77 74 0 no
## 78 74 0 no
## 79 74 0 no
## 80 74 0 no
## 81 75 0 no
## 82 76 0 no
## 83 77 1 yes
## 84 78 0 no
## 85 78 1 yes
## 86 79 0 no
## 87 79 0 no
## 88 79 0 no
## 89 79 0 no
## 90 79 0 no
## 91 80 0 no
## 92 80 0 no
## 93 82 0 no
## 94 82 1 yes
## 95 83 0 no
## 96 83 0 no
## 97 83 0 no
## 98 85 0 no
## 99 85 0 no
## 100 86 0 no
## 101 87 0 no
## 102 87 0 no
## 103 87 0 no
## 104 87 0 no
## 105 87 0 no
## 106 88 1 yes
## 107 88 0 no
## 108 88 0 no
## 109 88 0 no
## 110 88 0 no
## 111 90 1 yes
## 112 90 0 no
## 113 90 0 no
## 114 90 1 yes
## 115 91 0 no
## 116 91 0 no
## 117 94 0 no
## 118 94 0 no
## 119 94 0 no
## 120 95 1 yes
## 121 95 0 no
## 122 95 0 no
## 123 95 0 no
## 124 95 0 no
## 125 96 1 yes
## 126 97 0 no
## 127 100 1 yes
## 128 104 0 no
## 129 104 0 no
## 130 105 0 no
## 131 106 0 no
## 132 107 0 no
## 133 107 0 no
## 134 107 0 no
## 135 107 0 no
## 136 107 0 no
## 137 107 0 no
## 138 108 0 no
## 139 108 0 no
## 140 108 0 no
## 141 109 1 yes
## 142 109 0 no
## 143 109 0 no
## 144 110 0 no
## 145 111 1 yes
## 146 112 0 no
## 147 112 0 no
## 148 113 0 no
## 149 113 1 yes
## 150 115 0 no
## 151 115 1 yes
## 152 117 0 no
## 153 118 0 no
## 154 119 0 no
## 155 120 0 no
## 156 120 0 no
## 157 120 0 no
## 158 120 0 no
## 159 121 0 no
## 160 121 0 no
## 161 121 0 no
## 162 121 0 no
## 163 123 0 no
## 164 126 1 yes
## 165 129 1 yes
## 166 130 1 yes
## 167 134 0 no
## 168 135 1 yes
## 169 140 0 no
## 170 145 0 no
## 171 145 0 no
## 172 146 0 no
## 173 146 0 no
## 174 146 0 no
## 175 146 0 no
## 176 146 0 no
## 177 147 0 no
## 178 147 0 no
## 179 147 0 no
## 180 147 0 no
## 181 148 0 no
## 182 150 1 yes
## 183 154 1 yes
## 184 162 1 yes
## 185 170 1 yes
## 186 171 1 yes
## 187 172 1 yes
## 188 172 1 yes
## 189 172 0 no
## 190 174 0 no
## 191 174 0 no
## 192 174 0 no
## 193 175 0 no
## 194 180 0 no
## 195 180 1 yes
## 196 180 1 yes
## 197 185 0 no
## 198 186 0 no
## 199 186 0 no
## 200 186 0 no
## 201 186 0 no
## 202 186 0 no
## 203 186 0 no
## 204 187 0 no
## 205 187 0 no
## 206 187 0 no
## 207 187 0 no
## 208 187 0 no
## 209 187 0 no
## 210 187 0 no
## 211 188 0 no
## 212 192 0 no
## 213 192 0 no
## 214 193 1 yes
## 215 194 0 no
## 216 195 0 no
## 217 196 0 no
## 218 196 1 yes
## 219 197 0 no
## 220 197 0 no
## 221 198 1 yes
## 222 200 0 no
## 223 201 0 no
## 224 201 0 no
## 225 205 0 no
## 226 205 0 no
## 227 205 0 no
## 228 206 0 no
## 229 207 0 no
## 230 207 0 no
## 231 207 1 yes
## 232 208 0 no
## 233 209 0 no
## 234 209 0 no
## 235 209 0 no
## 236 209 0 no
## 237 209 0 no
## 238 210 0 no
## 239 210 0 no
## 240 211 0 no
## 241 212 0 no
## 242 212 0 no
## 243 212 0 no
## 244 213 0 no
## 245 213 0 no
## 246 213 0 no
## 247 214 1 yes
## 248 214 0 no
## 249 214 0 no
## 250 214 0 no
## 251 214 0 no
## 252 215 0 no
## 253 215 0 no
## 254 215 0 no
## 255 215 0 no
## 256 216 0 no
## 257 220 0 no
## 258 230 0 no
## 259 230 0 no
## 260 231 0 no
## 261 233 0 no
## 262 233 0 no
## 263 235 1 yes
## 264 237 0 no
## 265 237 0 no
## 266 240 0 no
## 267 241 1 yes
## 268 244 0 no
## 269 244 0 no
## 270 244 0 no
## 271 244 0 no
## 272 244 0 no
## 273 245 0 no
## 274 245 0 no
## 275 245 0 no
## 276 245 0 no
## 277 245 0 no
## 278 246 0 no
## 279 246 0 no
## 280 246 0 no
## 281 247 0 no
## 282 250 0 no
## 283 250 0 no
## 284 250 0 no
## 285 250 0 no
## 286 250 0 no
## 287 250 0 no
## 288 250 0 no
## 289 256 0 no
## 290 256 0 no
## 291 257 0 no
## 292 258 0 no
## 293 258 0 no
## 294 270 0 no
## 295 270 0 no
## 296 271 0 no
## 297 278 0 no
## 298 280 0 no
## 299 285 0 no
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
ggplot(data = mortality, aes(x = DEATH, y= age, fill = DEATH)) +
geom_boxplot() +
scale_fill_manual(values = c("no" = "purple", "yes" = "pink")) +
labs(title = "Box plot of mortality dataset", y = "Age", x = "Death_Event") +
theme_minimal()
col_names= names(mortality)
for (col in col_names) {
if (col == "DEATH") next
p = ggplot(mortality, aes(x =!!sym("DEATH"), y = !!sym(col), fill = "DEATH")) +
geom_boxplot() +
scale_fill_manual(values = c("no" = "purple", "yes" = "pink")) +
labs(title = "Box plot of Mortality dataset",x = "Death", y = col ) +
theme_minimal()
print(p)
}
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## for all column
col_names= names(mortality)
for (col in col_names) {
if (col == "DEATH") next
p = ggplot(mortality, aes_string(x = "DEATH", y = col, fill = "DEATH")) +
geom_boxplot() +
scale_fill_manual(values = c("no" = "purple", "yes" = "pink")) +
labs(title = "Box plot of Mortality dataset",x = "Death", y = col ) +
theme_minimal()
print(p)
}
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggplot(data = mortality, aes(x = DEATH, y= age, fill = DEATH)) +
geom_violin()+
scale_fill_manual(values = c("no" = "purple", "yes" = "pink")) +
labs(title = "Violin Plot of Mortality dataset", y = "Age", x = "Death") +
theme_minimal()
## for all column
col_names= names(mortality)
for (col in col_names) {
if (col == "DEATH") next
q = ggplot(mortality, aes_string(x = "DEATH", y = col, fill = "DEATH")) +
geom_violin()+
scale_fill_manual(values = c("no" = "purple", "yes" = "pink")) +
labs(title = "Violin Plot of Mortality dataset",x = "Death", y = col ) +
theme_minimal()
print(q)
}
ggplot(data = mortality, aes(x = DEATH, y = age, color = DEATH)) +
geom_point() +
scale_color_manual(values = c("no" = "purple", "yes" = "pink"))+
theme_minimal()
ggplot(data = mortality, aes(x = anaemia, y = age, color = DEATH)) +
geom_point() +
scale_color_manual(values = c("no" = "purple", "yes" = "pink"))+
theme_minimal()
## for all column
col_names= names(mortality)
for (col in col_names) {
if (col == "DEATH") next
r = ggplot(mortality, aes_string(x = col, y = "age", color = "DEATH")) +
geom_point() +
scale_color_manual(values = c("no" = "purple", "yes" = "pink")) +
labs(title = "Scale Point of Mortality dataset",y = "age", x = col ) +
theme_minimal()
print(r)
}
summary(mortality)
## age anaemia creatinine_phosphokinase diabetes
## Min. :40.00 Min. :0.0000 Min. : 23.0 Min. :0.0000
## 1st Qu.:51.00 1st Qu.:0.0000 1st Qu.: 116.5 1st Qu.:0.0000
## Median :60.00 Median :0.0000 Median : 250.0 Median :0.0000
## Mean :60.83 Mean :0.4314 Mean : 581.8 Mean :0.4181
## 3rd Qu.:70.00 3rd Qu.:1.0000 3rd Qu.: 582.0 3rd Qu.:1.0000
## Max. :95.00 Max. :1.0000 Max. :7861.0 Max. :1.0000
## ejection_fraction high_blood_pressure platelets serum_creatinine
## Min. :14.00 Min. :0.0000 Min. : 25100 Min. :0.500
## 1st Qu.:30.00 1st Qu.:0.0000 1st Qu.:212500 1st Qu.:0.900
## Median :38.00 Median :0.0000 Median :262000 Median :1.100
## Mean :38.08 Mean :0.3512 Mean :263358 Mean :1.394
## 3rd Qu.:45.00 3rd Qu.:1.0000 3rd Qu.:303500 3rd Qu.:1.400
## Max. :80.00 Max. :1.0000 Max. :850000 Max. :9.400
## serum_sodium sex smoking time
## Min. :113.0 Min. :0.0000 Min. :0.0000 Min. : 4.0
## 1st Qu.:134.0 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.: 73.0
## Median :137.0 Median :1.0000 Median :0.0000 Median :115.0
## Mean :136.6 Mean :0.6488 Mean :0.3211 Mean :130.3
## 3rd Qu.:140.0 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:203.0
## Max. :148.0 Max. :1.0000 Max. :1.0000 Max. :285.0
## DEATH_EVENT DEATH
## Min. :0.0000 Length:299
## 1st Qu.:0.0000 Class :character
## Median :0.0000 Mode :character
## Mean :0.3211
## 3rd Qu.:1.0000
## Max. :1.0000
ggplot(data = mortality, aes(x = DEATH, fill = DEATH) ) +
geom_bar() +
scale_fill_manual(values = c("no" = "purple", "yes" = "pink")) +
theme_minimal()
ggplot(data = mortality, aes(x = "", fill = DEATH)) +
geom_bar(stat = "count") +
coord_polar(theta = "y") +
scale_fill_manual(values = c("no" = "purple", "yes" = "pink")) +
theme_minimal()
cor_ma = cor(mortality[ ,1:5])
cor_ma
## age anaemia creatinine_phosphokinase
## age 1.00000000 0.08800644 -0.081583900
## anaemia 0.08800644 1.00000000 -0.190741030
## creatinine_phosphokinase -0.08158390 -0.19074103 1.000000000
## diabetes -0.10101239 -0.01272905 -0.009638514
## ejection_fraction 0.06009836 0.03155697 -0.044079554
## diabetes ejection_fraction
## age -0.101012385 0.06009836
## anaemia -0.012729046 0.03155697
## creatinine_phosphokinase -0.009638514 -0.04407955
## diabetes 1.000000000 -0.00485031
## ejection_fraction -0.004850310 1.00000000
library(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.3.3
ggcorrplot(cor_ma)
ggcorrplot(cor_ma, type="lower",colors = c("pink" , "skyblue"))
ggcorrplot(cor_ma, type="upper",colors = c("pink" , "skyblue"))
ggcorrplot(cor_ma, type="lower", lab = TRUE, colors = c("pink" , "skyblue"))
ggcorrplot(cor_ma, type="upper", lab = TRUE, colors = c("pink" , "skyblue"))
## comparing time
ggplot(mortality, aes(x = time, y = age, color = DEATH)) +
geom_line() + theme_minimal()
ggplot(mortality, aes(x = time)) +
geom_histogram(fill = "blue", color="purple", binwidth = 0.80)
## Pairwise Plots
library(GGally)
## Warning: package 'GGally' was built under R version 4.3.3
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
ggpairs(mortality[ , 1:14], aes(color=DEATH))
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## Warning in cor(x, y): the standard deviation is zero
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
mortality_violin = ggplot(data = mortality, aes(x = DEATH, y=age, fill = DEATH)) +
geom_violin()+
labs(title = "Pairwise Plots", y = "age", x = "DEATH") +
theme_minimal()
mortality_violin
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.3
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(mortality_violin)
scatter_mortality = ggplot(data = mortality, aes(x = ejection_fraction , y=age, color = DEATH)) +
geom_point() +
theme_minimal()
ggplotly(scatter_mortality)
library(ggplot2)
mortality_line = ggplot(mortality, aes(x = time, y = age, color = DEATH)) +
geom_line() +
theme_minimal()
ggplotly(mortality_line)