La base de datos fue construida a traves de una muestra aleatoria, que toma las historias clĆnicas remitidas a un centro cĆ”rdiaco por distintos medicos, despues de haber tomado las pruebas de laboratorio que analizan los diferentes niveles de calcio, fósforo y fosfatasa alcalina de pacientes mayores de 65 aƱos. Se tomaron en cuenta 3 distintas variables cualitativas como: el sexo (Sex), el laboratorio de donde fue extraida la muestra (Lab), Los rangos de edades mayores a 65 hasta 89 (AgeG); y 4 Distintas variables cuantitativas como: la edad (Age), el nivel de Calcio (CaMol), el nivel Fosforo (PhoMol) y el nivel Fosfatasa Alcalina (ALP).
Los datos que arrogo la muestra extraida de esta población recopila la información de 178 pacientes, entre los que se encuentran 92 hombres y 86 mujeres mayores de 65 años.
Al iniciar un proyecto nuevo en R, siempre es importante saber donde vamos a trabajar, por lo que establecemos la dirección de la carpeta y usamos setwd() para cambiarlo.
#1. Directorio de trabajo
wd="F:/Taller General 1"
setwd(wd)
Una de las cosas mƔs importantes al momento de crear un scrip en R, es saber Para que sirven y con cuales librerias vamos a trabajar.Como vamos a hacer uso de un grupo grande de librerias, las vamos a recopilar todas en una variable llamada lib_req. Por lo que cargaremos la libreria paletteer, la cual sera util para asignarla paleta de colores de las grƔficas, y easypackages nos permitirƔ cargar las demas librerias con la funcion packages
#2. Librerias
library(paletteer) #Libreria para paletas de colores
library(easypackages) #Libreria para cargar autometicamente otras librerias
lib_req<-c("lubridate","dplyr","readxl","visdat","missMDA","mice","DMwR2","editrules", "corrplot")# Listado de librerias requeridas por el script
easypackages::packages(lib_req) # Se Verifica la instalación y se carga las librerias
color_a=paletteer_d("ggthemes::excel_Aspect")
color_s=paletteer_d("ggsci::alternating_igv")
color_l=paletteer_d("ggthemes::Classic_10")
Para traer el documento a R hay distintas formas, nosotros usamos la libreria readxl, junto con la función read_xls para cargar la base de datos llamada calcium.
#3. Lectura de Datos (punto 1)
calcium <- read_xls("calcium.xls",col_names = TRUE,na = "N/A")
rownames(calcium)<-calcium$Observacion #la variable observacion es el nombre de cada reistro
calcium <- select(calcium, c(2:8)) # seleccionamos las variables restantes
names(calcium)
## [1] "Age" "Sex" "ALP" "Lab" "CaMol" "PhoMol" "AgeG"
dim(calcium)
## [1] 178 7
str(calcium)
## tibble [178 x 7] (S3: tbl_df/tbl/data.frame)
## $ Age : chr [1:178] "78" "72" "72" "NA" ...
## $ Sex : chr [1:178] "2" "2" "2" "2" ...
## $ ALP : chr [1:178] "83" "117" "132" "102" ...
## $ Lab : chr [1:178] "4" "4" "4" "4" ...
## $ CaMol : chr [1:178] "2.5299999999999998" "2.5" "2.4300000000000002" "2.48" ...
## $ PhoMol: chr [1:178] "1.0700000000000001" "1.1599999999999999" "1.1299999999999999" "0.81000000000000005" ...
## $ AgeG : chr [1:178] "75 - 79" "70 - 74" "70 - 74" "70 - 74" ...
summary(calcium)
## Age Sex ALP Lab
## Length:178 Length:178 Length:178 Length:178
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
## CaMol PhoMol AgeG
## Length:178 Length:178 Length:178
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
A partir de ahora, veremos los valores que tiene las variables que en la investigación se definieron como tipo categoricas, como lo son Sex, Lab, y AgeG.
# Observando las etiquetas en algunas de las variables tipo Factor
table(calcium$Sex)
##
## 1 12 2 21 22 f F m M
## 87 1 83 1 1 1 1 1 2
table(calcium$Lab)
##
## 1 2 21 3 4 43 5 6 NA
## 88 41 1 16 13 1 11 6 1
table(calcium$AgeG)
##
## 65 - 69 70 - 74 75 - 79 80 - 84 85-89 85 - 89 NA
## 55 70 38 9 1 4 1
Dada la anterior información, debemos adecuar las variables, según los factores establecidos por los investigadores.A las variables cualitativas se le asignaron los siguientes valores
# Declaración de niveles correctos para las variables tipo Factor
level_sex <- c("1"="Male", "2"="Female", "12"="Female", "21"="Male","22"="Female","f"="Female","F"="Female","m"="Male","M"="Male")
level_lab <- c("1"="Metpath","2"="Deyor","3"="St. Elizabeth's","4"="CB Rouche", "5"="YOH", "6" = "Horizon", "21"="Deyor","43"="CB Rouche")
level_ageg <- c("85-89"="85 - 89")
Luego, asignamos a cada variable la categoria que le corresponde, y a las variables tipo factor, se le asignan los niveles que deben tener.
## Modificación del formato y transformación de variables
calcium$Lab=as.numeric(calcium$Lab) #La variable lab se convierte primero a numerica por el dato faltante
calcium <- transform(calcium,
Sex=factor(dplyr::recode(Sex, !!!level_sex)),
Lab=factor(dplyr::recode(Lab, !!!level_lab)), #Despues lo volvemos tipo factor
AgeG=factor(dplyr::recode(AgeG, !!!level_ageg))
)
calcium$Age=as.numeric(calcium$Age)
calcium$ALP=as.numeric(calcium$ALP)
calcium$CaMol=as.numeric(calcium$CaMol)
calcium$PhoMol=as.numeric(calcium$PhoMol)
Como no sabemos que clase de errores o inconsistencia pueda presentar esta base de datos, tenemos que desarrollar el archivo consistencia.txt, el cual contiene 13 reglas de consistencia de datos que se sacaron según lo establecido en la investigación.
#4. Consistencia de datos (punto 2)
# Verificamos la consistencia de los datos
Rules <- editrules::editfile("consistencia.txt")
windows()
plot(Rules)
# Verificación de las reglas sobres los datos
editrules::violatedEdits(Rules, calcium)
## edit
## record num1 num2 num3 num4 num5 num6 num7 num8 dat11 mix9 mix10 mix11
## 1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 2 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 3 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 4 NA NA FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 5 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 6 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 7 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 8 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 9 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 10 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 11 FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 12 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 13 FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 14 NA NA FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 15 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 16 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 17 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 18 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 19 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 20 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 21 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 22 FALSE FALSE FALSE FALSE FALSE FALSE NA NA FALSE FALSE FALSE FALSE
## 23 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 24 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 25 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 26 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 27 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 28 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 29 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 30 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 31 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 32 FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 33 FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 34 FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 35 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 36 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 37 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 38 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 39 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 40 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 41 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 42 FALSE FALSE FALSE FALSE NA NA FALSE FALSE FALSE FALSE FALSE FALSE
## 43 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 44 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 45 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 46 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 47 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 48 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 49 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 50 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 51 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 52 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 53 FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 54 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 55 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 56 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 57 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 58 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 59 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 60 FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
## 61 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 62 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 63 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 64 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 65 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 66 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 67 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 68 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 69 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 70 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 71 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 72 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 73 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 74 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 75 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 76 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 77 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 78 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 79 FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE
## 80 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 81 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 82 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 83 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 84 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 85 FALSE FALSE NA NA FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 86 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 87 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 88 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 89 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 90 FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 91 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 92 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 93 FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 94 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 95 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 96 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 97 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 98 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 99 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 100 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 101 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 102 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 103 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 104 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 105 NA NA FALSE FALSE FALSE FALSE FALSE TRUE FALSE NA NA NA
## 106 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 107 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 108 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 109 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 110 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 111 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 112 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 113 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 114 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 115 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 116 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 117 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 118 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 119 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 120 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 121 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 122 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 123 FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 124 FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 125 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 126 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 127 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 128 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 129 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 130 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 131 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 132 FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 133 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 134 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 135 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 136 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 137 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 138 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 139 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 140 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 141 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 142 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 143 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 144 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 145 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 146 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 147 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 148 FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 149 FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 150 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 151 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 152 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 153 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 154 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 155 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 156 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 157 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 158 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 159 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 160 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 161 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 162 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 163 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 164 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 165 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 166 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 167 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 168 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 169 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 170 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 171 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 172 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 173 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 174 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## 175 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 176 FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 177 FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 178 FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## edit
## record mix12 mix13
## 1 FALSE FALSE
## 2 FALSE FALSE
## 3 FALSE FALSE
## 4 FALSE FALSE
## 5 FALSE FALSE
## 6 FALSE FALSE
## 7 FALSE FALSE
## 8 FALSE FALSE
## 9 FALSE FALSE
## 10 FALSE FALSE
## 11 FALSE FALSE
## 12 FALSE FALSE
## 13 FALSE FALSE
## 14 FALSE FALSE
## 15 FALSE FALSE
## 16 FALSE FALSE
## 17 FALSE FALSE
## 18 FALSE FALSE
## 19 FALSE FALSE
## 20 FALSE FALSE
## 21 FALSE FALSE
## 22 FALSE FALSE
## 23 FALSE FALSE
## 24 FALSE FALSE
## 25 FALSE FALSE
## 26 FALSE FALSE
## 27 FALSE FALSE
## 28 FALSE FALSE
## 29 FALSE FALSE
## 30 FALSE FALSE
## 31 FALSE FALSE
## 32 FALSE FALSE
## 33 FALSE FALSE
## 34 FALSE FALSE
## 35 FALSE FALSE
## 36 FALSE FALSE
## 37 FALSE FALSE
## 38 FALSE FALSE
## 39 FALSE FALSE
## 40 FALSE FALSE
## 41 FALSE FALSE
## 42 FALSE FALSE
## 43 FALSE FALSE
## 44 FALSE FALSE
## 45 FALSE FALSE
## 46 FALSE FALSE
## 47 FALSE FALSE
## 48 FALSE FALSE
## 49 FALSE FALSE
## 50 FALSE FALSE
## 51 FALSE FALSE
## 52 FALSE FALSE
## 53 FALSE FALSE
## 54 FALSE FALSE
## 55 FALSE FALSE
## 56 FALSE FALSE
## 57 FALSE FALSE
## 58 FALSE FALSE
## 59 FALSE FALSE
## 60 FALSE FALSE
## 61 FALSE FALSE
## 62 FALSE FALSE
## 63 FALSE FALSE
## 64 FALSE FALSE
## 65 FALSE FALSE
## 66 FALSE FALSE
## 67 FALSE FALSE
## 68 FALSE FALSE
## 69 FALSE FALSE
## 70 FALSE FALSE
## 71 FALSE FALSE
## 72 FALSE FALSE
## 73 FALSE FALSE
## 74 FALSE FALSE
## 75 FALSE FALSE
## 76 FALSE FALSE
## 77 FALSE FALSE
## 78 FALSE FALSE
## 79 FALSE FALSE
## 80 FALSE FALSE
## 81 FALSE FALSE
## 82 FALSE FALSE
## 83 FALSE FALSE
## 84 FALSE FALSE
## 85 FALSE FALSE
## 86 FALSE FALSE
## 87 FALSE FALSE
## 88 FALSE FALSE
## 89 FALSE FALSE
## 90 FALSE FALSE
## 91 FALSE FALSE
## 92 FALSE FALSE
## 93 FALSE FALSE
## 94 FALSE FALSE
## 95 FALSE FALSE
## 96 FALSE FALSE
## 97 FALSE FALSE
## 98 FALSE FALSE
## 99 FALSE FALSE
## 100 FALSE FALSE
## 101 FALSE FALSE
## 102 FALSE FALSE
## 103 FALSE FALSE
## 104 FALSE FALSE
## 105 NA NA
## 106 FALSE FALSE
## 107 FALSE FALSE
## 108 FALSE FALSE
## 109 FALSE FALSE
## 110 FALSE FALSE
## 111 FALSE FALSE
## 112 FALSE FALSE
## 113 FALSE FALSE
## 114 FALSE FALSE
## 115 FALSE FALSE
## 116 FALSE FALSE
## 117 FALSE FALSE
## 118 FALSE FALSE
## 119 FALSE FALSE
## 120 FALSE FALSE
## 121 FALSE FALSE
## 122 FALSE FALSE
## 123 FALSE FALSE
## 124 FALSE FALSE
## 125 FALSE FALSE
## 126 FALSE FALSE
## 127 FALSE FALSE
## 128 FALSE FALSE
## 129 FALSE FALSE
## 130 FALSE FALSE
## 131 FALSE FALSE
## 132 FALSE FALSE
## 133 FALSE FALSE
## 134 FALSE FALSE
## 135 FALSE FALSE
## 136 FALSE FALSE
## 137 FALSE FALSE
## 138 FALSE FALSE
## 139 FALSE FALSE
## 140 FALSE FALSE
## 141 FALSE FALSE
## 142 FALSE FALSE
## 143 FALSE FALSE
## 144 FALSE FALSE
## 145 FALSE FALSE
## 146 FALSE FALSE
## 147 FALSE FALSE
## 148 FALSE FALSE
## 149 FALSE FALSE
## 150 FALSE FALSE
## 151 FALSE FALSE
## 152 FALSE FALSE
## 153 FALSE FALSE
## 154 FALSE FALSE
## 155 FALSE FALSE
## 156 FALSE FALSE
## 157 FALSE FALSE
## 158 FALSE FALSE
## 159 FALSE FALSE
## 160 FALSE FALSE
## 161 FALSE FALSE
## 162 FALSE FALSE
## 163 FALSE FALSE
## 164 FALSE FALSE
## 165 FALSE FALSE
## 166 FALSE FALSE
## 167 FALSE FALSE
## 168 FALSE FALSE
## 169 FALSE FALSE
## 170 FALSE FALSE
## 171 FALSE FALSE
## 172 FALSE FALSE
## 173 FALSE FALSE
## 174 FALSE FALSE
## 175 FALSE FALSE
## 176 FALSE FALSE
## 177 FALSE FALSE
## 178 FALSE FALSE
Valid_calcium = editrules::violatedEdits(Rules, calcium)
summary(Valid_calcium) #cuantificar donde se cometen los errores
## Edit violations, 178 observations, 0 completely missing (0%):
##
## editname freq rel
## num8 34 19.1%
## num4 20 11.2%
## num5 7 3.9%
## num6 6 3.4%
## num2 3 1.7%
## num3 2 1.1%
## num7 1 0.6%
## dat11 1 0.6%
##
## Edit violations per record:
##
## errors freq rel
## 0 107 60.1%
## 1 58 32.6%
## 2 11 6.2%
## 3 1 0.6%
## 8 1 0.6%
# Visualización del diagnóstico
windows()
plot(Valid_calcium) #reporte de resultados
matrix(data=1:2492, 178, 14)
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
## [1,] 1 179 357 535 713 891 1069 1247 1425 1603 1781 1959 2137
## [2,] 2 180 358 536 714 892 1070 1248 1426 1604 1782 1960 2138
## [3,] 3 181 359 537 715 893 1071 1249 1427 1605 1783 1961 2139
## [4,] 4 182 360 538 716 894 1072 1250 1428 1606 1784 1962 2140
## [5,] 5 183 361 539 717 895 1073 1251 1429 1607 1785 1963 2141
## [6,] 6 184 362 540 718 896 1074 1252 1430 1608 1786 1964 2142
## [7,] 7 185 363 541 719 897 1075 1253 1431 1609 1787 1965 2143
## [8,] 8 186 364 542 720 898 1076 1254 1432 1610 1788 1966 2144
## [9,] 9 187 365 543 721 899 1077 1255 1433 1611 1789 1967 2145
## [10,] 10 188 366 544 722 900 1078 1256 1434 1612 1790 1968 2146
## [11,] 11 189 367 545 723 901 1079 1257 1435 1613 1791 1969 2147
## [12,] 12 190 368 546 724 902 1080 1258 1436 1614 1792 1970 2148
## [13,] 13 191 369 547 725 903 1081 1259 1437 1615 1793 1971 2149
## [14,] 14 192 370 548 726 904 1082 1260 1438 1616 1794 1972 2150
## [15,] 15 193 371 549 727 905 1083 1261 1439 1617 1795 1973 2151
## [16,] 16 194 372 550 728 906 1084 1262 1440 1618 1796 1974 2152
## [17,] 17 195 373 551 729 907 1085 1263 1441 1619 1797 1975 2153
## [18,] 18 196 374 552 730 908 1086 1264 1442 1620 1798 1976 2154
## [19,] 19 197 375 553 731 909 1087 1265 1443 1621 1799 1977 2155
## [20,] 20 198 376 554 732 910 1088 1266 1444 1622 1800 1978 2156
## [21,] 21 199 377 555 733 911 1089 1267 1445 1623 1801 1979 2157
## [22,] 22 200 378 556 734 912 1090 1268 1446 1624 1802 1980 2158
## [23,] 23 201 379 557 735 913 1091 1269 1447 1625 1803 1981 2159
## [24,] 24 202 380 558 736 914 1092 1270 1448 1626 1804 1982 2160
## [25,] 25 203 381 559 737 915 1093 1271 1449 1627 1805 1983 2161
## [26,] 26 204 382 560 738 916 1094 1272 1450 1628 1806 1984 2162
## [27,] 27 205 383 561 739 917 1095 1273 1451 1629 1807 1985 2163
## [28,] 28 206 384 562 740 918 1096 1274 1452 1630 1808 1986 2164
## [29,] 29 207 385 563 741 919 1097 1275 1453 1631 1809 1987 2165
## [30,] 30 208 386 564 742 920 1098 1276 1454 1632 1810 1988 2166
## [31,] 31 209 387 565 743 921 1099 1277 1455 1633 1811 1989 2167
## [32,] 32 210 388 566 744 922 1100 1278 1456 1634 1812 1990 2168
## [33,] 33 211 389 567 745 923 1101 1279 1457 1635 1813 1991 2169
## [34,] 34 212 390 568 746 924 1102 1280 1458 1636 1814 1992 2170
## [35,] 35 213 391 569 747 925 1103 1281 1459 1637 1815 1993 2171
## [36,] 36 214 392 570 748 926 1104 1282 1460 1638 1816 1994 2172
## [37,] 37 215 393 571 749 927 1105 1283 1461 1639 1817 1995 2173
## [38,] 38 216 394 572 750 928 1106 1284 1462 1640 1818 1996 2174
## [39,] 39 217 395 573 751 929 1107 1285 1463 1641 1819 1997 2175
## [40,] 40 218 396 574 752 930 1108 1286 1464 1642 1820 1998 2176
## [41,] 41 219 397 575 753 931 1109 1287 1465 1643 1821 1999 2177
## [42,] 42 220 398 576 754 932 1110 1288 1466 1644 1822 2000 2178
## [43,] 43 221 399 577 755 933 1111 1289 1467 1645 1823 2001 2179
## [44,] 44 222 400 578 756 934 1112 1290 1468 1646 1824 2002 2180
## [45,] 45 223 401 579 757 935 1113 1291 1469 1647 1825 2003 2181
## [46,] 46 224 402 580 758 936 1114 1292 1470 1648 1826 2004 2182
## [47,] 47 225 403 581 759 937 1115 1293 1471 1649 1827 2005 2183
## [48,] 48 226 404 582 760 938 1116 1294 1472 1650 1828 2006 2184
## [49,] 49 227 405 583 761 939 1117 1295 1473 1651 1829 2007 2185
## [50,] 50 228 406 584 762 940 1118 1296 1474 1652 1830 2008 2186
## [51,] 51 229 407 585 763 941 1119 1297 1475 1653 1831 2009 2187
## [52,] 52 230 408 586 764 942 1120 1298 1476 1654 1832 2010 2188
## [53,] 53 231 409 587 765 943 1121 1299 1477 1655 1833 2011 2189
## [54,] 54 232 410 588 766 944 1122 1300 1478 1656 1834 2012 2190
## [55,] 55 233 411 589 767 945 1123 1301 1479 1657 1835 2013 2191
## [56,] 56 234 412 590 768 946 1124 1302 1480 1658 1836 2014 2192
## [57,] 57 235 413 591 769 947 1125 1303 1481 1659 1837 2015 2193
## [58,] 58 236 414 592 770 948 1126 1304 1482 1660 1838 2016 2194
## [59,] 59 237 415 593 771 949 1127 1305 1483 1661 1839 2017 2195
## [60,] 60 238 416 594 772 950 1128 1306 1484 1662 1840 2018 2196
## [61,] 61 239 417 595 773 951 1129 1307 1485 1663 1841 2019 2197
## [62,] 62 240 418 596 774 952 1130 1308 1486 1664 1842 2020 2198
## [63,] 63 241 419 597 775 953 1131 1309 1487 1665 1843 2021 2199
## [64,] 64 242 420 598 776 954 1132 1310 1488 1666 1844 2022 2200
## [65,] 65 243 421 599 777 955 1133 1311 1489 1667 1845 2023 2201
## [66,] 66 244 422 600 778 956 1134 1312 1490 1668 1846 2024 2202
## [67,] 67 245 423 601 779 957 1135 1313 1491 1669 1847 2025 2203
## [68,] 68 246 424 602 780 958 1136 1314 1492 1670 1848 2026 2204
## [69,] 69 247 425 603 781 959 1137 1315 1493 1671 1849 2027 2205
## [70,] 70 248 426 604 782 960 1138 1316 1494 1672 1850 2028 2206
## [71,] 71 249 427 605 783 961 1139 1317 1495 1673 1851 2029 2207
## [72,] 72 250 428 606 784 962 1140 1318 1496 1674 1852 2030 2208
## [73,] 73 251 429 607 785 963 1141 1319 1497 1675 1853 2031 2209
## [74,] 74 252 430 608 786 964 1142 1320 1498 1676 1854 2032 2210
## [75,] 75 253 431 609 787 965 1143 1321 1499 1677 1855 2033 2211
## [76,] 76 254 432 610 788 966 1144 1322 1500 1678 1856 2034 2212
## [77,] 77 255 433 611 789 967 1145 1323 1501 1679 1857 2035 2213
## [78,] 78 256 434 612 790 968 1146 1324 1502 1680 1858 2036 2214
## [79,] 79 257 435 613 791 969 1147 1325 1503 1681 1859 2037 2215
## [80,] 80 258 436 614 792 970 1148 1326 1504 1682 1860 2038 2216
## [81,] 81 259 437 615 793 971 1149 1327 1505 1683 1861 2039 2217
## [82,] 82 260 438 616 794 972 1150 1328 1506 1684 1862 2040 2218
## [83,] 83 261 439 617 795 973 1151 1329 1507 1685 1863 2041 2219
## [84,] 84 262 440 618 796 974 1152 1330 1508 1686 1864 2042 2220
## [85,] 85 263 441 619 797 975 1153 1331 1509 1687 1865 2043 2221
## [86,] 86 264 442 620 798 976 1154 1332 1510 1688 1866 2044 2222
## [87,] 87 265 443 621 799 977 1155 1333 1511 1689 1867 2045 2223
## [88,] 88 266 444 622 800 978 1156 1334 1512 1690 1868 2046 2224
## [89,] 89 267 445 623 801 979 1157 1335 1513 1691 1869 2047 2225
## [90,] 90 268 446 624 802 980 1158 1336 1514 1692 1870 2048 2226
## [91,] 91 269 447 625 803 981 1159 1337 1515 1693 1871 2049 2227
## [92,] 92 270 448 626 804 982 1160 1338 1516 1694 1872 2050 2228
## [93,] 93 271 449 627 805 983 1161 1339 1517 1695 1873 2051 2229
## [94,] 94 272 450 628 806 984 1162 1340 1518 1696 1874 2052 2230
## [95,] 95 273 451 629 807 985 1163 1341 1519 1697 1875 2053 2231
## [96,] 96 274 452 630 808 986 1164 1342 1520 1698 1876 2054 2232
## [97,] 97 275 453 631 809 987 1165 1343 1521 1699 1877 2055 2233
## [98,] 98 276 454 632 810 988 1166 1344 1522 1700 1878 2056 2234
## [99,] 99 277 455 633 811 989 1167 1345 1523 1701 1879 2057 2235
## [100,] 100 278 456 634 812 990 1168 1346 1524 1702 1880 2058 2236
## [101,] 101 279 457 635 813 991 1169 1347 1525 1703 1881 2059 2237
## [102,] 102 280 458 636 814 992 1170 1348 1526 1704 1882 2060 2238
## [103,] 103 281 459 637 815 993 1171 1349 1527 1705 1883 2061 2239
## [104,] 104 282 460 638 816 994 1172 1350 1528 1706 1884 2062 2240
## [105,] 105 283 461 639 817 995 1173 1351 1529 1707 1885 2063 2241
## [106,] 106 284 462 640 818 996 1174 1352 1530 1708 1886 2064 2242
## [107,] 107 285 463 641 819 997 1175 1353 1531 1709 1887 2065 2243
## [108,] 108 286 464 642 820 998 1176 1354 1532 1710 1888 2066 2244
## [109,] 109 287 465 643 821 999 1177 1355 1533 1711 1889 2067 2245
## [110,] 110 288 466 644 822 1000 1178 1356 1534 1712 1890 2068 2246
## [111,] 111 289 467 645 823 1001 1179 1357 1535 1713 1891 2069 2247
## [112,] 112 290 468 646 824 1002 1180 1358 1536 1714 1892 2070 2248
## [113,] 113 291 469 647 825 1003 1181 1359 1537 1715 1893 2071 2249
## [114,] 114 292 470 648 826 1004 1182 1360 1538 1716 1894 2072 2250
## [115,] 115 293 471 649 827 1005 1183 1361 1539 1717 1895 2073 2251
## [116,] 116 294 472 650 828 1006 1184 1362 1540 1718 1896 2074 2252
## [117,] 117 295 473 651 829 1007 1185 1363 1541 1719 1897 2075 2253
## [118,] 118 296 474 652 830 1008 1186 1364 1542 1720 1898 2076 2254
## [119,] 119 297 475 653 831 1009 1187 1365 1543 1721 1899 2077 2255
## [120,] 120 298 476 654 832 1010 1188 1366 1544 1722 1900 2078 2256
## [121,] 121 299 477 655 833 1011 1189 1367 1545 1723 1901 2079 2257
## [122,] 122 300 478 656 834 1012 1190 1368 1546 1724 1902 2080 2258
## [123,] 123 301 479 657 835 1013 1191 1369 1547 1725 1903 2081 2259
## [124,] 124 302 480 658 836 1014 1192 1370 1548 1726 1904 2082 2260
## [125,] 125 303 481 659 837 1015 1193 1371 1549 1727 1905 2083 2261
## [126,] 126 304 482 660 838 1016 1194 1372 1550 1728 1906 2084 2262
## [127,] 127 305 483 661 839 1017 1195 1373 1551 1729 1907 2085 2263
## [128,] 128 306 484 662 840 1018 1196 1374 1552 1730 1908 2086 2264
## [129,] 129 307 485 663 841 1019 1197 1375 1553 1731 1909 2087 2265
## [130,] 130 308 486 664 842 1020 1198 1376 1554 1732 1910 2088 2266
## [131,] 131 309 487 665 843 1021 1199 1377 1555 1733 1911 2089 2267
## [132,] 132 310 488 666 844 1022 1200 1378 1556 1734 1912 2090 2268
## [133,] 133 311 489 667 845 1023 1201 1379 1557 1735 1913 2091 2269
## [134,] 134 312 490 668 846 1024 1202 1380 1558 1736 1914 2092 2270
## [135,] 135 313 491 669 847 1025 1203 1381 1559 1737 1915 2093 2271
## [136,] 136 314 492 670 848 1026 1204 1382 1560 1738 1916 2094 2272
## [137,] 137 315 493 671 849 1027 1205 1383 1561 1739 1917 2095 2273
## [138,] 138 316 494 672 850 1028 1206 1384 1562 1740 1918 2096 2274
## [139,] 139 317 495 673 851 1029 1207 1385 1563 1741 1919 2097 2275
## [140,] 140 318 496 674 852 1030 1208 1386 1564 1742 1920 2098 2276
## [141,] 141 319 497 675 853 1031 1209 1387 1565 1743 1921 2099 2277
## [142,] 142 320 498 676 854 1032 1210 1388 1566 1744 1922 2100 2278
## [143,] 143 321 499 677 855 1033 1211 1389 1567 1745 1923 2101 2279
## [144,] 144 322 500 678 856 1034 1212 1390 1568 1746 1924 2102 2280
## [145,] 145 323 501 679 857 1035 1213 1391 1569 1747 1925 2103 2281
## [146,] 146 324 502 680 858 1036 1214 1392 1570 1748 1926 2104 2282
## [147,] 147 325 503 681 859 1037 1215 1393 1571 1749 1927 2105 2283
## [148,] 148 326 504 682 860 1038 1216 1394 1572 1750 1928 2106 2284
## [149,] 149 327 505 683 861 1039 1217 1395 1573 1751 1929 2107 2285
## [150,] 150 328 506 684 862 1040 1218 1396 1574 1752 1930 2108 2286
## [151,] 151 329 507 685 863 1041 1219 1397 1575 1753 1931 2109 2287
## [152,] 152 330 508 686 864 1042 1220 1398 1576 1754 1932 2110 2288
## [153,] 153 331 509 687 865 1043 1221 1399 1577 1755 1933 2111 2289
## [154,] 154 332 510 688 866 1044 1222 1400 1578 1756 1934 2112 2290
## [155,] 155 333 511 689 867 1045 1223 1401 1579 1757 1935 2113 2291
## [156,] 156 334 512 690 868 1046 1224 1402 1580 1758 1936 2114 2292
## [157,] 157 335 513 691 869 1047 1225 1403 1581 1759 1937 2115 2293
## [158,] 158 336 514 692 870 1048 1226 1404 1582 1760 1938 2116 2294
## [159,] 159 337 515 693 871 1049 1227 1405 1583 1761 1939 2117 2295
## [160,] 160 338 516 694 872 1050 1228 1406 1584 1762 1940 2118 2296
## [161,] 161 339 517 695 873 1051 1229 1407 1585 1763 1941 2119 2297
## [162,] 162 340 518 696 874 1052 1230 1408 1586 1764 1942 2120 2298
## [163,] 163 341 519 697 875 1053 1231 1409 1587 1765 1943 2121 2299
## [164,] 164 342 520 698 876 1054 1232 1410 1588 1766 1944 2122 2300
## [165,] 165 343 521 699 877 1055 1233 1411 1589 1767 1945 2123 2301
## [166,] 166 344 522 700 878 1056 1234 1412 1590 1768 1946 2124 2302
## [167,] 167 345 523 701 879 1057 1235 1413 1591 1769 1947 2125 2303
## [168,] 168 346 524 702 880 1058 1236 1414 1592 1770 1948 2126 2304
## [169,] 169 347 525 703 881 1059 1237 1415 1593 1771 1949 2127 2305
## [170,] 170 348 526 704 882 1060 1238 1416 1594 1772 1950 2128 2306
## [171,] 171 349 527 705 883 1061 1239 1417 1595 1773 1951 2129 2307
## [172,] 172 350 528 706 884 1062 1240 1418 1596 1774 1952 2130 2308
## [173,] 173 351 529 707 885 1063 1241 1419 1597 1775 1953 2131 2309
## [174,] 174 352 530 708 886 1064 1242 1420 1598 1776 1954 2132 2310
## [175,] 175 353 531 709 887 1065 1243 1421 1599 1777 1955 2133 2311
## [176,] 176 354 532 710 888 1066 1244 1422 1600 1778 1956 2134 2312
## [177,] 177 355 533 711 889 1067 1245 1423 1601 1779 1957 2135 2313
## [178,] 178 356 534 712 890 1068 1246 1424 1602 1780 1958 2136 2314
## [,14]
## [1,] 2315
## [2,] 2316
## [3,] 2317
## [4,] 2318
## [5,] 2319
## [6,] 2320
## [7,] 2321
## [8,] 2322
## [9,] 2323
## [10,] 2324
## [11,] 2325
## [12,] 2326
## [13,] 2327
## [14,] 2328
## [15,] 2329
## [16,] 2330
## [17,] 2331
## [18,] 2332
## [19,] 2333
## [20,] 2334
## [21,] 2335
## [22,] 2336
## [23,] 2337
## [24,] 2338
## [25,] 2339
## [26,] 2340
## [27,] 2341
## [28,] 2342
## [29,] 2343
## [30,] 2344
## [31,] 2345
## [32,] 2346
## [33,] 2347
## [34,] 2348
## [35,] 2349
## [36,] 2350
## [37,] 2351
## [38,] 2352
## [39,] 2353
## [40,] 2354
## [41,] 2355
## [42,] 2356
## [43,] 2357
## [44,] 2358
## [45,] 2359
## [46,] 2360
## [47,] 2361
## [48,] 2362
## [49,] 2363
## [50,] 2364
## [51,] 2365
## [52,] 2366
## [53,] 2367
## [54,] 2368
## [55,] 2369
## [56,] 2370
## [57,] 2371
## [58,] 2372
## [59,] 2373
## [60,] 2374
## [61,] 2375
## [62,] 2376
## [63,] 2377
## [64,] 2378
## [65,] 2379
## [66,] 2380
## [67,] 2381
## [68,] 2382
## [69,] 2383
## [70,] 2384
## [71,] 2385
## [72,] 2386
## [73,] 2387
## [74,] 2388
## [75,] 2389
## [76,] 2390
## [77,] 2391
## [78,] 2392
## [79,] 2393
## [80,] 2394
## [81,] 2395
## [82,] 2396
## [83,] 2397
## [84,] 2398
## [85,] 2399
## [86,] 2400
## [87,] 2401
## [88,] 2402
## [89,] 2403
## [90,] 2404
## [91,] 2405
## [92,] 2406
## [93,] 2407
## [94,] 2408
## [95,] 2409
## [96,] 2410
## [97,] 2411
## [98,] 2412
## [99,] 2413
## [100,] 2414
## [101,] 2415
## [102,] 2416
## [103,] 2417
## [104,] 2418
## [105,] 2419
## [106,] 2420
## [107,] 2421
## [108,] 2422
## [109,] 2423
## [110,] 2424
## [111,] 2425
## [112,] 2426
## [113,] 2427
## [114,] 2428
## [115,] 2429
## [116,] 2430
## [117,] 2431
## [118,] 2432
## [119,] 2433
## [120,] 2434
## [121,] 2435
## [122,] 2436
## [123,] 2437
## [124,] 2438
## [125,] 2439
## [126,] 2440
## [127,] 2441
## [128,] 2442
## [129,] 2443
## [130,] 2444
## [131,] 2445
## [132,] 2446
## [133,] 2447
## [134,] 2448
## [135,] 2449
## [136,] 2450
## [137,] 2451
## [138,] 2452
## [139,] 2453
## [140,] 2454
## [141,] 2455
## [142,] 2456
## [143,] 2457
## [144,] 2458
## [145,] 2459
## [146,] 2460
## [147,] 2461
## [148,] 2462
## [149,] 2463
## [150,] 2464
## [151,] 2465
## [152,] 2466
## [153,] 2467
## [154,] 2468
## [155,] 2469
## [156,] 2470
## [157,] 2471
## [158,] 2472
## [159,] 2473
## [160,] 2474
## [161,] 2475
## [162,] 2476
## [163,] 2477
## [164,] 2478
## [165,] 2479
## [166,] 2480
## [167,] 2481
## [168,] 2482
## [169,] 2483
## [170,] 2484
## [171,] 2485
## [172,] 2486
## [173,] 2487
## [174,] 2488
## [175,] 2489
## [176,] 2490
## [177,] 2491
## [178,] 2492
which(Valid_calcium) #con esta funcion podemos ver en que posicion se encuentra los datos que no cumplen las reglas de consistencia
## [1] 189 231 301 504 505 554 555 559 560 561 562 563 564 565 566
## [16] 567 568 569 570 571 582 584 624 633 711 716 721 735 820 821
## [31] 836 853 903 922 969 983 1022 1066 1128 1248 1249 1253 1254 1263 1279
## [46] 1280 1292 1295 1299 1303 1320 1326 1327 1328 1334 1335 1336 1337 1340 1346
## [61] 1351 1352 1360 1370 1371 1375 1382 1393 1407 1409 1415 1420 1424 1503
Despues de recoger las muestras y pasarla a la base de datos, podemos notar a simple vista algunos datos faltantes o datos inconsistentes, ademas podemos observar algunos datos numericos algo bajos o altos, pero no se podria determinar a simple vista si son datos atipicos o no. Lo que si notamos es que tan solo el 60% de los resultados no presentan algun error de consistencia y el 32% tiene tan solo un error, los cuales se puede ver que con mayor frecuencia estan entre las reglas 3 a 6 de la hoja de consistencia
El código que implementamos para conocer aquellos datos NA de la muestra es is.na.
#5. Visualizacion de datos faltantes (punto 3)
is.na(calcium) # para cada elemento de Datos verifica si es NA
## Age Sex ALP Lab CaMol PhoMol AgeG
## [1,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [4,] TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## [5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [6,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [7,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [8,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [9,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [10,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [11,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [12,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [13,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [14,] TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## [15,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [16,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [17,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [18,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [19,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [20,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [21,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [22,] FALSE FALSE TRUE FALSE FALSE FALSE FALSE
## [23,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [24,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [25,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [26,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [27,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [28,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [29,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [30,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [31,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [32,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [33,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [34,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [35,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [36,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [37,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [38,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [39,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [40,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [41,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [42,] FALSE FALSE FALSE FALSE FALSE TRUE FALSE
## [43,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [44,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [45,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [46,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [47,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [48,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [49,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [50,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [51,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [52,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [53,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [54,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [55,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [56,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [57,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [58,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [59,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [60,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [61,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [62,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [63,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [64,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [65,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [66,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [67,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [68,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [69,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [70,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [71,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [72,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [73,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [74,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [75,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [76,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [77,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [78,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [79,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [80,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [81,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [82,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [83,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [84,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [85,] FALSE FALSE FALSE FALSE TRUE FALSE FALSE
## [86,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [87,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [88,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [89,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [90,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [91,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [92,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [93,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [94,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [95,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [96,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [97,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [98,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [99,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [100,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [101,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [102,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [103,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [104,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [105,] TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## [106,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [107,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [108,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [109,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [110,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [111,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [112,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [113,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [114,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [115,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [116,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [117,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [118,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [119,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [120,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [121,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [122,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [123,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [124,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [125,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [126,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [127,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [128,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [129,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [130,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [131,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [132,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [133,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [134,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [135,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [136,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [137,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [138,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [139,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [140,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [141,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [142,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [143,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [144,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [145,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [146,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [147,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [148,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [149,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [150,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [151,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [152,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [153,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [154,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [155,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [156,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [157,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [158,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [159,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [160,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [161,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [162,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [163,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [164,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [165,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [166,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [167,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [168,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [169,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [170,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE
## [171,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [172,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [173,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [174,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [175,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [176,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [177,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [178,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
En la base de datos se encuentran 7 datos NA.
age: 3 datos en las observaciones en 4, 14 y 105
ALP: 1 dato en la observación en 22.
Lab: 1 dato en la observación en 170.
CaMol: 1 dato en la observación en 85.
PhoMol: 1 dato en la observación en 42.
x11()
visdat::vis_miss(calcium)# Una función que visualiza los datos faltantes en la hoja de calculo
visdat es una librerĆa que permite visualizar la proporción de datos
perdidos dentro de un conjunto de datos. en esta podemo ver los 7 datos
faltantes en cada variable.
# Función que evalua e identifica los datos faltantes por variable e individuo.
miss<-function(calcium,plot=T){
n=nrow(calcium);p=ncol(calcium)
names.obs<-rownames(calcium)
nobs.comp=sum(complete.cases(calcium)) # Cuenta los registros completos
Obs.comp=which(complete.cases(calcium)) # Identifica los registros completos
nobs.miss = sum(!complete.cases(calcium)) # Identifica los registros con datos faltantes.
Obs.miss=which(!complete.cases(calcium)) # Identifica los registros con datos faltantes.
calcium.NA<-is.na(calcium)
Var_Num<- sort(colSums(calcium.NA),decreasing=T)
Var_per<-round(Var_Num/n,3)
Obs_Num<-rowSums(calcium.NA)
names(Obs_Num)<-names.obs
Obs_Num<-sort(Obs_Num,decreasing=T)
Obs_per<-round(Obs_Num/p,3)
lista<-list(n.row = n, n.col = p,n.comp = nobs.comp,Obs.comp = Obs.comp,n.miss = nobs.miss,Obs.miss = Obs.miss, Var.n = Var_Num , Var.p = Var_per, Obs.n= Obs_Num, Obs.per= Obs_per)
if(plot){
windows(height=10,width=15)
par(mfrow=c(1,2))
coord<-barplot(Var_per,plot=F)
barplot(Var_per,xaxt="n",horiz=T,yaxt="n",xlim=c(-0.2,1), ylim=c(0,max(coord)+1),main= "% datos faltantes por variable")
axis(2,at=coord,labels=names(Var_per), cex.axis=0.5,pos=0,las=2)
axis(1,seq(0,1,0.2),seq(0,1,0.2),pos=0)
coord<-barplot(Obs_per,plot=F)
barplot(Obs_per,xaxt="n",horiz=T,yaxt="n",xlim=c(-0.2,1), ylim=c(0,max(coord)+1),main= "% datos faltantes por registro")
axis(2,at=coord,labels=names(Obs_per),cex.axis=0.5,pos=0,las=2)
axis(1,seq(0,1,0.2),seq(0,1,0.2))
}
return(invisible(lista))
}
Summary.NA = miss(calcium) # Asignamos el resultado a un objeto lista para consultarlo
str(calcium)
## 'data.frame': 178 obs. of 7 variables:
## $ Age : num 78 72 72 NA 73 73 65 68 89 84 ...
## $ Sex : Factor w/ 2 levels "Female","Male": 1 1 1 1 1 1 1 1 2 2 ...
## $ ALP : num 83 117 132 102 114 88 213 153 86 108 ...
## $ Lab : Factor w/ 6 levels "CB Rouche","Deyor",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ CaMol : num 2.53 2.5 2.43 2.48 2.33 2.13 2.55 2.45 2.25 2.43 ...
## $ PhoMol: num 1.07 1.16 1.13 0.81 1.13 0.84 1.26 1.23 0.65 0.84 ...
## $ AgeG : Factor w/ 6 levels "65 - 69","70 - 74",..: 3 2 2 2 2 2 5 1 5 4 ...
El proncentaje de NA que se encuentra en la muestra.
summary(calcium)
## Age Sex ALP Lab
## Min. : 65.00 Female:87 Min. : 9.00 CB Rouche :14
## 1st Qu.: 69.00 Male :91 1st Qu.: 71.00 Deyor :42
## Median : 72.00 Median : 85.00 Horizon : 6
## Mean : 83.65 Mean : 92.03 Metpath :88
## 3rd Qu.: 75.50 3rd Qu.:109.00 St. Elizabeth's:16
## Max. :771.00 Max. :219.00 YOH :11
## NA's :3 NA's :1 NA's : 1
## CaMol PhoMol AgeG
## Min. : 1.050 Min. :0.09 65 - 69:55
## 1st Qu.: 2.280 1st Qu.:0.97 70 - 74:70
## Median : 2.350 Median :1.13 75 - 79:38
## Mean : 3.921 Mean :1.16 80 - 84: 9
## 3rd Qu.: 2.480 3rd Qu.:1.23 85 - 89: 5
## Max. :25.300 Max. :8.84 NA : 1
## NA's :1 NA's :1
(Corrección de los niveles dentro de cada variable de tipo factor).
#6. Correccion de registros inconsistentes y faltantes (punto 4)
#Buscar posicion de los datos para compararlos con los datos originales
which(is.na(calcium$Lab))
## [1] 170
which(calcium$AgeG=="NA")
## [1] 79
which(is.na(calcium$Age))
## [1] 4 14 105
which(is.na(calcium$ALP))
## [1] 22
which(is.na(calcium$CaMol))
## [1] 85
which(is.na(calcium$PhoMol))
## [1] 42
Viendo la ubicacion de los datos faltantes e incosistentes buscamos en la hoja de datos tecnicamnente correcta, y realizamos los cambio pertinente
#Correcciones de los datos faltantes o con inconsistencias
calcium$AgeG[79]="80 - 84"
calcium$Age[4]=73
calcium$Age[14]=76
calcium$ALP[22]=64
calcium$Age[11]=71
calcium$Age[53]=69
calcium$Age[123]=73
calcium$CaMol[21]=2.20
calcium$CaMol[25]=2.53
calcium$CaMol[26]=2.00
calcium$CaMol[27]=2.23
calcium$CaMol[28]=2.43
calcium$CaMol[29]=2.50
calcium$CaMol[30]=2.22
calcium$CaMol[31]=2.40
calcium$CaMol[32]=2.50
calcium$CaMol[33]=2.50
calcium$CaMol[34]=2.35
calcium$CaMol[35]=2.25
calcium$CaMol[36]=2.45
calcium$CaMol[37]=2.33
calcium$CaMol[149]=2.05
calcium$PhoMol[32]=1.23
calcium$PhoMol[108]=0.90
calcium$PhoMol[132]=0.84
calcium$PhoMol[176]=1.26
calcium$ALP[60]=97
calcium$Lab[170]="Metpath"
calcium <- transform(calcium,
AgeG=factor(dplyr::recode(AgeG, !!!level_ageg))
)
# Verificación de las reglas sobres los datos
summary(editrules::violatedEdits(Rules, calcium))
## Edit violations, 178 observations, 0 completely missing (0%):
##
## editname freq rel
## num8 34 19.1%
## num4 6 3.4%
## num5 6 3.4%
## num6 3 1.7%
## num3 1 0.6%
##
## Edit violations per record:
##
## errors freq rel
## 0 128 71.9%
## 1 45 25.3%
## 2 4 2.2%
## 8 1 0.6%
# Visualización del diagnóstico
windows()
plot(editrules::violatedEdits(Rules, calcium))
El grÔfico muestra la probabilidad de que ocurra una violación a cada
una de las reglas.
#visualizamos un resumen de las variables
str(calcium)
## 'data.frame': 178 obs. of 7 variables:
## $ Age : num 78 72 72 73 73 73 65 68 89 84 ...
## $ Sex : Factor w/ 2 levels "Female","Male": 1 1 1 1 1 1 1 1 2 2 ...
## $ ALP : num 83 117 132 102 114 88 213 153 86 108 ...
## $ Lab : Factor w/ 6 levels "CB Rouche","Deyor",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ CaMol : num 2.53 2.5 2.43 2.48 2.33 2.13 2.55 2.45 2.25 2.43 ...
## $ PhoMol: num 1.07 1.16 1.13 0.81 1.13 0.84 1.26 1.23 0.65 0.84 ...
## $ AgeG : Factor w/ 5 levels "65 - 69","70 - 74",..: 3 2 2 2 2 2 5 1 5 4 ...
summary(calcium)
## Age Sex ALP Lab
## Min. :65.00 Female:87 Min. : 42.00 CB Rouche :14
## 1st Qu.:69.00 Male :91 1st Qu.: 71.25 Deyor :42
## Median :72.00 Median : 85.00 Horizon : 6
## Mean :72.32 Mean : 92.37 Metpath :89
## 3rd Qu.:75.00 3rd Qu.:108.75 St. Elizabeth's:16
## Max. :89.00 Max. :219.00 YOH :11
## NA's :1
## CaMol PhoMol AgeG
## Min. :1.900 Min. :0.520 65 - 69:55
## 1st Qu.:2.250 1st Qu.:0.970 70 - 74:70
## Median :2.350 Median :1.130 75 - 79:38
## Mean :2.354 Mean :1.103 80 - 84:10
## 3rd Qu.:2.450 3rd Qu.:1.230 85 - 89: 5
## Max. :2.750 Max. :1.610
## NA's :1 NA's :1
#Visualizamos nuevamente los datos faltantes despues de las correcciones
x11()
visdat::vis_miss(calcium)
Ahora la proporción de datos perdidos dentro de un conjunto del datos que son 3 datos faltantes.
Iniciaremos a realizar el analisis de los datos atipicos univariados con la Variable: Alp
#7. Datos atipicos (punto 5)
# Identificación y visualización de outliers Univariados.
# Iniciaremos con la Variable: Alp
attach(calcium)
x11()
par(mfrow=c(3,1))
with(calcium,{
hist(ALP,freq=F,col="blue",breaks=13)
boxplot(calcium$ALP,horizontal=T,col="blue")
hist(scale(ALP),freq=F,col="blue",breaks=13) #histograma escalando
}
)
##Criterio Estandarización
id = which(abs(scale(calcium$ALP))>3)
calcium$ALP[id]
## [1] 213 193 219
##Criterio Boxplot
boxplot.stats(calcium$ALP)$out
## [1] 213 168 193 219 171
which(calcium$ALP%in%boxplot.stats(calcium$ALP)$out)
## [1] 7 74 80 94 100
##Criterio Distancia Cooks
mean(calcium$ALP)
## [1] 92.36517
model=lm(calcium$ALP~1,data=calcium);CD=cooks.distance(model) # modelo en funcion del intercepto
id_ALP=unname(which(CD>4*mean(CD)))
windows()
labels=1:nrow(calcium);labels[-id_ALP]="."
plot(CD,pch=20);abline(h=4*mean(CD),col="red",ylab="Cooks_Distance")
text(id_ALP,CD[id_ALP],id_ALP, col="red",pos=3,cex=0.8)
En este grƔfico se muestran las observaciones que presentan los
outliers.
### Este procedimiento tendriamos que repetirlo para todas las variables, mejor lo ponemos en una función.
id.out.uni=function(x,method=c("Standarized","Tukey","Cook")){
id.out=NULL
if(method=="Standarized"){id.out=which(abs(scale(x))>3)}
else if(method=="Tukey"){id.out=which(x%in%(boxplot.stats(x)$out))}
else if(method=="Cook"){model=lm(x~1);CD=cooks.distance(model)
id.out=unname(which(CD>4*mean(CD)))}
return(id.out)
}
# Miremos como funciona la función la variable PhoMol
id.out.uni(calcium$PhoMol,method="Standarized")
## [1] 23
id.out.uni(calcium$PhoMol,method="Tukey")
## [1] 23
id.out.uni(calcium$PhoMol,method="Cook")
## [1] 9 13 23 78 92
El primer boxplot, el de la Edad muestra que la distribución de esta variable, tiene una media de 72 y cuenta con una cola superior muy larga, ademas, a sobre la media, La grÔfica muestra que existen 3 datos sobre la edad mÔxima de es 84 años.
El segundo boxplot de ALP muestra una media de 92 y cuenta con una cola superior un poco larga, asĆ mismo, existen 5 datos atĆpicos.
El tercer boxplot el de PhoMol muestra una media de 1.16, posee 1 datos atĆpicos en la parte inferior de la distribución.
El cuarto boxplot de CaMol muestra una media de 3.92, posee 1 datos atĆpicos en la parte inferior de la distribución.
Identificación multivariada de outliers
# Ahora vamos a automatizar la inspección de las variables
calcium.1<-dplyr::select(calcium,where(is.numeric))
calcium.1<-na.omit(calcium.1)
#Visualizar
windows()
par(mfrow=c(2,2))
lapply(calcium.1,boxplot,col="Blue")
## $Age
## $Age$stats
## [,1]
## [1,] 65
## [2,] 69
## [3,] 71
## [4,] 75
## [5,] 84
##
## $Age$n
## [1] 175
##
## $Age$conf
## [,1]
## [1,] 70.28338
## [2,] 71.71662
##
## $Age$out
## [1] 89 88 86
##
## $Age$group
## [1] 1 1 1
##
## $Age$names
## [1] "1"
##
##
## $ALP
## $ALP$stats
## [,1]
## [1,] 42.0
## [2,] 71.0
## [3,] 85.0
## [4,] 107.5
## [5,] 159.0
##
## $ALP$n
## [1] 175
##
## $ALP$conf
## [,1]
## [1,] 80.64056
## [2,] 89.35944
##
## $ALP$out
## [1] 213 168 193 219 171
##
## $ALP$group
## [1] 1 1 1 1 1
##
## $ALP$names
## [1] "1"
##
##
## $CaMol
## $CaMol$stats
## [,1]
## [1,] 2.00
## [2,] 2.25
## [3,] 2.35
## [4,] 2.45
## [5,] 2.75
##
## $CaMol$n
## [1] 175
##
## $CaMol$conf
## [,1]
## [1,] 2.326113
## [2,] 2.373887
##
## $CaMol$out
## [1] 1.9
##
## $CaMol$group
## [1] 1
##
## $CaMol$names
## [1] "1"
##
##
## $PhoMol
## $PhoMol$stats
## [,1]
## [1,] 0.65
## [2,] 0.97
## [3,] 1.13
## [4,] 1.23
## [5,] 1.61
##
## $PhoMol$n
## [1] 175
##
## $PhoMol$conf
## [,1]
## [1,] 1.098946
## [2,] 1.161054
##
## $PhoMol$out
## [1] 0.52
##
## $PhoMol$group
## [1] 1
##
## $PhoMol$names
## [1] "1"
### Identificar los Datos Atipicos
out_Stand = lapply(calcium.1[,(1:4)],id.out.uni,method="Standarized")
out_Tukey = lapply(calcium.1[,(1:4)],id.out.uni,method="Tukey")
out_Cook = lapply(calcium.1[,(1:4)],id.out.uni,method="Cook")
Este es el scaterplot de las variables cuantitativas entre cada una de ellas,los coeficientes que aparecen en la grĆ”ficas donde si todos los puntos se ajustan a una lĆnea serĆa porque las variables estĆ”n altamente correlacionadas. Y, si en algunas grĆ”ficas pasa lo contrario, es porque estĆ”n poco correlacionadas, ademas, los valores positivos siginifican una relacion directa y los negativos signifacan una relacion inversa.
# Identificación multivariada de outliers
calcium.cor = cor(calcium.1[,(1:4)],method="pearson")
windows(height=10,width=15)
corrplot::corrplot(calcium.cor , method = "ellipse",addCoef.col = "black",type="upper")
windows(height=10,width=15)
pairs(calcium.1[,(1:4)],lower.panel = panel.smooth, pch = 15)
## Visualización de outliers multivariados
out.mult=function(calcium){
n= nrow(calcium); p= ncol(calcium)
Distance= mahalanobis(calcium,center=colMeans(calcium),cov=cov(calcium))
Limit= qchisq(0.01, lower.tail=F,df=p)
id.dist= which(Distance>Limit)
Score_LOF = DMwR2::lofactor(calcium, k=5)
id.LOF <- order(Score_LOF, decreasing=T)[1:ceiling(0.01*n)]
windows()
par(mfrow=c(2,1))
plot(Distance,pch=20,ylim=c(0,max(Distance)*1.2))
text(id.dist,Distance[id.dist],id.dist, col="red",pos=3,cex=0.8)
abline(h=Limit,col="red",lwd=2,lty=2)
plot(Score_LOF,pch=20,ylim=c(0,max(Score_LOF)*1.2))
text(id.LOF,Score_LOF[id.LOF],id.LOF, col="red",pos=3,cex=0.8)
return(list(Out_dist=id.dist,Out_LOF=id.LOF))
}
id_Out_mult=out.mult(calcium.1)
## $Out_dist
## 7 9 23 79 80 94 148
## 7 9 23 78 79 92 145
##
## $Out_LOF
## [1] 92 7
#8. imputacion de datos inconsistentes y faltantes (punto 6)
Visualizar.c= function(calcium){ #Una función para visualizar los datos de calcium
with(calcium,{
## Distribución de los datos entre los individuos
windows(height=10,width=15)
par(mfrow=c(2,2))
plot(calcium$Age,type="l",col="Red")
plot(calcium$ALP,type="l",col="Gray")
plot(calcium$CaMol,type="l",col="Blue")
plot(calcium$PhoMol,type="l",col="Green")
## Variación entre rangos de edad
windows(height=10,width=15)
par(mfrow=c(2,2))
plot(calcium$Age~calcium$Sex,type="l",col="Red")
plot(calcium$ALP~calcium$Sex,type="l",col="Gray")
plot(calcium$CaMol~calcium$Sex,type="l",col="Blue")
plot(calcium$PhoMol~calcium$Sex,type="l",col="Green")
})
## Correlación entre covariables cuantitativas
calcium.cuant<-dplyr::select(calcium,where(is.numeric))
c.cor = cor(calcium.cuant,method="pearson")
print(c.cor)
windows(height=10,width=15)
corrplot::corrplot(c.cor, method = "ellipse",addCoef.col = "black",type="upper")
windows(height=10,width=15)
pairs(calcium.cuant,lower.panel = panel.smooth, pch = 15)
}
## Visualización.
Visualizar.c(calcium)
## Age ALP CaMol PhoMol
## Age 1 NA NA NA
## ALP NA 1 NA NA
## CaMol NA NA 1 NA
## PhoMol NA NA NA 1
Convertimos a valores NA, los datos atipicos e influyentes que se encointraron en el literal alterior
## primera solución, identificar y completar (ya realizada en el punto 4)
calcium$ALP[7] <- NA
calcium$ALP[79] <- NA
calcium$ALP[92] <- NA
calcium$ALP[98] <- NA
calcium$PhoMol[23] <- NA
calcium$CaMol[145] <- NA
## Una segunda aproximación, omitir los registros con datos faltantes.
calcium_clean=na.omit(calcium)# se omiten todos los registros con datos faltantes
windows(height=10,width=15); visdat::vis_miss(calcium_clean)
Visualizar.c(calcium_clean)
## Age ALP CaMol PhoMol
## Age 1.00000000 -0.04631604 -0.04217134 -0.20105499
## ALP -0.04631604 1.00000000 0.16394871 0.08294085
## CaMol -0.04217134 0.16394871 1.00000000 0.07742572
## PhoMol -0.20105499 0.08294085 0.07742572 1.00000000
Imputamos por la media
## Tercera aproximación, Imputar
# Imputación por la media.
mean(calcium$Age)
## [1] NA
mean(calcium$Age,na.rm=T)
## [1] 72.32203
mean(calcium$CaMol,na.rm=T)
## [1] 2.354886
mean(calcium$PhoMol,na.rm=T)
## [1] 1.106023
imputM = mice::mice(calcium, maxit = 1, method = "mean",seed = 2018,print=F)
calcium_ImputM = mice::complete(imputM)
windows(height=10,width=15); visdat::vis_miss(calcium_ImputM)
Visualizar.c(calcium_ImputM)
## Age ALP CaMol PhoMol
## Age 1.00000000 -0.03075768 -0.04902275 -0.16398629
## ALP -0.03075768 1.00000000 0.14892411 0.09529700
## CaMol -0.04902275 0.14892411 1.00000000 0.08210418
## PhoMol -0.16398629 0.09529700 0.08210418 1.00000000
Imputamos por el metodo de regresión
## Imputación por regresion.
imputR = mice::mice(calcium, maxit = 1, method = "norm.predict",seed = 2018,print=F)
calcium_ImputR = mice::complete(imputR)
windows(height=10,width=15); visdat::vis_miss(calcium_ImputR)
Visualizar.c(calcium_ImputR)
## Age ALP CaMol PhoMol
## Age 1.00000000 -0.03762524 -0.04241098 -0.16923814
## ALP -0.03762524 1.00000000 0.14451748 0.09765356
## CaMol -0.04241098 0.14451748 1.00000000 0.07864835
## PhoMol -0.16923814 0.09765356 0.07864835 1.00000000
Hacemos los modelos de regresión con cada metodo de imputación para ver cual es el que vamos a usar, segun el r ajustado y el r ajustado al cuadrado
## La imputación puede cambiar los resultados de los modelos - Una comparación
# Un modelo de regresión
model_miss=lm(calcium$ALP~.,calcium[,-c(2,4)]) # Con los Datos Faltantes
summary(model_miss)
##
## Call:
## lm(formula = calcium$ALP ~ ., data = calcium[, -c(2, 4)])
##
## Residuals:
## Min 1Q Median 3Q Max
## -56.121 -19.655 -5.006 15.441 132.287
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -122.851 112.788 -1.089 0.2777
## Age 1.957 1.574 1.244 0.2155
## CaMol 30.527 16.665 1.832 0.0688 .
## PhoMol 9.350 13.940 0.671 0.5033
## AgeG70 - 74 -6.973 8.691 -0.802 0.4236
## AgeG75 - 79 -17.051 16.005 -1.065 0.2883
## AgeG80 - 84 -35.042 24.157 -1.451 0.1488
## AgeG85 - 89 -52.990 34.080 -1.555 0.1219
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 29.03 on 161 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.05229, Adjusted R-squared: 0.01108
## F-statistic: 1.269 on 7 and 161 DF, p-value: 0.2689
model_clean=lm(calcium_clean$ALP~.,calcium_clean[,-c(2,4)]) # Eliminando registros con Datos Faltantes
summary(model_clean)
##
## Call:
## lm(formula = calcium_clean$ALP ~ ., data = calcium_clean[, -c(2,
## 4)])
##
## Residuals:
## Min 1Q Median 3Q Max
## -56.121 -19.655 -5.006 15.441 132.287
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -122.851 112.788 -1.089 0.2777
## Age 1.957 1.574 1.244 0.2155
## CaMol 30.527 16.665 1.832 0.0688 .
## PhoMol 9.350 13.940 0.671 0.5033
## AgeG70 - 74 -6.973 8.691 -0.802 0.4236
## AgeG75 - 79 -17.051 16.005 -1.065 0.2883
## AgeG80 - 84 -35.042 24.157 -1.451 0.1488
## AgeG85 - 89 -52.990 34.080 -1.555 0.1219
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 29.03 on 161 degrees of freedom
## Multiple R-squared: 0.05229, Adjusted R-squared: 0.01108
## F-statistic: 1.269 on 7 and 161 DF, p-value: 0.2689
model_ImputM=lm(calcium_ImputM$ALP~.,calcium_ImputM[,-c(2,4)]) # Con Imputación por la media
summary(model_ImputM)
##
## Call:
## lm(formula = calcium_ImputM$ALP ~ ., data = calcium_ImputM[,
## -c(2, 4)])
##
## Residuals:
## Min 1Q Median 3Q Max
## -55.102 -20.493 -4.768 16.165 130.696
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -83.716 86.262 -0.970 0.3332
## Age 1.301 1.068 1.218 0.2250
## CaMol 30.622 16.211 1.889 0.0606 .
## PhoMol 14.095 13.219 1.066 0.2878
## AgeG70 - 74 -4.317 6.960 -0.620 0.5359
## AgeG75 - 79 -10.875 11.599 -0.938 0.3498
## AgeG80 - 84 -25.972 17.763 -1.462 0.1456
## AgeG85 - 89 -32.540 20.807 -1.564 0.1197
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 28.95 on 170 degrees of freedom
## Multiple R-squared: 0.04869, Adjusted R-squared: 0.009516
## F-statistic: 1.243 on 7 and 170 DF, p-value: 0.282
model_ImputR=lm(calcium_ImputR$ALP~.,calcium_ImputR[,-c(2,4)]) # Con Imputación por Regresión
summary(model_ImputR)
##
## Call:
## lm(formula = calcium_ImputR$ALP ~ ., data = calcium_ImputR[,
## -c(2, 4)])
##
## Residuals:
## Min 1Q Median 3Q Max
## -54.787 -20.640 -4.787 16.321 129.823
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -64.115 87.694 -0.731 0.4657
## Age 1.057 1.093 0.967 0.3348
## CaMol 29.215 16.242 1.799 0.0738 .
## PhoMol 14.370 13.292 1.081 0.2812
## AgeG70 - 74 -3.092 7.093 -0.436 0.6635
## AgeG75 - 79 -8.767 11.885 -0.738 0.4617
## AgeG80 - 84 -21.435 18.132 -1.182 0.2388
## AgeG85 - 89 -30.336 21.128 -1.436 0.1529
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 29.04 on 170 degrees of freedom
## Multiple R-squared: 0.04516, Adjusted R-squared: 0.005843
## F-statistic: 1.149 on 7 and 170 DF, p-value: 0.3352
##revisamos una ultima vez que los datos esten 100% listos
# Verificación de las reglas sobres los datos
summary(editrules::violatedEdits(Rules, calcium_ImputM))
## Edit violations, 178 observations, 0 completely missing (0%):
##
## editname freq rel
## num8 33 18.5%
## num4 6 3.4%
## num5 5 2.8%
## num6 3 1.7%
## num3 1 0.6%
##
## Edit violations per record:
##
## errors freq rel
## 0 132 74.2%
## 1 44 24.7%
## 2 2 1.1%
# Visualización del diagnóstico
windows()
plot(editrules::violatedEdits(Rules, calcium_ImputM))
#visualizamos un resumen de las variables
str(calcium_ImputM)
## 'data.frame': 178 obs. of 7 variables:
## $ Age : num 78 72 72 73 73 73 65 68 89 84 ...
## $ Sex : Factor w/ 2 levels "Female","Male": 1 1 1 1 1 1 1 1 2 2 ...
## $ ALP : num 83 117 132 102 114 ...
## $ Lab : Factor w/ 6 levels "CB Rouche","Deyor",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ CaMol : num 2.53 2.5 2.43 2.48 2.33 2.13 2.55 2.45 2.25 2.43 ...
## $ PhoMol: num 1.07 1.16 1.13 0.81 1.13 0.84 1.26 1.23 0.65 0.84 ...
## $ AgeG : Factor w/ 5 levels "65 - 69","70 - 74",..: 3 2 2 2 2 2 5 1 5 4 ...
summary(calcium_ImputM)
## Age Sex ALP Lab
## Min. :65.00 Female:87 Min. : 42.00 CB Rouche :14
## 1st Qu.:69.00 Male :91 1st Qu.: 71.25 Deyor :42
## Median :72.00 Median : 86.00 Horizon : 6
## Mean :72.32 Mean : 91.70 Metpath :89
## 3rd Qu.:75.00 3rd Qu.:107.00 St. Elizabeth's:16
## Max. :89.00 Max. :219.00 YOH :11
## CaMol PhoMol AgeG
## Min. :1.900 Min. :0.650 65 - 69:55
## 1st Qu.:2.250 1st Qu.:0.970 70 - 74:70
## Median :2.350 Median :1.130 75 - 79:38
## Mean :2.355 Mean :1.106 80 - 84:10
## 3rd Qu.:2.450 3rd Qu.:1.230 85 - 89: 5
## Max. :2.750 Max. :1.610
#Visualizamos nuevamente los datos faltantes despues de las correcciones
x11()
visdat::vis_miss(calcium_ImputM)
La proporción de datos perdidos dentro del conjunto de datos ahora es
cero, eliminamos los datos NA.
#Descargamos la base de datos limpia
write.table(calcium_ImputM, file="clean_calcium.csv")
#9. Tableros graficos (punto 8)
#8.1
# Visualización de graficas en un solo panel.
attach(calcium_ImputM)
## The following objects are masked from calcium:
##
## Age, AgeG, ALP, CaMol, Lab, PhoMol, Sex
windows(height=10,width=20) # Abre una nueva ventana grafica con las dimensiones predeterminadas
M=matrix(c(1,1,2,2,1,1,2,2,3,3,2,2,3,3,2,2), nrow=4,byrow=F)
layout(M) # Partición de la ventana
boxplot(Age~AgeG,col=color_a)
boxplot(Age~Lab,col=color_l)
boxplot(Age~Sex,col=color_s)
- Como podemos evidenciar, la distribución de la edad hay pocas personas
mayores de 80 aƱos, una mayor frecuencia en la poblacion femenina,sin
embargo, esta no difiere mucho de la cantidad de hombres. De igual
forma, en la distribuvion por rango de edad, tenemos que hay una alta
concentración en las edades de 70-74 y la mayor cantidad de pacientes se
encuentran en el laboratorio Metpath.
#Otra forma de visualizar la distribucion
windows(height=10,width=20) # Abre una nueva ventana grafica con las dimensiones predeterminadas
M=matrix(c(1,1,2,2,1,1,3,3,4,4,6,6,5,5,7,7), nrow=4,byrow=F)
layout(M) # Partición de la ventana
#Distribucion por edad
plot(x = Age, ylim=c(64,90), main= "Distribución de edad", xlab="Observación")
abline(h=80,col = 'steelblue', lwd = 2, lty = 2)
#distribucion por grupo de edad
tabla_e=table(AgeG)
prop.table(tabla_e)
## AgeG
## 65 - 69 70 - 74 75 - 79 80 - 84 85 - 89
## 0.30898876 0.39325843 0.21348315 0.05617978 0.02808989
barplot(tabla_e, col=color_a, xlab="edadG",main="Frecuencia absoluta", ylim=c(0,100))
barplot(prop.table(tabla_e)*100, col=color_a, xlab="edadG",main="Frecuencia relativa (%)", ylim=c(0,100))
#distribucion por sexo
tabla_s=table(Sex)
prop.table(tabla_s)
## Sex
## Female Male
## 0.488764 0.511236
barplot(tabla_s, col=color_s, xlab="Sexo",main="Frecuencia absoluta", ylim=c(0,100))
barplot(prop.table(tabla_s)*100, col=color_s, xlab="Sexo",main="Frecuencia relativa (%)", ylim=c(0,100))
#distribucion por laboratorio
tabla_l=table(Lab)
prop.table(tabla_l)
## Lab
## CB Rouche Deyor Horizon Metpath St. Elizabeth's
## 0.07865169 0.23595506 0.03370787 0.50000000 0.08988764
## YOH
## 0.06179775
barplot(tabla_l, col=color_l, xlab="Lab",main="Frecuencia absoluta", ylim=c(0,100))
barplot(prop.table(tabla_l)*100, col=color_l, xlab="Lab",main="Frecuencia relativa (%)", ylim=c(0,100))
- La diferencia de la variable ALP entre las variables AgeG, Lab y Sex,
podemos determinar que cada rango de edad tiene uni vamores medios muy
parecidos, sin embargo, los primeros dos intervalos tienen mayor
dispersión. Por otro lado, la concentración es mayor en hombres que en
mujeres. Y por ultimo, la distribuión de esta variable es mayor en CB
Rouche y menor en YOH, en los otros laboratorios precenta pequeas
variaciones su media.
#8.2
# Visualización de graficas en un solo panel ALP
windows(height=10,width=20) # Abre una nueva ventana grafica con las dimensiones predeterminadas
M=matrix(c(1,1,2,2,1,1,2,2,3,3,2,2,3,3,2,2), nrow=4,byrow=F)
layout(M) # Partición de la ventana
plot(ALP~AgeG,col=color_a)
plot(ALP~Lab,col=color_l)
plot(ALP~Sex,col=color_s)
- La diferencia de la variable CaMol entre las variables AgeG, Lab y
Sex, podemos determinar que las personas con mayor edad tienen valores
mas bajos de calcio, y su pico esta en la edad entre 70-74 aƱos. Por
otro lado, la concentración es mayor en hombres que en mujeres. Y por
ultimo, la distribución de esta variable entre los laboratorios va
descendiendo en cada laboratorio como se ve en la grƔfica.
# Visualización de graficas en un solo panel CaMol
windows(height=10,width=20) # Abre una nueva ventana grafica con las dimensiones predeterminadas
M=matrix(c(1,1,2,2,1,1,2,2,3,3,2,2,3,3,2,2), nrow=4,byrow=F)
layout(M) # Partición de la ventana
plot(CaMol~AgeG,col=color_a)
plot(CaMol~Lab,col=color_l)
plot(CaMol~Sex,col=color_s)
- La diferencia de la variable PhoMol entre las variables AgeG, Lab y
Sex, podemos determinar que a medida que la edad de las personas
aumenta, la cantidad de PhoMol de las personas disminuye. Por otro lado,
la concentración es mayor en hombres que en mujeres. Y por ultimo, la
distribuión de esta variable entre los laboratorios es relativamente
semejante, exceptuando los laboratorios CB Rouche y YOH, las cuales
presentan unos valores mas bajos y altos respectivamente.
# Visualización de graficas en un solo panel PhoMol
windows(height=10,width=20) # Abre una nueva ventana grafica con las dimensiones predeterminadas
M=matrix(c(1,1,2,2,1,1,2,2,3,3,2,2,3,3,2,2), nrow=4,byrow=F)
layout(M) # Partición de la ventana
plot(PhoMol~AgeG,col=color_a)
plot(PhoMol~Lab,col=color_l)
plot(PhoMol~Sex,col=color_s)
- Al final, realizamos el analisis de la estructura de correlación de
las variables, y observamos que la relación entre Age-PhoMol tiene la
mayor correlación negativa, caso contrario, la relación ALP-CaMol tiene
la mayor correlación positiva.
#8.3
calcium.cuant<-dplyr::select(calcium_ImputM,where(is.numeric))
c.cor = cor(calcium.cuant,method="pearson")
print(c.cor)
## Age ALP CaMol PhoMol
## Age 1.00000000 -0.03075768 -0.04902275 -0.16398629
## ALP -0.03075768 1.00000000 0.14892411 0.09529700
## CaMol -0.04902275 0.14892411 1.00000000 0.08210418
## PhoMol -0.16398629 0.09529700 0.08210418 1.00000000
windows(height=10,width=15)
corrplot::corrplot(c.cor, method = "ellipse",addCoef.col = "black",type="upper")
windows(height=10,width=15)
pairs(calcium.cuant,lower.panel = panel.smooth, pch = 15)