Problemas del corazon
La incursión del análisis de datos en diferentes ámbitos es un tema que cobra mayor fuerza conforme avance la tecnología, y la medicina no es la excepción, muchos estudios e investigaciones tales como epidemas, imagenología médica, pruebas física, fármacos, entre otros se apoya en los datos y permiten reforzar la toma de decisiones, la incorporación de técnicas como machine learning permiten generar alertas tempranas y predictivas para los pacientes, es por esto que en el caso particular de la cardiología se busca con datos históricos predecir de alguna manera si un nuevo paciente pueda o no presentar un problema cardiaco.
Este conjunto de datos contiene 76 variables, pero todos los experimentos publicados utilizan solamente 14 de ellas, en particular, el conjunto de datos de Cleveland es el único que es empleado por los investigadores de machine learning, el campo target se refiere a la presencia o no de una enfermedad del corazón en el paciente.
La siguiente tabla muestra un resumen del conjunto de datos con las variables y el detalle de las mismas:
| variable | detalle |
|---|---|
| age | age in years |
| sex | sex (1=male;0=female) |
| cp | chest pain type (1=typical angina;2=atypical angina;3=non anginal pain;4=asymptomatic) |
| trestbps | resting blood pressure (in mm Hg on admission to the hospital) |
| chol | serum cholestoral in mg/dl |
| fbs | (fasting blood sugar > 120 mg/dl) (1 = true; 0 = false) |
| restecg | resting electrocardiographic results (0=normal;1:having ST-T wave abnormality;2:showing ventricular hypertrophy |
| thalach | maximum heart rate achieved |
| exang | exercise induced angina (1 = yes; 0 = no) |
| oldpeak | ST depression induced by exercise relative to rest |
| slope | the slope of the peak exercise ST segment(1=unsloping;2=flat;3=downsloping) |
| ca | number of major vessels (0-3) colored by flourosopy |
| thal | 3=normal;6=fixed defect;7=reversable defect |
| target | 0:non disease; 1:disease |
Los siguientes links muestran un detalle de los datos y de otros aspectos relacionados, el primero responde a la plataforma kagle y el segundo a la fuente madre:
| ï..age | sex | cp | trestbps | chol | fbs | restecg | thalach | exang | oldpeak | slope | ca | thal | target |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 63 | 1 | 3 | 145 | 233 | 1 | 0 | 150 | 0 | 2.3 | 0 | 0 | 1 | 1 |
| 37 | 1 | 2 | 130 | 250 | 0 | 1 | 187 | 0 | 3.5 | 0 | 0 | 2 | 1 |
| 41 | 0 | 1 | 130 | 204 | 0 | 0 | 172 | 0 | 1.4 | 2 | 0 | 2 | 1 |
| 56 | 1 | 1 | 120 | 236 | 0 | 1 | 178 | 0 | 0.8 | 2 | 0 | 2 | 1 |
| 57 | 0 | 0 | 120 | 354 | 0 | 1 | 163 | 1 | 0.6 | 2 | 0 | 2 | 1 |
| 57 | 1 | 0 | 140 | 192 | 0 | 1 | 148 | 0 | 0.4 | 1 | 0 | 1 | 1 |
El conjunto de datos contiene 14 variables y un total de n=303 observaciones.
El conjunto de datos contiene variables que por su naturaleza deben pertenecer a otro tipo, por ejemplo variables que se reflejan de tipo cuantitativo que realmente corresponden al tipo cualitativo, esto se refleja en el resumen general del dataset:
str(datos)
## 'data.frame': 303 obs. of 14 variables:
## $ ï..age : int 63 37 41 56 57 57 56 44 52 57 ...
## $ sex : int 1 1 0 1 0 1 0 1 1 1 ...
## $ cp : int 3 2 1 1 0 0 1 1 2 2 ...
## $ trestbps: int 145 130 130 120 120 140 140 120 172 150 ...
## $ chol : int 233 250 204 236 354 192 294 263 199 168 ...
## $ fbs : int 1 0 0 0 0 0 0 0 1 0 ...
## $ restecg : int 0 1 0 1 1 1 0 1 1 1 ...
## $ thalach : int 150 187 172 178 163 148 153 173 162 174 ...
## $ exang : int 0 0 0 0 1 0 0 0 0 0 ...
## $ oldpeak : num 2.3 3.5 1.4 0.8 0.6 0.4 1.3 0 0.5 1.6 ...
## $ slope : int 0 0 2 2 2 1 1 2 2 2 ...
## $ ca : int 0 0 0 0 0 0 0 0 0 0 ...
## $ thal : int 1 2 2 2 2 1 2 3 3 2 ...
## $ target : int 1 1 1 1 1 1 1 1 1 1 ...
Variables como sex, cp, fbs, restecg, exang, slope, thal y target a pesar de estar codificadas con un número no implican que su naturaleza es de tipo cuantitativa, es por esto que podemos realizar el ajuste y transformar las variables a tipo character o factor, como sigue:
library(dbplyr)
datos$sex<-as.factor(datos$sex)
datos$cp<-as.factor(datos$cp)
datos$fbs<-as.factor(datos$fbs)
datos$restecg<-as.factor(datos$restecg)
datos$exang<-as.factor(datos$exang)
datos$slope<-as.factor(datos$slope)
datos$target<-as.factor(datos$target)
dplyr::glimpse(datos)
## Rows: 303
## Columns: 14
## $ ï..age <int> 63, 37, 41, 56, 57, 57, 56, 44, 52, 57, 54, 48, 49, 64, 58...
## $ sex <fct> 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0...
## $ cp <fct> 3, 2, 1, 1, 0, 0, 1, 1, 2, 2, 0, 2, 1, 3, 3, 2, 2, 3, 0, 3...
## $ trestbps <int> 145, 130, 130, 120, 120, 140, 140, 120, 172, 150, 140, 130...
## $ chol <int> 233, 250, 204, 236, 354, 192, 294, 263, 199, 168, 239, 275...
## $ fbs <fct> 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0...
## $ restecg <fct> 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1...
## $ thalach <int> 150, 187, 172, 178, 163, 148, 153, 173, 162, 174, 160, 139...
## $ exang <fct> 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0...
## $ oldpeak <dbl> 2.3, 3.5, 1.4, 0.8, 0.6, 0.4, 1.3, 0.0, 0.5, 1.6, 1.2, 0.2...
## $ slope <fct> 0, 0, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 0, 2, 2...
## $ ca <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2...
## $ thal <int> 1, 2, 2, 2, 2, 1, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2...
## $ target <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
El análisis va a consistir de tres etapas:
autocorrelacion.