Enrique
Monsivais
2023-10-04
## hora dia mes año
## Min. : 0.00 Min. : 1.000 Min. : 1.000 Min. :2011
## 1st Qu.: 6.00 1st Qu.: 5.000 1st Qu.: 4.000 1st Qu.:2011
## Median :12.00 Median :10.000 Median : 7.000 Median :2012
## Mean :11.54 Mean : 9.993 Mean : 6.521 Mean :2012
## 3rd Qu.:18.00 3rd Qu.:15.000 3rd Qu.:10.000 3rd Qu.:2012
## Max. :23.00 Max. :19.000 Max. :12.000 Max. :2012
## estacion dia_de_la_semana asueto temperatura
## Min. :1.000 Min. :1.000 Min. :0.00000 Min. : 0.82
## 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:0.00000 1st Qu.:13.94
## Median :3.000 Median :4.000 Median :0.00000 Median :20.50
## Mean :2.507 Mean :4.014 Mean :0.02857 Mean :20.23
## 3rd Qu.:4.000 3rd Qu.:6.000 3rd Qu.:0.00000 3rd Qu.:26.24
## Max. :4.000 Max. :7.000 Max. :1.00000 Max. :41.00
## sensacion_termica humedad velocidad_del_viento
## Min. : 0.76 Min. : 0.00 Min. : 0.000
## 1st Qu.:16.66 1st Qu.: 47.00 1st Qu.: 7.002
## Median :24.24 Median : 62.00 Median :12.998
## Mean :23.66 Mean : 61.89 Mean :12.799
## 3rd Qu.:31.06 3rd Qu.: 77.00 3rd Qu.:16.998
## Max. :45.45 Max. :100.00 Max. :56.997
## rentas_de_no_registrados rentas_de_registrados rentas_totales
## Min. : 0.00 Min. : 0.0 Min. : 1.0
## 1st Qu.: 4.00 1st Qu.: 36.0 1st Qu.: 42.0
## Median : 17.00 Median :118.0 Median :145.0
## Mean : 36.02 Mean :155.6 Mean :191.6
## 3rd Qu.: 49.00 3rd Qu.:222.0 3rd Qu.:284.0
## Max. :367.00 Max. :886.0 Max. :977.0
Observación: 1. Los días llegan hasta el 19 y no hasta 31.
regresion <- lm(rentas_totales ~ hora + dia + mes + año + estacion + dia_de_la_semana + asueto + temperatura + sensacion_termica + humedad + velocidad_del_viento, data =df)
summary(regresion)##
## Call:
## lm(formula = rentas_totales ~ hora + dia + mes + año + estacion +
## dia_de_la_semana + asueto + temperatura + sensacion_termica +
## humedad + velocidad_del_viento, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -305.52 -93.64 -27.70 61.85 649.10
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.661e+05 5.496e+03 -30.217 < 2e-16 ***
## hora 7.735e+00 2.070e-01 37.368 < 2e-16 ***
## dia 3.844e-01 2.482e-01 1.549 0.12150
## mes 9.996e+00 1.682e+00 5.943 2.89e-09 ***
## año 8.258e+01 2.732e+00 30.225 < 2e-16 ***
## estacion -7.774e+00 5.177e+00 -1.502 0.13324
## dia_de_la_semana 4.393e-01 6.918e-01 0.635 0.52545
## asueto -4.864e+00 8.365e+00 -0.582 0.56089
## temperatura 1.582e+00 1.038e+00 1.524 0.12752
## sensacion_termica 4.748e+00 9.552e-01 4.971 6.76e-07 ***
## humedad -2.115e+00 7.884e-02 -26.827 < 2e-16 ***
## velocidad_del_viento 5.582e-01 1.809e-01 3.086 0.00203 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 141.7 on 10874 degrees of freedom
## Multiple R-squared: 0.3891, Adjusted R-squared: 0.3885
## F-statistic: 629.6 on 11 and 10874 DF, p-value: < 2.2e-16
regresion <- lm(rentas_totales ~ hora + mes + año + sensacion_termica + humedad + velocidad_del_viento, data=df)
summary(regresion)##
## Call:
## lm(formula = rentas_totales ~ hora + mes + año + sensacion_termica +
## humedad + velocidad_del_viento, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -308.60 -93.85 -28.34 61.05 648.09
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.662e+05 5.496e+03 -30.250 < 2e-16 ***
## hora 7.734e+00 2.070e-01 37.364 < 2e-16 ***
## mes 7.574e+00 4.207e-01 18.002 < 2e-16 ***
## año 8.266e+01 2.732e+00 30.258 < 2e-16 ***
## sensacion_termica 6.172e+00 1.689e-01 36.539 < 2e-16 ***
## humedad -2.121e+00 7.858e-02 -26.988 < 2e-16 ***
## velocidad_del_viento 6.208e-01 1.771e-01 3.506 0.000457 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 141.7 on 10879 degrees of freedom
## Multiple R-squared: 0.3886, Adjusted R-squared: 0.3883
## F-statistic: 1153 on 6 and 10879 DF, p-value: < 2.2e-16
datos <- data.frame(hora=11.54, mes=1:12, año=2013, sensacion_termica=23.66, humedad=61.89, velocidad_del_viento=12.799)
predict(regresion, datos)## 1 2 3 4 5 6 7 8
## 273.6001 281.1738 288.7475 296.3213 303.8950 311.4687 319.0424 326.6161
## 9 10 11 12
## 334.1898 341.7635 349.3372 356.9110
## Observation Dist_Taxi Dist_Market Dist_Hospital
## Min. : 1.0 Min. : 146 Min. : 1666 Min. : 3227
## 1st Qu.:237.0 1st Qu.: 6477 1st Qu.: 9367 1st Qu.:11302
## Median :469.0 Median : 8228 Median :11149 Median :13189
## Mean :468.4 Mean : 8235 Mean :11022 Mean :13091
## 3rd Qu.:700.0 3rd Qu.: 9939 3rd Qu.:12675 3rd Qu.:14855
## Max. :932.0 Max. :20662 Max. :20945 Max. :23294
##
## Carpet Builtup Parking City_Category
## Min. : 775 Min. : 932 Length:905 Length:905
## 1st Qu.: 1317 1st Qu.: 1579 Class :character Class :character
## Median : 1478 Median : 1774 Mode :character Mode :character
## Mean : 1511 Mean : 1794
## 3rd Qu.: 1654 3rd Qu.: 1985
## Max. :24300 Max. :12730
## NA's :7
## Rainfall House_Price
## Min. :-110.0 Min. : 1492000
## 1st Qu.: 600.0 1st Qu.: 4623000
## Median : 780.0 Median : 5860000
## Mean : 786.9 Mean : 6083992
## 3rd Qu.: 970.0 3rd Qu.: 7200000
## Max. :1560.0 Max. :150000000
##
## Parking n
## 1 Open 355
## 2 Not Provided 225
## 3 Covered 184
## 4 No Parking 141
## City_Category n
## 1 CAT B 351
## 2 CAT A 320
## 3 CAT C 234
Observación: 1. El precio de la casa esta con datos atípicos 2. Rainfall tiene valores negativos 3. Carpet tiene 7 NA
## [1] 7
## Observation Dist_Taxi Dist_Market Dist_Hospital Carpet
## 0 0 0 0 7
## Builtup Parking City_Category Rainfall House_Price
## 0 0 0 0 0
# Eliminar los NA
bd <- na.omit(bd)
#Eliminar registro de valor atípico
bd <- bd[bd$House_Price<120000000,]
#Eliminar registro de Rainfall negativo
bd <- bd[bd$Rainfall>=0,]
# Gráficas
boxplot(bd$House_Price, horizontal = TRUE)regresion <- lm(House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital + Carpet + Builtup + Parking + City_Category + Rainfall, data =bd)
summary(regresion)##
## Call:
## lm(formula = House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital +
## Carpet + Builtup + Parking + City_Category + Rainfall, data = bd)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3572009 -800792 -65720 761534 4401585
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.599e+06 3.672e+05 15.246 < 2e-16 ***
## Dist_Taxi 3.009e+01 2.682e+01 1.122 0.2622
## Dist_Market 1.285e+01 2.081e+01 0.618 0.5370
## Dist_Hospital 4.864e+01 3.008e+01 1.617 0.1062
## Carpet -7.997e+02 3.476e+03 -0.230 0.8181
## Builtup 1.339e+03 2.901e+03 0.462 0.6444
## ParkingNo Parking -6.040e+05 1.389e+05 -4.348 1.53e-05 ***
## ParkingNot Provided -4.924e+05 1.235e+05 -3.988 7.22e-05 ***
## ParkingOpen -2.632e+05 1.126e+05 -2.338 0.0196 *
## City_CategoryCAT B -1.877e+06 9.598e+04 -19.554 < 2e-16 ***
## City_CategoryCAT C -2.890e+06 1.059e+05 -27.300 < 2e-16 ***
## Rainfall -1.175e+02 1.550e+02 -0.758 0.4484
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1222000 on 884 degrees of freedom
## Multiple R-squared: 0.5007, Adjusted R-squared: 0.4945
## F-statistic: 80.58 on 11 and 884 DF, p-value: < 2.2e-16
regresion <- lm(House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital + Carpet + Builtup + Parking + City_Category + Rainfall, data =bd)
summary(regresion)##
## Call:
## lm(formula = House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital +
## Carpet + Builtup + Parking + City_Category + Rainfall, data = bd)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3572009 -800792 -65720 761534 4401585
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.599e+06 3.672e+05 15.246 < 2e-16 ***
## Dist_Taxi 3.009e+01 2.682e+01 1.122 0.2622
## Dist_Market 1.285e+01 2.081e+01 0.618 0.5370
## Dist_Hospital 4.864e+01 3.008e+01 1.617 0.1062
## Carpet -7.997e+02 3.476e+03 -0.230 0.8181
## Builtup 1.339e+03 2.901e+03 0.462 0.6444
## ParkingNo Parking -6.040e+05 1.389e+05 -4.348 1.53e-05 ***
## ParkingNot Provided -4.924e+05 1.235e+05 -3.988 7.22e-05 ***
## ParkingOpen -2.632e+05 1.126e+05 -2.338 0.0196 *
## City_CategoryCAT B -1.877e+06 9.598e+04 -19.554 < 2e-16 ***
## City_CategoryCAT C -2.890e+06 1.059e+05 -27.300 < 2e-16 ***
## Rainfall -1.175e+02 1.550e+02 -0.758 0.4484
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1222000 on 884 degrees of freedom
## Multiple R-squared: 0.5007, Adjusted R-squared: 0.4945
## F-statistic: 80.58 on 11 and 884 DF, p-value: < 2.2e-16
## pclass survived name sex
## Min. :1.000 Min. :0.000 Length:1310 Length:1310
## 1st Qu.:2.000 1st Qu.:0.000 Class :character Class :character
## Median :3.000 Median :0.000 Mode :character Mode :character
## Mean :2.295 Mean :0.382
## 3rd Qu.:3.000 3rd Qu.:1.000
## Max. :3.000 Max. :1.000
## NA's :1 NA's :1
## age sibsp parch ticket
## Min. : 0.1667 Min. :0.0000 Min. :0.000 Length:1310
## 1st Qu.:21.0000 1st Qu.:0.0000 1st Qu.:0.000 Class :character
## Median :28.0000 Median :0.0000 Median :0.000 Mode :character
## Mean :29.8811 Mean :0.4989 Mean :0.385
## 3rd Qu.:39.0000 3rd Qu.:1.0000 3rd Qu.:0.000
## Max. :80.0000 Max. :8.0000 Max. :9.000
## NA's :264 NA's :1 NA's :1
## fare cabin embarked boat
## Min. : 0.000 Length:1310 Length:1310 Length:1310
## 1st Qu.: 7.896 Class :character Class :character Class :character
## Median : 14.454 Mode :character Mode :character Mode :character
## Mean : 33.295
## 3rd Qu.: 31.275
## Max. :512.329
## NA's :2
## body home.dest
## Min. : 1.0 Length:1310
## 1st Qu.: 72.0 Class :character
## Median :155.0 Mode :character
## Mean :160.8
## 3rd Qu.:256.0
## Max. :328.0
## NA's :1189
#count(titanic, name, sort=TRUE)
#count(titanic, sex, sort=TRUE)
#count(titanic, ticket, sort=TRUE)
#count(titanic, cabin, sort=TRUE)
#count(titanic, embarked, sort=TRUE)
#count(titanic, boat, sort=TRUE)
#count(titanic, home.dest, sort=TRUE)Observaciones: 1. Tenemos NA en la base de datos. 2. Un par de nombres están repetidos
# Cambiar de nombre a la variable pclass
colnames(titanic)[1] <- "class"
# Extraer las variables de interés
Titanic <- titanic[c("class","age", "sex", "survived")]
# ¿Cúantos NA tengo en la base de datos?
sum(is.na(Titanic))## [1] 266
## class age sex survived
## 1 264 0 1
## 'data.frame': 1046 obs. of 4 variables:
## $ class : int 1 1 1 1 1 1 1 1 1 1 ...
## $ age : num 29 0.917 2 30 25 ...
## $ sex : chr "female" "male" "female" "male" ...
## $ survived: int 1 1 0 0 0 1 1 0 1 0 ...
## - attr(*, "na.action")= 'omit' Named int [1:264] 16 38 41 47 60 70 71 75 81 107 ...
## ..- attr(*, "names")= chr [1:264] "16" "38" "41" "47" ...
## n= 1046
##
## node), split, n, loss, yval, (yprob)
## * denotes terminal node
##
## 1) root 1046 427 0 (0.59177820 0.40822180)
## 2) sex=male 658 135 0 (0.79483283 0.20516717)
## 4) age>=9.5 615 110 0 (0.82113821 0.17886179) *
## 5) age< 9.5 43 18 1 (0.41860465 0.58139535)
## 10) class=3 29 11 0 (0.62068966 0.37931034) *
## 11) class=1,2 14 0 1 (0.00000000 1.00000000) *
## 3) sex=female 388 96 1 (0.24742268 0.75257732)
## 6) class=3 152 72 0 (0.52631579 0.47368421)
## 12) age>=1.5 145 66 0 (0.54482759 0.45517241) *
## 13) age< 1.5 7 1 1 (0.14285714 0.85714286) *
## 7) class=1,2 236 16 1 (0.06779661 0.93220339) *
## diagnosis radius_mean texture_mean perimeter_mean
## Length:569 Min. : 6.981 Min. : 9.71 Min. : 43.79
## Class :character 1st Qu.:11.700 1st Qu.:16.17 1st Qu.: 75.17
## Mode :character Median :13.370 Median :18.84 Median : 86.24
## Mean :14.127 Mean :19.29 Mean : 91.97
## 3rd Qu.:15.780 3rd Qu.:21.80 3rd Qu.:104.10
## Max. :28.110 Max. :39.28 Max. :188.50
## area_mean smoothness_mean compactness_mean concavity_mean
## Min. : 143.5 Min. :0.05263 Min. :0.01938 Min. :0.00000
## 1st Qu.: 420.3 1st Qu.:0.08637 1st Qu.:0.06492 1st Qu.:0.02956
## Median : 551.1 Median :0.09587 Median :0.09263 Median :0.06154
## Mean : 654.9 Mean :0.09636 Mean :0.10434 Mean :0.08880
## 3rd Qu.: 782.7 3rd Qu.:0.10530 3rd Qu.:0.13040 3rd Qu.:0.13070
## Max. :2501.0 Max. :0.16340 Max. :0.34540 Max. :0.42680
## concave.points_mean symmetry_mean fractal_dimension_mean radius_se
## Min. :0.00000 Min. :0.1060 Min. :0.04996 Min. :0.1115
## 1st Qu.:0.02031 1st Qu.:0.1619 1st Qu.:0.05770 1st Qu.:0.2324
## Median :0.03350 Median :0.1792 Median :0.06154 Median :0.3242
## Mean :0.04892 Mean :0.1812 Mean :0.06280 Mean :0.4052
## 3rd Qu.:0.07400 3rd Qu.:0.1957 3rd Qu.:0.06612 3rd Qu.:0.4789
## Max. :0.20120 Max. :0.3040 Max. :0.09744 Max. :2.8730
## texture_se perimeter_se area_se smoothness_se
## Min. :0.3602 Min. : 0.757 Min. : 6.802 Min. :0.001713
## 1st Qu.:0.8339 1st Qu.: 1.606 1st Qu.: 17.850 1st Qu.:0.005169
## Median :1.1080 Median : 2.287 Median : 24.530 Median :0.006380
## Mean :1.2169 Mean : 2.866 Mean : 40.337 Mean :0.007041
## 3rd Qu.:1.4740 3rd Qu.: 3.357 3rd Qu.: 45.190 3rd Qu.:0.008146
## Max. :4.8850 Max. :21.980 Max. :542.200 Max. :0.031130
## compactness_se concavity_se concave.points_se symmetry_se
## Min. :0.002252 Min. :0.00000 Min. :0.000000 Min. :0.007882
## 1st Qu.:0.013080 1st Qu.:0.01509 1st Qu.:0.007638 1st Qu.:0.015160
## Median :0.020450 Median :0.02589 Median :0.010930 Median :0.018730
## Mean :0.025478 Mean :0.03189 Mean :0.011796 Mean :0.020542
## 3rd Qu.:0.032450 3rd Qu.:0.04205 3rd Qu.:0.014710 3rd Qu.:0.023480
## Max. :0.135400 Max. :0.39600 Max. :0.052790 Max. :0.078950
## fractal_dimension_se radius_worst texture_worst perimeter_worst
## Min. :0.0008948 Min. : 7.93 Min. :12.02 Min. : 50.41
## 1st Qu.:0.0022480 1st Qu.:13.01 1st Qu.:21.08 1st Qu.: 84.11
## Median :0.0031870 Median :14.97 Median :25.41 Median : 97.66
## Mean :0.0037949 Mean :16.27 Mean :25.68 Mean :107.26
## 3rd Qu.:0.0045580 3rd Qu.:18.79 3rd Qu.:29.72 3rd Qu.:125.40
## Max. :0.0298400 Max. :36.04 Max. :49.54 Max. :251.20
## area_worst smoothness_worst compactness_worst concavity_worst
## Min. : 185.2 Min. :0.07117 Min. :0.02729 Min. :0.0000
## 1st Qu.: 515.3 1st Qu.:0.11660 1st Qu.:0.14720 1st Qu.:0.1145
## Median : 686.5 Median :0.13130 Median :0.21190 Median :0.2267
## Mean : 880.6 Mean :0.13237 Mean :0.25427 Mean :0.2722
## 3rd Qu.:1084.0 3rd Qu.:0.14600 3rd Qu.:0.33910 3rd Qu.:0.3829
## Max. :4254.0 Max. :0.22260 Max. :1.05800 Max. :1.2520
## concave.points_worst symmetry_worst fractal_dimension_worst
## Min. :0.00000 Min. :0.1565 Min. :0.05504
## 1st Qu.:0.06493 1st Qu.:0.2504 1st Qu.:0.07146
## Median :0.09993 Median :0.2822 Median :0.08004
## Mean :0.11461 Mean :0.2901 Mean :0.08395
## 3rd Qu.:0.16140 3rd Qu.:0.3179 3rd Qu.:0.09208
## Max. :0.29100 Max. :0.6638 Max. :0.20750
## diagnosis n
## 1 B 357
## 2 M 212
library(rpart)
library(rpart.plot)
arbol2 <- rpart(formula = diagnosis ~ ., data=cancer_de_mama)
arbol2 ## n= 569
##
## node), split, n, loss, yval, (yprob)
## * denotes terminal node
##
## 1) root 569 212 B (0.62741652 0.37258348)
## 2) radius_worst< 16.795 379 33 B (0.91292876 0.08707124)
## 4) concave.points_worst< 0.1358 333 5 B (0.98498498 0.01501502) *
## 5) concave.points_worst>=0.1358 46 18 M (0.39130435 0.60869565)
## 10) texture_worst< 25.67 19 4 B (0.78947368 0.21052632) *
## 11) texture_worst>=25.67 27 3 M (0.11111111 0.88888889) *
## 3) radius_worst>=16.795 190 11 M (0.05789474 0.94210526) *
## BillNo Itemname Quantity Date
## Length:522064 Length:522064 Min. :-9600.00 Length:522064
## Class :character Class :character 1st Qu.: 1.00 Class :character
## Mode :character Mode :character Median : 3.00 Mode :character
## Mean : 10.09
## 3rd Qu.: 10.00
## Max. :80995.00
##
## Hour Price CustomerID Country
## Length:522064 Min. :-11062.060 Min. :12346 Length:522064
## Class :character 1st Qu.: 1.250 1st Qu.:13950 Class :character
## Mode :character Median : 2.080 Median :15265 Mode :character
## Mean : 3.827 Mean :15317
## 3rd Qu.: 4.130 3rd Qu.:16837
## Max. : 13541.330 Max. :18287
## NA's :134041
## Total
## Min. :-11062.06
## 1st Qu.: 3.75
## Median : 9.78
## Mean : 19.69
## 3rd Qu.: 17.40
## Max. :168469.60
##
#count(bd,BillNo, sort = TRUE)
#count(bd,Itemname, sort = TRUE)
#count(bd,Date, sort = TRUE)
#count(bd,Hour, sort = TRUE)
#count(bd,Country, sort = TRUE)Observaciones:
## [1] 134041
## BillNo Itemname Quantity Date Hour Price CustomerID
## 0 0 0 0 0 0 134041
## Country Total
## 0 0
#Eliminar NA
bd <- na.omit(bd)
# Eliminar totales negativos
bd <- bd[bd$Total>0,]
# Identificar outliers
boxplot(bd$Total, horizontal=TRUE)Observaciones: 4. Tenemos outliers en Total.
# Obtener cantidad de visitas por cliente
Visitas<- group_by(bd,CustomerID) %>%
summarize(Visitas=n_distinct(BillNo))
# Obtener el total por ticket
ticket_promedio <- aggregate(Total ~ CustomerID+BillNo, data=bd, sum)
# Obtener el ticket promedio
ticket_promedio <- aggregate(Total ~ CustomerID, data=ticket_promedio, mean)
# Juntar las tablas Visitas y Ticket Promedio
objetos<- merge(Visitas, ticket_promedio, by="CustomerID")
# Llamar a los renglones como CustomerID
rownames(objetos) <- objetos$CustomerID
# Eliminar columna CustomerID
objetos<-subset(objetos, select=-c(CustomerID))
# Eliminar datos fuera de los normal
# Los datos fuera de lo normal estan fuera de los siguientes limites:
#Limite inferior = Q1 - 1.5*IQR
#Limite superior = Q3 + 1.5*IQR
#Q1:Cuartil 1, Q3: Cuartil 3, IQR=Rango Intercuartil
# Columna Visitas
IQR_V <- IQR(objetos$Visitas)
IQR_V## [1] 4
## Visitas Total
## Min. : 1.000 Min. : 3.45
## 1st Qu.: 1.000 1st Qu.: 178.30
## Median : 2.000 Median : 292.00
## Mean : 4.227 Mean : 415.62
## 3rd Qu.: 5.000 3rd Qu.: 426.63
## Max. :209.000 Max. :84236.25
## [1] -5
## [1] 11
objetos <- objetos[objetos$Visitas <=11,]
# Renombrar columnas
colnames(objetos)<-c("Visitas", "TicketPromedio")
# Ticket Promedio
IQR_TP<- IQR(objetos$TicketPromedio)
IQR_TP## [1] 243.3733
## [1] -186.76
## [1] 791.69
library (tidyverse)
library (foreign)
library (ggplot2)
library(dplyr)
library(scales)
library(ggrepel)
library(readr)
library(readxl)
library(rpart)
library(rpart.plot)
library(factoextra)
claims <- read.csv("C:\\Users\\enriq\\OneDrive\\Documentos\\Datos a Desiciones\\Modulo4\\ClaimsData2018.csv")
transactions <- read.csv("C:\\Users\\enriq\\OneDrive\\Documentos\\Datos a Desiciones\\Modulo4\\TransactionsSummary2018.csv")
datos <- as.data.frame(claims)## ClaimID TotalPaid TotalReserves TotalRecovery
## Min. : 650915 Min. : -270 Min. : 0 Min. : 0.00
## 1st Qu.: 811125 1st Qu.: 60 1st Qu.: 0 1st Qu.: 0.00
## Median : 844626 Median : 235 Median : 0 Median : 0.00
## Mean :10149151 Mean : 6746 Mean : 2233 Mean : 68.88
## 3rd Qu.:22716506 3rd Qu.: 938 3rd Qu.: 0 3rd Qu.: 0.00
## Max. :62203891 Max. :4527291 Max. :2069575 Max. :130541.03
## IndemnityPaid OtherPaid ClaimStatus IncidentDate
## Min. : -475 Min. : -7820 Length:134004 Length:134004
## 1st Qu.: 0 1st Qu.: 58 Class :character Class :character
## Median : 0 Median : 230 Mode :character Mode :character
## Mean : 3061 Mean : 3685
## 3rd Qu.: 0 3rd Qu.: 855
## Max. :640732 Max. :4129915
## IncidentDescription ReturnToWorkDate AverageWeeklyWage ClaimantOpenedDate
## Length:134004 Length:134004 Length:134004 Length:134004
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## ClaimantClosedDate EmployerNotificationDate ReceivedDate
## Length:134004 Length:134004 Length:134004
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## IsDenied ClaimantAge_at_DOI Gender ClaimantType
## Min. :0.00000 Length:134004 Length:134004 Length:134004
## 1st Qu.:0.00000 Class :character Class :character Class :character
## Median :0.00000 Mode :character Mode :character Mode :character
## Mean :0.04474
## 3rd Qu.:0.00000
## Max. :1.00000
## Injuryture BodyPartRegion BodyPart
## Length:134004 Length:134004 Length:134004
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## ClaimID BillReviewALE Hospital PhysicianOutpatient
## Min. : 633915 Min. : -456.0 Min. : -12570.4 Min. : -4655.7
## 1st Qu.: 793224 1st Qu.: 16.0 1st Qu.: 193.9 1st Qu.: 107.6
## Median : 828263 Median : 32.0 Median : 559.1 Median : 221.6
## Mean :10112865 Mean : 191.2 Mean : 4394.7 Mean : 1752.3
## 3rd Qu.:22700126 3rd Qu.: 80.0 3rd Qu.: 2253.4 3rd Qu.: 710.5
## Max. :62246496 Max. :56475.3 Max. :2759604.0 Max. :1481468.5
## NA's :61857 NA's :67254 NA's :6978
## Rx
## Min. : -469.5
## 1st Qu.: 23.3
## Median : 58.3
## Mean : 1140.4
## 3rd Qu.: 174.5
## Max. :631635.5
## NA's :67744
Modificamos el tipo de variable, de caracter a fecha
claims$ClaimantOpenedDate<-as.Date(claims$ClaimantOpenedDate,format="%d/%m/%Y")
claims$ClaimantClosedDate<-as.Date(claims$ClaimantClosedDate,format="%d/%m/%Y")
claims$IncidentDate<-as.Date(claims$IncidentDate,format="%d/%m/%Y")
claims$ReturnToWorkDate<-as.Date(claims$ReturnToWorkDate,format="%d/%m/%Y")
claims$EmployerNotificationDate<-as.Date(claims$EmployerNotificationDate,format="%d/%m/%Y")
claims$ReceivedDate<-as.Date(claims$ReceivedDate,format="%d/%m/%Y")Convertimos el tipo de variable de caracter a numerica
claims<-claims%>%mutate(AverageWeeklyWage=as.numeric(AverageWeeklyWage))
claims<-claims%>%mutate(ClaimantAge_at_DOI=as.numeric(ClaimantAge_at_DOI))Eliminamos las edades iguales o menores a cero
Unificamos las bases de datos con un left join en un nuevo df
## ClaimID TotalPaid TotalReserves TotalRecovery
## Min. : 650915 Min. : -22 Min. : 0 Min. : 0.00
## 1st Qu.: 814283 1st Qu.: 82 1st Qu.: 0 1st Qu.: 0.00
## Median : 845571 Median : 281 Median : 0 Median : 0.00
## Mean :12146395 Mean : 8368 Mean : 3365 Mean : 68.22
## 3rd Qu.:22725794 3rd Qu.: 1229 3rd Qu.: 0 3rd Qu.: 0.00
## Max. :62203891 Max. :4527291 Max. :2069575 Max. :130541.03
##
## IndemnityPaid OtherPaid ClaimStatus IncidentDate
## Min. : -475 Min. : -22 Length:88833 Min. :1968-09-27
## 1st Qu.: 0 1st Qu.: 79 Class :character 1st Qu.:2003-08-05
## Median : 0 Median : 275 Mode :character Median :2007-02-27
## Mean : 3698 Mean : 4670 Mean :2006-10-11
## 3rd Qu.: 0 3rd Qu.: 1126 3rd Qu.:2010-11-17
## Max. :640732 Max. :4129915 Max. :2014-06-27
##
## IncidentDescription ReturnToWorkDate AverageWeeklyWage
## Length:88833 Min. :1984-01-01 Min. : 0.0
## Class :character 1st Qu.:2005-12-09 1st Qu.: 300.0
## Mode :character Median :2009-04-29 Median : 502.6
## Mean :2008-07-19 Mean : 629.0
## 3rd Qu.:2012-02-14 3rd Qu.: 684.8
## Max. :2015-05-07 Max. :2024000.0
## NA's :30493 NA's :50480
## ClaimantOpenedDate ClaimantClosedDate EmployerNotificationDate
## Min. :1968-09-27 Min. :1999-06-01 Min. :1972-09-10
## 1st Qu.:2003-09-18 1st Qu.:2005-10-04 1st Qu.:2004-03-31
## Median :2007-04-18 Median :2008-12-11 Median :2007-09-26
## Mean :2006-11-22 Mean :2008-10-09 Mean :2007-10-07
## 3rd Qu.:2010-12-13 3rd Qu.:2011-06-10 3rd Qu.:2011-06-01
## Max. :2014-06-30 Max. :2014-06-30 Max. :9988-02-21
## NA's :4637 NA's :11756
## ReceivedDate IsDenied ClaimantAge_at_DOI Gender
## Min. :1968-09-27 Min. :0.00000 Min. : 0.00 Length:88833
## 1st Qu.:2003-09-16 1st Qu.:0.00000 1st Qu.:33.00 Class :character
## Median :2007-03-28 Median :0.00000 Median :42.00 Mode :character
## Mean :2007-01-28 Mean :0.05227 Mean :42.05
## 3rd Qu.:2010-12-17 3rd Qu.:0.00000 3rd Qu.:51.00
## Max. :5202-01-10 Max. :1.00000 Max. :94.00
##
## ClaimantType Injuryture BodyPartRegion BodyPart
## Length:88833 Length:88833 Length:88833 Length:88833
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## BillReviewALE Hospital PhysicianOutpatient Rx
## Min. : -448.0 Min. : -12570.4 Min. : -549.5 Min. : -160.7
## 1st Qu.: 16.0 1st Qu.: 205.4 1st Qu.: 105.8 1st Qu.: 22.4
## Median : 24.0 Median : 600.9 Median : 217.3 Median : 60.1
## Mean : 188.4 Mean : 5005.3 Mean : 1773.7 Mean : 1625.4
## 3rd Qu.: 64.0 3rd Qu.: 2298.7 3rd Qu.: 673.7 3rd Qu.: 183.0
## Max. :46055.3 Max. :2759604.0 Max. :1219766.6 Max. :631635.5
## NA's :70866 NA's :75592 NA's :56446 NA's :76768
## ClaimID TotalPaid TotalReserves TotalRecovery IndemnityPaid OtherPaid
## 1 650915 11947.55 0 0 243.65 11703.90
## 2 650916 0.00 0 0 0.00 0.00
## 3 650917 9295.89 0 0 0.00 9295.89
## 4 650918 1026.29 0 0 0.00 1026.29
## 5 650919 43108.03 0 0 40000.00 3108.03
## 6 650920 331.90 0 0 0.00 331.90
## ClaimStatus IncidentDate
## 1 C 2009-06-17
## 2 C 2009-06-26
## 3 C 2009-06-25
## 4 C 2009-06-12
## 5 C 2009-06-29
## 6 C 2009-06-25
## IncidentDescription
## 1 Employee was moving concrete rings and installing a meter. He strained lower back.
## 2 Employee was pulling lining. He felt a pop in the back causing a strain.
## 3 Employee was in the restroom. He heard a scream from another restroom that startled him and he fell on his left hand causing a fracture. ()
## 4 Employee was unloading truck using a pallet jack to unload heavy equipment. Heavy load caused him to lose balance, and he struck his right shoulder on door jamb causing unspecified injury. ()
## 5 Employee was leaning over to pick up a piece of paper. She fell out of rolling chair causing pain to lower back. Dx: lower back strain/buldging disc. ()
## 6 Employee was performing general lawn care maintence and outdoor tours and educatiol programs. He sustained a bite of right calf causing infection.
## ReturnToWorkDate AverageWeeklyWage ClaimantOpenedDate ClaimantClosedDate
## 1 2009-12-08 639.59 2009-07-02 2010-07-20
## 2 2009-06-26 NA 2009-07-02 2009-11-25
## 3 2009-07-13 1649.00 2009-07-02 2010-03-30
## 4 2009-06-12 NA 2009-07-02 2010-03-29
## 5 <NA> 539.00 2009-07-02 2011-05-06
## 6 2009-06-25 NA 2009-07-02 2009-11-25
## EmployerNotificationDate ReceivedDate IsDenied ClaimantAge_at_DOI Gender
## 1 2009-06-29 2009-07-02 0 49 Male
## 2 2009-07-01 2009-07-02 0 49 Male
## 3 2009-06-25 2009-07-02 0 47 Male
## 4 2009-06-23 2009-07-02 0 61 Male
## 5 2009-07-01 2009-07-02 0 41 Female
## 6 2009-06-25 2009-07-02 0 28 Male
## ClaimantType Injuryture BodyPartRegion BodyPart BillReviewALE
## 1 Indemnity Strain Trunk Lower Back Area NA
## 2 Medical Only Strain Trunk Lower Back Area NA
## 3 Indemnity Fracture Upper Extremities Hand NA
## 4 Medical Only Contusion Upper Extremities Shoulder(S) NA
## 5 Indemnity Strain Trunk Lower Back Area NA
## 6 Medical Only Puncture Lower Extremities Lower Leg NA
## Hospital PhysicianOutpatient Rx
## 1 NA NA NA
## 2 NA NA NA
## 3 NA NA NA
## 4 NA NA NA
## 5 NA NA NA
## 6 NA NA NA
regresion <- lm(TotalPaid ~ Gender + Days + ClaimantType
+ Injuryture + BodyPartRegion + BodyPart, data= df)
summary(regresion)##
## Call:
## lm(formula = TotalPaid ~ Gender + Days + ClaimantType + Injuryture +
## BodyPartRegion + BodyPart, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36581 -4458 -4 2169 1372311
##
## Coefficients: (7 not defined because of singularities)
## Estimate
## (Intercept) 4.719e+03
## GenderMale 1.889e+02
## GenderNot Available 6.501e+03
## Days 3.152e+00
## ClaimantTypeMedical Only -1.576e+04
## ClaimantTypeReport Only -1.527e+04
## InjurytureAll Other Cumulative Injury, NOC 3.102e+03
## InjurytureAll Other Occupatiol Disease Injury, NOC 1.180e+04
## InjurytureAll Other Specific Injuries, Noc 2.616e+03
## InjurytureAmputation 8.228e+03
## InjurytureAngi Pectoris 3.261e+03
## InjurytureAsbestosis 1.150e+04
## InjurytureAsphyxiation 2.083e+04
## InjurytureBlack Lung 4.914e+03
## InjurytureBurn 6.462e+03
## InjurytureCancer 2.554e+04
## InjurytureCarpal Tunnel Syndrome 4.553e+03
## InjurytureConcussion 7.261e+03
## InjurytureContagious Disease 3.118e+03
## InjurytureContusion 4.798e+03
## InjurytureCrushing 6.400e+03
## InjurytureDermatitis 4.291e+03
## InjurytureDislocation 6.376e+03
## InjurytureDust Disease, NOC 4.285e+03
## InjurytureElectric Shock 3.152e+03
## InjurytureForeign Body 3.639e+03
## InjurytureFracture 8.861e+03
## InjurytureFreezing 1.705e+03
## InjurytureHearing Loss Or Impairment -3.014e+03
## InjurytureHeat Prostration 2.554e+03
## InjurytureHernia 2.462e+01
## InjurytureInfection 4.239e+03
## InjurytureInflammation 5.140e+03
## InjurytureLaceration 5.116e+03
## InjurytureLoss of Hearing 3.644e+03
## InjurytureMental Disorder 8.621e+03
## InjurytureMental Stress -1.509e+02
## InjurytureMultiple Injuries Including Both Physical and Psychological 8.474e+03
## InjurytureMultiple Physical Injuries Only 7.203e+03
## InjurytureMyocardial Infarction 7.457e+03
## InjurytureNo Physical Injury 4.739e+03
## InjurytureNon-Standard Code 1.388e+03
## InjurytureNot Available 5.863e+03
## InjuryturePoisoning?Chemical (Other Than Metals) 3.501e+03
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 4.241e+03
## InjuryturePuncture 4.969e+03
## InjurytureRadiation 8.736e+03
## InjurytureRespiratory Disorders 4.327e+03
## InjurytureRupture 1.390e+04
## InjurytureSeverance 1.958e+04
## InjurytureSilicosis 5.136e+03
## InjurytureSprain 5.737e+03
## InjurytureStrain 4.869e+03
## InjurytureSyncope 3.910e+03
## InjurytureVascular 4.310e+03
## InjurytureVDT-Related Disease -1.795e+03
## InjurytureVision Loss 4.294e+03
## BodyPartRegionLower Extremities 5.119e+03
## BodyPartRegionMultiple Body Parts 1.035e+04
## BodyPartRegionNeck 1.746e+04
## BodyPartRegionNon-Standard Code -1.470e+03
## BodyPartRegionNot Available 6.237e+03
## BodyPartRegionTrunk 3.038e+03
## BodyPartRegionUpper Extremities 3.464e+03
## BodyPartAnkle -2.648e+03
## BodyPartArtificial Appliance -7.387e+03
## BodyPartBody Systems and Multiple Body Systems -6.359e+03
## BodyPartBrain 1.309e+04
## BodyPartButtocks 1.175e+03
## BodyPartChest 9.252e+02
## BodyPartDisc-Trunk 3.347e+03
## BodyPartEar(S) 5.084e+03
## BodyPartElbow 6.802e+02
## BodyPartEyes 4.177e+03
## BodyPartFacial Bones 3.602e+03
## BodyPartFinger(S) -1.011e+03
## BodyPartFoot -2.643e+03
## BodyPartGreat Toe -2.662e+03
## BodyPartHand 1.200e+02
## BodyPartHeart -3.209e+03
## BodyPartHip -2.082e+02
## BodyPartInsufficient Info to Properly Identify?Unclassified -5.929e+03
## BodyPartInterl Organs 5.753e+02
## BodyPartKnee 5.199e+02
## BodyPartLarynx -1.811e+04
## BodyPartLower Arm 1.011e+03
## BodyPartLower Back Area 2.666e+03
## BodyPartLower Leg -1.442e+03
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 3.822e+03
## BodyPartLungs 1.597e+03
## BodyPartMouth 2.736e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) -4.729e+03
## BodyPartMultiple Head Injury 4.727e+03
## BodyPartMultiple Lower Extremities 9.249e+02
## BodyPartMultiple Neck Injury -1.180e+04
## BodyPartMultiple Trunk -2.427e+03
## BodyPartMultiple Upper Extremities -2.565e+02
## BodyPartNo Physical Injury -6.257e+03
## BodyPartNon-Standard Code NA
## BodyPartNose 4.225e+03
## BodyPartNot Available NA
## BodyPartPelvis 4.388e+03
## BodyPartSacrum And Coccyx -1.364e+03
## BodyPartShoulder(S) 4.446e+03
## BodyPartSkull 5.343e+03
## BodyPartSoft Tissue-Head 5.954e+03
## BodyPartSoft Tissue-Neck -1.265e+04
## BodyPartSpil Cord-Trunk -1.577e+03
## BodyPartTeeth NA
## BodyPartThumb -6.400e+02
## BodyPartToes -3.139e+03
## BodyPartTrachea -1.612e+04
## BodyPartUpper Arm 7.550e+02
## BodyPartUpper Back Area 1.287e+03
## BodyPartUpper Leg NA
## BodyPartVertebrae NA
## BodyPartWhole Body NA
## BodyPartWrist NA
## Std. Error
## (Intercept) 9.639e+03
## GenderMale 1.522e+02
## GenderNot Available 9.853e+02
## Days 8.391e-02
## ClaimantTypeMedical Only 1.857e+02
## ClaimantTypeReport Only 3.307e+02
## InjurytureAll Other Cumulative Injury, NOC 1.017e+04
## InjurytureAll Other Occupatiol Disease Injury, NOC 1.092e+04
## InjurytureAll Other Specific Injuries, Noc 9.534e+03
## InjurytureAmputation 9.995e+03
## InjurytureAngi Pectoris 1.088e+04
## InjurytureAsbestosis 9.972e+03
## InjurytureAsphyxiation 1.149e+04
## InjurytureBlack Lung 1.557e+04
## InjurytureBurn 9.555e+03
## InjurytureCancer 1.291e+04
## InjurytureCarpal Tunnel Syndrome 9.580e+03
## InjurytureConcussion 9.578e+03
## InjurytureContagious Disease 9.626e+03
## InjurytureContusion 9.531e+03
## InjurytureCrushing 9.572e+03
## InjurytureDermatitis 9.550e+03
## InjurytureDislocation 9.605e+03
## InjurytureDust Disease, NOC 1.066e+04
## InjurytureElectric Shock 9.777e+03
## InjurytureForeign Body 9.547e+03
## InjurytureFracture 9.540e+03
## InjurytureFreezing 1.429e+04
## InjurytureHearing Loss Or Impairment 9.950e+03
## InjurytureHeat Prostration 9.695e+03
## InjurytureHernia 9.665e+03
## InjurytureInfection 9.609e+03
## InjurytureInflammation 9.551e+03
## InjurytureLaceration 9.533e+03
## InjurytureLoss of Hearing 1.017e+04
## InjurytureMental Disorder 1.173e+04
## InjurytureMental Stress 9.691e+03
## InjurytureMultiple Injuries Including Both Physical and Psychological 1.005e+04
## InjurytureMultiple Physical Injuries Only 9.543e+03
## InjurytureMyocardial Infarction 1.095e+04
## InjurytureNo Physical Injury 9.545e+03
## InjurytureNon-Standard Code 9.545e+03
## InjurytureNot Available 9.601e+03
## InjuryturePoisoning?Chemical (Other Than Metals) 9.681e+03
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 9.748e+03
## InjuryturePuncture 9.537e+03
## InjurytureRadiation 1.060e+04
## InjurytureRespiratory Disorders 9.587e+03
## InjurytureRupture 9.786e+03
## InjurytureSeverance 1.052e+04
## InjurytureSilicosis 1.556e+04
## InjurytureSprain 9.533e+03
## InjurytureStrain 9.530e+03
## InjurytureSyncope 9.732e+03
## InjurytureVascular 1.167e+04
## InjurytureVDT-Related Disease 1.783e+04
## InjurytureVision Loss 1.028e+04
## BodyPartRegionLower Extremities 1.662e+03
## BodyPartRegionMultiple Body Parts 2.749e+03
## BodyPartRegionNeck 4.977e+03
## BodyPartRegionNon-Standard Code 1.585e+03
## BodyPartRegionNot Available 8.199e+03
## BodyPartRegionTrunk 1.604e+03
## BodyPartRegionUpper Extremities 1.486e+03
## BodyPartAnkle 9.093e+02
## BodyPartArtificial Appliance 9.008e+03
## BodyPartBody Systems and Multiple Body Systems 2.591e+03
## BodyPartBrain 4.122e+03
## BodyPartButtocks 1.390e+03
## BodyPartChest 8.896e+02
## BodyPartDisc-Trunk 1.248e+03
## BodyPartEar(S) 1.912e+03
## BodyPartElbow 6.520e+02
## BodyPartEyes 1.513e+03
## BodyPartFacial Bones 1.648e+03
## BodyPartFinger(S) 4.682e+02
## BodyPartFoot 9.329e+02
## BodyPartGreat Toe 1.856e+03
## BodyPartHand 4.759e+02
## BodyPartHeart 4.653e+03
## BodyPartHip 1.072e+03
## BodyPartInsufficient Info to Properly Identify?Unclassified 2.541e+03
## BodyPartInterl Organs 1.870e+03
## BodyPartKnee 8.646e+02
## BodyPartLarynx 7.785e+03
## BodyPartLower Arm 5.743e+02
## BodyPartLower Back Area 7.431e+02
## BodyPartLower Leg 9.503e+02
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 1.016e+03
## BodyPartLungs 1.450e+03
## BodyPartMouth 1.809e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) 2.352e+03
## BodyPartMultiple Head Injury 1.533e+03
## BodyPartMultiple Lower Extremities 1.169e+03
## BodyPartMultiple Neck Injury 4.806e+03
## BodyPartMultiple Trunk 1.978e+03
## BodyPartMultiple Upper Extremities 7.923e+02
## BodyPartNo Physical Injury 2.477e+03
## BodyPartNon-Standard Code NA
## BodyPartNose 1.810e+03
## BodyPartNot Available NA
## BodyPartPelvis 1.978e+03
## BodyPartSacrum And Coccyx 2.796e+03
## BodyPartShoulder(S) 4.958e+02
## BodyPartSkull 1.665e+03
## BodyPartSoft Tissue-Head 1.633e+03
## BodyPartSoft Tissue-Neck 4.793e+03
## BodyPartSpil Cord-Trunk 1.408e+03
## BodyPartTeeth NA
## BodyPartThumb 6.275e+02
## BodyPartToes 1.312e+03
## BodyPartTrachea 7.803e+03
## BodyPartUpper Arm 7.016e+02
## BodyPartUpper Back Area 1.053e+03
## BodyPartUpper Leg NA
## BodyPartVertebrae NA
## BodyPartWhole Body NA
## BodyPartWrist NA
## t value
## (Intercept) 0.490
## GenderMale 1.241
## GenderNot Available 6.598
## Days 37.564
## ClaimantTypeMedical Only -84.874
## ClaimantTypeReport Only -46.161
## InjurytureAll Other Cumulative Injury, NOC 0.305
## InjurytureAll Other Occupatiol Disease Injury, NOC 1.081
## InjurytureAll Other Specific Injuries, Noc 0.274
## InjurytureAmputation 0.823
## InjurytureAngi Pectoris 0.300
## InjurytureAsbestosis 1.154
## InjurytureAsphyxiation 1.813
## InjurytureBlack Lung 0.316
## InjurytureBurn 0.676
## InjurytureCancer 1.979
## InjurytureCarpal Tunnel Syndrome 0.475
## InjurytureConcussion 0.758
## InjurytureContagious Disease 0.324
## InjurytureContusion 0.503
## InjurytureCrushing 0.669
## InjurytureDermatitis 0.449
## InjurytureDislocation 0.664
## InjurytureDust Disease, NOC 0.402
## InjurytureElectric Shock 0.322
## InjurytureForeign Body 0.381
## InjurytureFracture 0.929
## InjurytureFreezing 0.119
## InjurytureHearing Loss Or Impairment -0.303
## InjurytureHeat Prostration 0.263
## InjurytureHernia 0.003
## InjurytureInfection 0.441
## InjurytureInflammation 0.538
## InjurytureLaceration 0.537
## InjurytureLoss of Hearing 0.358
## InjurytureMental Disorder 0.735
## InjurytureMental Stress -0.016
## InjurytureMultiple Injuries Including Both Physical and Psychological 0.843
## InjurytureMultiple Physical Injuries Only 0.755
## InjurytureMyocardial Infarction 0.681
## InjurytureNo Physical Injury 0.496
## InjurytureNon-Standard Code 0.145
## InjurytureNot Available 0.611
## InjuryturePoisoning?Chemical (Other Than Metals) 0.362
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 0.435
## InjuryturePuncture 0.521
## InjurytureRadiation 0.824
## InjurytureRespiratory Disorders 0.451
## InjurytureRupture 1.420
## InjurytureSeverance 1.862
## InjurytureSilicosis 0.330
## InjurytureSprain 0.602
## InjurytureStrain 0.511
## InjurytureSyncope 0.402
## InjurytureVascular 0.369
## InjurytureVDT-Related Disease -0.101
## InjurytureVision Loss 0.418
## BodyPartRegionLower Extremities 3.079
## BodyPartRegionMultiple Body Parts 3.766
## BodyPartRegionNeck 3.508
## BodyPartRegionNon-Standard Code -0.927
## BodyPartRegionNot Available 0.761
## BodyPartRegionTrunk 1.894
## BodyPartRegionUpper Extremities 2.332
## BodyPartAnkle -2.912
## BodyPartArtificial Appliance -0.820
## BodyPartBody Systems and Multiple Body Systems -2.455
## BodyPartBrain 3.176
## BodyPartButtocks 0.846
## BodyPartChest 1.040
## BodyPartDisc-Trunk 2.681
## BodyPartEar(S) 2.659
## BodyPartElbow 1.043
## BodyPartEyes 2.760
## BodyPartFacial Bones 2.186
## BodyPartFinger(S) -2.159
## BodyPartFoot -2.833
## BodyPartGreat Toe -1.434
## BodyPartHand 0.252
## BodyPartHeart -0.690
## BodyPartHip -0.194
## BodyPartInsufficient Info to Properly Identify?Unclassified -2.333
## BodyPartInterl Organs 0.308
## BodyPartKnee 0.601
## BodyPartLarynx -2.327
## BodyPartLower Arm 1.760
## BodyPartLower Back Area 3.588
## BodyPartLower Leg -1.517
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 3.760
## BodyPartLungs 1.101
## BodyPartMouth 1.513
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) -2.010
## BodyPartMultiple Head Injury 3.083
## BodyPartMultiple Lower Extremities 0.791
## BodyPartMultiple Neck Injury -2.456
## BodyPartMultiple Trunk -1.227
## BodyPartMultiple Upper Extremities -0.324
## BodyPartNo Physical Injury -2.526
## BodyPartNon-Standard Code NA
## BodyPartNose 2.334
## BodyPartNot Available NA
## BodyPartPelvis 2.218
## BodyPartSacrum And Coccyx -0.488
## BodyPartShoulder(S) 8.966
## BodyPartSkull 3.209
## BodyPartSoft Tissue-Head 3.647
## BodyPartSoft Tissue-Neck -2.640
## BodyPartSpil Cord-Trunk -1.121
## BodyPartTeeth NA
## BodyPartThumb -1.020
## BodyPartToes -2.393
## BodyPartTrachea -2.066
## BodyPartUpper Arm 1.076
## BodyPartUpper Back Area 1.222
## BodyPartUpper Leg NA
## BodyPartVertebrae NA
## BodyPartWhole Body NA
## BodyPartWrist NA
## Pr(>|t|)
## (Intercept) 0.624416
## GenderMale 0.214431
## GenderNot Available 4.18e-11
## Days < 2e-16
## ClaimantTypeMedical Only < 2e-16
## ClaimantTypeReport Only < 2e-16
## InjurytureAll Other Cumulative Injury, NOC 0.760316
## InjurytureAll Other Occupatiol Disease Injury, NOC 0.279886
## InjurytureAll Other Specific Injuries, Noc 0.783805
## InjurytureAmputation 0.410381
## InjurytureAngi Pectoris 0.764325
## InjurytureAsbestosis 0.248704
## InjurytureAsphyxiation 0.069869
## InjurytureBlack Lung 0.752292
## InjurytureBurn 0.498863
## InjurytureCancer 0.047863
## InjurytureCarpal Tunnel Syndrome 0.634600
## InjurytureConcussion 0.448390
## InjurytureContagious Disease 0.746027
## InjurytureContusion 0.614654
## InjurytureCrushing 0.503723
## InjurytureDermatitis 0.653175
## InjurytureDislocation 0.506796
## InjurytureDust Disease, NOC 0.687670
## InjurytureElectric Shock 0.747125
## InjurytureForeign Body 0.703049
## InjurytureFracture 0.353000
## InjurytureFreezing 0.905045
## InjurytureHearing Loss Or Impairment 0.761937
## InjurytureHeat Prostration 0.792216
## InjurytureHernia 0.997967
## InjurytureInfection 0.659106
## InjurytureInflammation 0.590456
## InjurytureLaceration 0.591489
## InjurytureLoss of Hearing 0.720178
## InjurytureMental Disorder 0.462361
## InjurytureMental Stress 0.987577
## InjurytureMultiple Injuries Including Both Physical and Psychological 0.398971
## InjurytureMultiple Physical Injuries Only 0.450348
## InjurytureMyocardial Infarction 0.496034
## InjurytureNo Physical Injury 0.619553
## InjurytureNon-Standard Code 0.884410
## InjurytureNot Available 0.541425
## InjuryturePoisoning?Chemical (Other Than Metals) 0.717650
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 0.663499
## InjuryturePuncture 0.602334
## InjurytureRadiation 0.409970
## InjurytureRespiratory Disorders 0.651767
## InjurytureRupture 0.155649
## InjurytureSeverance 0.062630
## InjurytureSilicosis 0.741385
## InjurytureSprain 0.547297
## InjurytureStrain 0.609402
## InjurytureSyncope 0.687865
## InjurytureVascular 0.711966
## InjurytureVDT-Related Disease 0.919815
## InjurytureVision Loss 0.676082
## BodyPartRegionLower Extremities 0.002077
## BodyPartRegionMultiple Body Parts 0.000166
## BodyPartRegionNeck 0.000451
## BodyPartRegionNon-Standard Code 0.353802
## BodyPartRegionNot Available 0.446839
## BodyPartRegionTrunk 0.058240
## BodyPartRegionUpper Extremities 0.019719
## BodyPartAnkle 0.003593
## BodyPartArtificial Appliance 0.412221
## BodyPartBody Systems and Multiple Body Systems 0.014108
## BodyPartBrain 0.001492
## BodyPartButtocks 0.397769
## BodyPartChest 0.298345
## BodyPartDisc-Trunk 0.007340
## BodyPartEar(S) 0.007832
## BodyPartElbow 0.296788
## BodyPartEyes 0.005786
## BodyPartFacial Bones 0.028787
## BodyPartFinger(S) 0.030861
## BodyPartFoot 0.004607
## BodyPartGreat Toe 0.151448
## BodyPartHand 0.800953
## BodyPartHeart 0.490416
## BodyPartHip 0.846059
## BodyPartInsufficient Info to Properly Identify?Unclassified 0.019626
## BodyPartInterl Organs 0.758366
## BodyPartKnee 0.547655
## BodyPartLarynx 0.019993
## BodyPartLower Arm 0.078346
## BodyPartLower Back Area 0.000333
## BodyPartLower Leg 0.129283
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 0.000170
## BodyPartLungs 0.270917
## BodyPartMouth 0.130397
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) 0.044393
## BodyPartMultiple Head Injury 0.002049
## BodyPartMultiple Lower Extremities 0.428973
## BodyPartMultiple Neck Injury 0.014053
## BodyPartMultiple Trunk 0.219773
## BodyPartMultiple Upper Extremities 0.746093
## BodyPartNo Physical Injury 0.011530
## BodyPartNon-Standard Code NA
## BodyPartNose 0.019580
## BodyPartNot Available NA
## BodyPartPelvis 0.026584
## BodyPartSacrum And Coccyx 0.625813
## BodyPartShoulder(S) < 2e-16
## BodyPartSkull 0.001332
## BodyPartSoft Tissue-Head 0.000265
## BodyPartSoft Tissue-Neck 0.008300
## BodyPartSpil Cord-Trunk 0.262491
## BodyPartTeeth NA
## BodyPartThumb 0.307786
## BodyPartToes 0.016731
## BodyPartTrachea 0.038875
## BodyPartUpper Arm 0.281885
## BodyPartUpper Back Area 0.221792
## BodyPartUpper Leg NA
## BodyPartVertebrae NA
## BodyPartWhole Body NA
## BodyPartWrist NA
##
## (Intercept)
## GenderMale
## GenderNot Available ***
## Days ***
## ClaimantTypeMedical Only ***
## ClaimantTypeReport Only ***
## InjurytureAll Other Cumulative Injury, NOC
## InjurytureAll Other Occupatiol Disease Injury, NOC
## InjurytureAll Other Specific Injuries, Noc
## InjurytureAmputation
## InjurytureAngi Pectoris
## InjurytureAsbestosis
## InjurytureAsphyxiation .
## InjurytureBlack Lung
## InjurytureBurn
## InjurytureCancer *
## InjurytureCarpal Tunnel Syndrome
## InjurytureConcussion
## InjurytureContagious Disease
## InjurytureContusion
## InjurytureCrushing
## InjurytureDermatitis
## InjurytureDislocation
## InjurytureDust Disease, NOC
## InjurytureElectric Shock
## InjurytureForeign Body
## InjurytureFracture
## InjurytureFreezing
## InjurytureHearing Loss Or Impairment
## InjurytureHeat Prostration
## InjurytureHernia
## InjurytureInfection
## InjurytureInflammation
## InjurytureLaceration
## InjurytureLoss of Hearing
## InjurytureMental Disorder
## InjurytureMental Stress
## InjurytureMultiple Injuries Including Both Physical and Psychological
## InjurytureMultiple Physical Injuries Only
## InjurytureMyocardial Infarction
## InjurytureNo Physical Injury
## InjurytureNon-Standard Code
## InjurytureNot Available
## InjuryturePoisoning?Chemical (Other Than Metals)
## InjuryturePoisoning?General (NOT OD or Cumulative Injury)
## InjuryturePuncture
## InjurytureRadiation
## InjurytureRespiratory Disorders
## InjurytureRupture
## InjurytureSeverance .
## InjurytureSilicosis
## InjurytureSprain
## InjurytureStrain
## InjurytureSyncope
## InjurytureVascular
## InjurytureVDT-Related Disease
## InjurytureVision Loss
## BodyPartRegionLower Extremities **
## BodyPartRegionMultiple Body Parts ***
## BodyPartRegionNeck ***
## BodyPartRegionNon-Standard Code
## BodyPartRegionNot Available
## BodyPartRegionTrunk .
## BodyPartRegionUpper Extremities *
## BodyPartAnkle **
## BodyPartArtificial Appliance
## BodyPartBody Systems and Multiple Body Systems *
## BodyPartBrain **
## BodyPartButtocks
## BodyPartChest
## BodyPartDisc-Trunk **
## BodyPartEar(S) **
## BodyPartElbow
## BodyPartEyes **
## BodyPartFacial Bones *
## BodyPartFinger(S) *
## BodyPartFoot **
## BodyPartGreat Toe
## BodyPartHand
## BodyPartHeart
## BodyPartHip
## BodyPartInsufficient Info to Properly Identify?Unclassified *
## BodyPartInterl Organs
## BodyPartKnee
## BodyPartLarynx *
## BodyPartLower Arm .
## BodyPartLower Back Area ***
## BodyPartLower Leg
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) ***
## BodyPartLungs
## BodyPartMouth
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) *
## BodyPartMultiple Head Injury **
## BodyPartMultiple Lower Extremities
## BodyPartMultiple Neck Injury *
## BodyPartMultiple Trunk
## BodyPartMultiple Upper Extremities
## BodyPartNo Physical Injury *
## BodyPartNon-Standard Code
## BodyPartNose *
## BodyPartNot Available
## BodyPartPelvis *
## BodyPartSacrum And Coccyx
## BodyPartShoulder(S) ***
## BodyPartSkull **
## BodyPartSoft Tissue-Head ***
## BodyPartSoft Tissue-Neck **
## BodyPartSpil Cord-Trunk
## BodyPartTeeth
## BodyPartThumb
## BodyPartToes *
## BodyPartTrachea *
## BodyPartUpper Arm
## BodyPartUpper Back Area
## BodyPartUpper Leg
## BodyPartVertebrae
## BodyPartWhole Body
## BodyPartWrist
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 21300 on 84085 degrees of freedom
## Multiple R-squared: 0.1245, Adjusted R-squared: 0.1234
## F-statistic: 108.7 on 110 and 84085 DF, p-value: < 2.2e-16
df <- subset(df,
ClaimantType == "Medical Only" |
ClaimantType == "Report Only" |
BodyPart %in% c("Body Systems and Multiple Body Systems", "Brain", "Disc-Trunk", "Eyes",
"Insufficient Info to Properly Identify?Unclassified", "Lower Back Area",
"Lumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)",
"Multiple Body Parts (Including Body Systems and Body Parts)",
"No Physical Injury", "Shoulder(S)")
)regresion <- lm(TotalPaid ~ ClaimantType + Days + Injuryture + BodyPart, data= df)
summary(regresion)##
## Call:
## lm(formula = TotalPaid ~ ClaimantType + Days + Injuryture + BodyPart,
## data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -32285 -1284 311 1010 1087942
##
## Coefficients:
## Estimate
## (Intercept) 1.443e+04
## ClaimantTypeMedical Only -2.142e+04
## ClaimantTypeReport Only -2.175e+04
## Days 1.774e+00
## InjurytureAll Other Cumulative Injury, NOC 7.903e+03
## InjurytureAll Other Occupatiol Disease Injury, NOC 7.210e+03
## InjurytureAll Other Specific Injuries, Noc 5.875e+03
## InjurytureAmputation 7.516e+03
## InjurytureAngi Pectoris 7.884e+03
## InjurytureAsbestosis 4.043e+03
## InjurytureAsphyxiation 7.108e+03
## InjurytureBlack Lung 6.980e+03
## InjurytureBurn 6.558e+03
## InjurytureCancer 4.073e+03
## InjurytureCarpal Tunnel Syndrome 6.829e+03
## InjurytureConcussion 8.141e+03
## InjurytureContagious Disease 5.860e+03
## InjurytureContusion 6.814e+03
## InjurytureCrushing 7.128e+03
## InjurytureDermatitis 6.389e+03
## InjurytureDislocation 6.539e+03
## InjurytureDust Disease, NOC 6.347e+03
## InjurytureElectric Shock 5.154e+03
## InjurytureForeign Body 5.954e+03
## InjurytureFracture 8.917e+03
## InjurytureFreezing 4.378e+03
## InjurytureHearing Loss Or Impairment 6.105e+03
## InjurytureHeat Prostration 5.110e+03
## InjurytureHernia 7.545e+03
## InjurytureInfection 6.588e+03
## InjurytureInflammation 7.289e+03
## InjurytureLaceration 6.784e+03
## InjurytureLoss of Hearing 6.703e+03
## InjurytureMental Disorder 1.083e+04
## InjurytureMental Stress -2.663e+02
## InjurytureMultiple Injuries Including Both Physical and Psychological 1.111e+02
## InjurytureMultiple Physical Injuries Only 7.540e+03
## InjurytureMyocardial Infarction 6.215e+03
## InjurytureNo Physical Injury 6.850e+03
## InjurytureNon-Standard Code 4.787e+03
## InjurytureNot Available 7.628e+03
## InjuryturePoisoning?Chemical (Other Than Metals) 6.167e+03
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 6.404e+03
## InjuryturePuncture 6.623e+03
## InjurytureRadiation 1.286e+04
## InjurytureRespiratory Disorders 6.304e+03
## InjurytureRupture 1.321e+04
## InjurytureSeverance 2.963e+04
## InjurytureSilicosis 7.161e+03
## InjurytureSprain 7.189e+03
## InjurytureStrain 6.624e+03
## InjurytureSyncope 6.658e+03
## InjurytureVascular 9.112e+03
## InjurytureVDT-Related Disease 7.408e+03
## InjurytureVision Loss 5.454e+03
## BodyPartAnkle -6.147e+02
## BodyPartArtificial Appliance -4.214e+02
## BodyPartBody Systems and Multiple Body Systems -2.008e+03
## BodyPartBrain 6.945e+03
## BodyPartButtocks -2.086e+01
## BodyPartChest -6.016e+02
## BodyPartDisc-Trunk 6.530e+02
## BodyPartEar(S) -4.247e+02
## BodyPartElbow -3.192e+02
## BodyPartEyes -1.249e+03
## BodyPartFacial Bones -4.397e+02
## BodyPartFinger(S) -7.353e+02
## BodyPartFoot -6.491e+02
## BodyPartGreat Toe -5.559e+02
## BodyPartHand -4.565e+02
## BodyPartHeart 2.019e+03
## BodyPartHip -2.398e+02
## BodyPartInsufficient Info to Properly Identify?Unclassified -1.993e+03
## BodyPartInterl Organs -1.035e+03
## BodyPartKnee -3.833e+02
## BodyPartLarynx -1.484e+02
## BodyPartLower Arm -8.330e+01
## BodyPartLower Back Area -6.384e+02
## BodyPartLower Leg -4.373e+02
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 5.127e+02
## BodyPartLungs 5.180e+02
## BodyPartMouth -5.199e+02
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) -2.788e+02
## BodyPartMultiple Head Injury -8.343e+02
## BodyPartMultiple Lower Extremities -1.255e+03
## BodyPartMultiple Neck Injury -6.547e+02
## BodyPartMultiple Trunk -1.123e+03
## BodyPartMultiple Upper Extremities -1.473e+03
## BodyPartNo Physical Injury -1.903e+03
## BodyPartNon-Standard Code -1.513e+03
## BodyPartNose -8.124e+02
## BodyPartNot Available 6.757e+02
## BodyPartPelvis -3.236e+02
## BodyPartSacrum And Coccyx -4.307e+02
## BodyPartShoulder(S) 1.127e+03
## BodyPartSkull 2.687e+02
## BodyPartSoft Tissue-Head 8.865e+02
## BodyPartSoft Tissue-Neck 4.945e+02
## BodyPartSpil Cord-Trunk -3.740e+02
## BodyPartTeeth -1.823e+02
## BodyPartThumb -5.491e+02
## BodyPartToes -7.703e+02
## BodyPartTrachea -2.788e+03
## BodyPartUpper Arm -1.129e+03
## BodyPartUpper Back Area -2.069e+02
## BodyPartUpper Leg -3.367e+02
## BodyPartVertebrae 4.494e+02
## BodyPartWhole Body 7.236e+02
## BodyPartWrist -5.398e+02
## Std. Error
## (Intercept) 7.576e+03
## ClaimantTypeMedical Only 2.412e+02
## ClaimantTypeReport Only 3.326e+02
## Days 7.241e-02
## InjurytureAll Other Cumulative Injury, NOC 8.240e+03
## InjurytureAll Other Occupatiol Disease Injury, NOC 8.985e+03
## InjurytureAll Other Specific Injuries, Noc 7.551e+03
## InjurytureAmputation 1.411e+04
## InjurytureAngi Pectoris 8.989e+03
## InjurytureAsbestosis 7.979e+03
## InjurytureAsphyxiation 9.412e+03
## InjurytureBlack Lung 1.233e+04
## InjurytureBurn 7.569e+03
## InjurytureCancer 1.233e+04
## InjurytureCarpal Tunnel Syndrome 7.614e+03
## InjurytureConcussion 7.602e+03
## InjurytureContagious Disease 7.627e+03
## InjurytureContusion 7.547e+03
## InjurytureCrushing 7.590e+03
## InjurytureDermatitis 7.563e+03
## InjurytureDislocation 7.627e+03
## InjurytureDust Disease, NOC 8.486e+03
## InjurytureElectric Shock 7.770e+03
## InjurytureForeign Body 7.560e+03
## InjurytureFracture 7.565e+03
## InjurytureFreezing 1.132e+04
## InjurytureHearing Loss Or Impairment 8.152e+03
## InjurytureHeat Prostration 7.689e+03
## InjurytureHernia 7.900e+03
## InjurytureInfection 7.616e+03
## InjurytureInflammation 7.566e+03
## InjurytureLaceration 7.549e+03
## InjurytureLoss of Hearing 8.189e+03
## InjurytureMental Disorder 9.466e+03
## InjurytureMental Stress 7.692e+03
## InjurytureMultiple Injuries Including Both Physical and Psychological 8.070e+03
## InjurytureMultiple Physical Injuries Only 7.558e+03
## InjurytureMyocardial Infarction 1.008e+04
## InjurytureNo Physical Injury 7.559e+03
## InjurytureNon-Standard Code 7.561e+03
## InjurytureNot Available 7.606e+03
## InjuryturePoisoning?Chemical (Other Than Metals) 7.671e+03
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 7.729e+03
## InjuryturePuncture 7.552e+03
## InjurytureRadiation 8.480e+03
## InjurytureRespiratory Disorders 7.598e+03
## InjurytureRupture 7.924e+03
## InjurytureSeverance 8.652e+03
## InjurytureSilicosis 1.232e+04
## InjurytureSprain 7.550e+03
## InjurytureStrain 7.547e+03
## InjurytureSyncope 7.730e+03
## InjurytureVascular 9.622e+03
## InjurytureVDT-Related Disease 1.848e+04
## InjurytureVision Loss 8.139e+03
## BodyPartAnkle 7.369e+02
## BodyPartArtificial Appliance 7.574e+03
## BodyPartBody Systems and Multiple Body Systems 1.138e+03
## BodyPartBrain 3.141e+03
## BodyPartButtocks 1.245e+03
## BodyPartChest 8.107e+02
## BodyPartDisc-Trunk 1.047e+03
## BodyPartEar(S) 1.283e+03
## BodyPartElbow 8.091e+02
## BodyPartEyes 7.468e+02
## BodyPartFacial Bones 9.373e+02
## BodyPartFinger(S) 6.997e+02
## BodyPartFoot 7.568e+02
## BodyPartGreat Toe 1.561e+03
## BodyPartHand 7.024e+02
## BodyPartHeart 6.705e+03
## BodyPartHip 9.009e+02
## BodyPartInsufficient Info to Properly Identify?Unclassified 1.035e+03
## BodyPartInterl Organs 1.803e+03
## BodyPartKnee 6.917e+02
## BodyPartLarynx 6.411e+03
## BodyPartLower Arm 7.520e+02
## BodyPartLower Back Area 6.839e+02
## BodyPartLower Leg 7.731e+02
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 8.763e+02
## BodyPartLungs 1.282e+03
## BodyPartMouth 1.146e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) 6.828e+02
## BodyPartMultiple Head Injury 7.948e+02
## BodyPartMultiple Lower Extremities 9.953e+02
## BodyPartMultiple Neck Injury 8.636e+02
## BodyPartMultiple Trunk 1.785e+03
## BodyPartMultiple Upper Extremities 9.061e+02
## BodyPartNo Physical Injury 9.599e+02
## BodyPartNon-Standard Code 8.844e+02
## BodyPartNose 1.173e+03
## BodyPartNot Available 6.424e+03
## BodyPartPelvis 1.864e+03
## BodyPartSacrum And Coccyx 2.626e+03
## BodyPartShoulder(S) 7.072e+02
## BodyPartSkull 9.959e+02
## BodyPartSoft Tissue-Head 9.055e+02
## BodyPartSoft Tissue-Neck 7.811e+02
## BodyPartSpil Cord-Trunk 1.743e+03
## BodyPartTeeth 1.536e+03
## BodyPartThumb 7.867e+02
## BodyPartToes 1.093e+03
## BodyPartTrachea 5.403e+03
## BodyPartUpper Arm 8.455e+02
## BodyPartUpper Back Area 9.807e+02
## BodyPartUpper Leg 9.571e+02
## BodyPartVertebrae 5.374e+03
## BodyPartWhole Body 2.142e+03
## BodyPartWrist 7.295e+02
## t value
## (Intercept) 1.905
## ClaimantTypeMedical Only -88.807
## ClaimantTypeReport Only -65.385
## Days 24.493
## InjurytureAll Other Cumulative Injury, NOC 0.959
## InjurytureAll Other Occupatiol Disease Injury, NOC 0.802
## InjurytureAll Other Specific Injuries, Noc 0.778
## InjurytureAmputation 0.533
## InjurytureAngi Pectoris 0.877
## InjurytureAsbestosis 0.507
## InjurytureAsphyxiation 0.755
## InjurytureBlack Lung 0.566
## InjurytureBurn 0.866
## InjurytureCancer 0.330
## InjurytureCarpal Tunnel Syndrome 0.897
## InjurytureConcussion 1.071
## InjurytureContagious Disease 0.768
## InjurytureContusion 0.903
## InjurytureCrushing 0.939
## InjurytureDermatitis 0.845
## InjurytureDislocation 0.857
## InjurytureDust Disease, NOC 0.748
## InjurytureElectric Shock 0.663
## InjurytureForeign Body 0.788
## InjurytureFracture 1.179
## InjurytureFreezing 0.387
## InjurytureHearing Loss Or Impairment 0.749
## InjurytureHeat Prostration 0.665
## InjurytureHernia 0.955
## InjurytureInfection 0.865
## InjurytureInflammation 0.963
## InjurytureLaceration 0.899
## InjurytureLoss of Hearing 0.819
## InjurytureMental Disorder 1.145
## InjurytureMental Stress -0.035
## InjurytureMultiple Injuries Including Both Physical and Psychological 0.014
## InjurytureMultiple Physical Injuries Only 0.998
## InjurytureMyocardial Infarction 0.617
## InjurytureNo Physical Injury 0.906
## InjurytureNon-Standard Code 0.633
## InjurytureNot Available 1.003
## InjuryturePoisoning?Chemical (Other Than Metals) 0.804
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 0.829
## InjuryturePuncture 0.877
## InjurytureRadiation 1.516
## InjurytureRespiratory Disorders 0.830
## InjurytureRupture 1.668
## InjurytureSeverance 3.424
## InjurytureSilicosis 0.581
## InjurytureSprain 0.952
## InjurytureStrain 0.878
## InjurytureSyncope 0.861
## InjurytureVascular 0.947
## InjurytureVDT-Related Disease 0.401
## InjurytureVision Loss 0.670
## BodyPartAnkle -0.834
## BodyPartArtificial Appliance -0.056
## BodyPartBody Systems and Multiple Body Systems -1.765
## BodyPartBrain 2.211
## BodyPartButtocks -0.017
## BodyPartChest -0.742
## BodyPartDisc-Trunk 0.623
## BodyPartEar(S) -0.331
## BodyPartElbow -0.394
## BodyPartEyes -1.672
## BodyPartFacial Bones -0.469
## BodyPartFinger(S) -1.051
## BodyPartFoot -0.858
## BodyPartGreat Toe -0.356
## BodyPartHand -0.650
## BodyPartHeart 0.301
## BodyPartHip -0.266
## BodyPartInsufficient Info to Properly Identify?Unclassified -1.925
## BodyPartInterl Organs -0.574
## BodyPartKnee -0.554
## BodyPartLarynx -0.023
## BodyPartLower Arm -0.111
## BodyPartLower Back Area -0.933
## BodyPartLower Leg -0.566
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 0.585
## BodyPartLungs 0.404
## BodyPartMouth -0.454
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) -0.408
## BodyPartMultiple Head Injury -1.050
## BodyPartMultiple Lower Extremities -1.260
## BodyPartMultiple Neck Injury -0.758
## BodyPartMultiple Trunk -0.629
## BodyPartMultiple Upper Extremities -1.626
## BodyPartNo Physical Injury -1.982
## BodyPartNon-Standard Code -1.711
## BodyPartNose -0.692
## BodyPartNot Available 0.105
## BodyPartPelvis -0.174
## BodyPartSacrum And Coccyx -0.164
## BodyPartShoulder(S) 1.594
## BodyPartSkull 0.270
## BodyPartSoft Tissue-Head 0.979
## BodyPartSoft Tissue-Neck 0.633
## BodyPartSpil Cord-Trunk -0.215
## BodyPartTeeth -0.119
## BodyPartThumb -0.698
## BodyPartToes -0.705
## BodyPartTrachea -0.516
## BodyPartUpper Arm -1.335
## BodyPartUpper Back Area -0.211
## BodyPartUpper Leg -0.352
## BodyPartVertebrae 0.084
## BodyPartWhole Body 0.338
## BodyPartWrist -0.740
## Pr(>|t|)
## (Intercept) 0.056736
## ClaimantTypeMedical Only < 2e-16
## ClaimantTypeReport Only < 2e-16
## Days < 2e-16
## InjurytureAll Other Cumulative Injury, NOC 0.337513
## InjurytureAll Other Occupatiol Disease Injury, NOC 0.422310
## InjurytureAll Other Specific Injuries, Noc 0.436486
## InjurytureAmputation 0.594373
## InjurytureAngi Pectoris 0.380447
## InjurytureAsbestosis 0.612352
## InjurytureAsphyxiation 0.450102
## InjurytureBlack Lung 0.571342
## InjurytureBurn 0.386277
## InjurytureCancer 0.741142
## InjurytureCarpal Tunnel Syndrome 0.369791
## InjurytureConcussion 0.284219
## InjurytureContagious Disease 0.442325
## InjurytureContusion 0.366632
## InjurytureCrushing 0.347678
## InjurytureDermatitis 0.398220
## InjurytureDislocation 0.391248
## InjurytureDust Disease, NOC 0.454476
## InjurytureElectric Shock 0.507169
## InjurytureForeign Body 0.430933
## InjurytureFracture 0.238513
## InjurytureFreezing 0.698869
## InjurytureHearing Loss Or Impairment 0.453957
## InjurytureHeat Prostration 0.506338
## InjurytureHernia 0.339545
## InjurytureInfection 0.387054
## InjurytureInflammation 0.335356
## InjurytureLaceration 0.368838
## InjurytureLoss of Hearing 0.413053
## InjurytureMental Disorder 0.252412
## InjurytureMental Stress 0.972379
## InjurytureMultiple Injuries Including Both Physical and Psychological 0.989019
## InjurytureMultiple Physical Injuries Only 0.318500
## InjurytureMyocardial Infarction 0.537370
## InjurytureNo Physical Injury 0.364857
## InjurytureNon-Standard Code 0.526664
## InjurytureNot Available 0.315908
## InjuryturePoisoning?Chemical (Other Than Metals) 0.421448
## InjuryturePoisoning?General (NOT OD or Cumulative Injury) 0.407377
## InjuryturePuncture 0.380527
## InjurytureRadiation 0.129434
## InjurytureRespiratory Disorders 0.406721
## InjurytureRupture 0.095380
## InjurytureSeverance 0.000617
## InjurytureSilicosis 0.561170
## InjurytureSprain 0.341011
## InjurytureStrain 0.380106
## InjurytureSyncope 0.389025
## InjurytureVascular 0.343632
## InjurytureVDT-Related Disease 0.688503
## InjurytureVision Loss 0.502777
## BodyPartAnkle 0.404140
## BodyPartArtificial Appliance 0.955628
## BodyPartBody Systems and Multiple Body Systems 0.077644
## BodyPartBrain 0.027030
## BodyPartButtocks 0.986633
## BodyPartChest 0.458030
## BodyPartDisc-Trunk 0.533003
## BodyPartEar(S) 0.740603
## BodyPartElbow 0.693220
## BodyPartEyes 0.094514
## BodyPartFacial Bones 0.639002
## BodyPartFinger(S) 0.293278
## BodyPartFoot 0.391073
## BodyPartGreat Toe 0.721728
## BodyPartHand 0.515782
## BodyPartHeart 0.763337
## BodyPartHip 0.790093
## BodyPartInsufficient Info to Properly Identify?Unclassified 0.054199
## BodyPartInterl Organs 0.566017
## BodyPartKnee 0.579503
## BodyPartLarynx 0.981529
## BodyPartLower Arm 0.911799
## BodyPartLower Back Area 0.350606
## BodyPartLower Leg 0.571676
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk) 0.558451
## BodyPartLungs 0.686253
## BodyPartMouth 0.650177
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts) 0.683069
## BodyPartMultiple Head Injury 0.293869
## BodyPartMultiple Lower Extremities 0.207497
## BodyPartMultiple Neck Injury 0.448434
## BodyPartMultiple Trunk 0.529099
## BodyPartMultiple Upper Extremities 0.104042
## BodyPartNo Physical Injury 0.047431
## BodyPartNon-Standard Code 0.087176
## BodyPartNose 0.488719
## BodyPartNot Available 0.916234
## BodyPartPelvis 0.862199
## BodyPartSacrum And Coccyx 0.869700
## BodyPartShoulder(S) 0.111023
## BodyPartSkull 0.787341
## BodyPartSoft Tissue-Head 0.327532
## BodyPartSoft Tissue-Neck 0.526681
## BodyPartSpil Cord-Trunk 0.830098
## BodyPartTeeth 0.905487
## BodyPartThumb 0.485157
## BodyPartToes 0.481107
## BodyPartTrachea 0.605885
## BodyPartUpper Arm 0.181824
## BodyPartUpper Back Area 0.832935
## BodyPartUpper Leg 0.724998
## BodyPartVertebrae 0.933367
## BodyPartWhole Body 0.735438
## BodyPartWrist 0.459265
##
## (Intercept) .
## ClaimantTypeMedical Only ***
## ClaimantTypeReport Only ***
## Days ***
## InjurytureAll Other Cumulative Injury, NOC
## InjurytureAll Other Occupatiol Disease Injury, NOC
## InjurytureAll Other Specific Injuries, Noc
## InjurytureAmputation
## InjurytureAngi Pectoris
## InjurytureAsbestosis
## InjurytureAsphyxiation
## InjurytureBlack Lung
## InjurytureBurn
## InjurytureCancer
## InjurytureCarpal Tunnel Syndrome
## InjurytureConcussion
## InjurytureContagious Disease
## InjurytureContusion
## InjurytureCrushing
## InjurytureDermatitis
## InjurytureDislocation
## InjurytureDust Disease, NOC
## InjurytureElectric Shock
## InjurytureForeign Body
## InjurytureFracture
## InjurytureFreezing
## InjurytureHearing Loss Or Impairment
## InjurytureHeat Prostration
## InjurytureHernia
## InjurytureInfection
## InjurytureInflammation
## InjurytureLaceration
## InjurytureLoss of Hearing
## InjurytureMental Disorder
## InjurytureMental Stress
## InjurytureMultiple Injuries Including Both Physical and Psychological
## InjurytureMultiple Physical Injuries Only
## InjurytureMyocardial Infarction
## InjurytureNo Physical Injury
## InjurytureNon-Standard Code
## InjurytureNot Available
## InjuryturePoisoning?Chemical (Other Than Metals)
## InjuryturePoisoning?General (NOT OD or Cumulative Injury)
## InjuryturePuncture
## InjurytureRadiation
## InjurytureRespiratory Disorders
## InjurytureRupture .
## InjurytureSeverance ***
## InjurytureSilicosis
## InjurytureSprain
## InjurytureStrain
## InjurytureSyncope
## InjurytureVascular
## InjurytureVDT-Related Disease
## InjurytureVision Loss
## BodyPartAnkle
## BodyPartArtificial Appliance
## BodyPartBody Systems and Multiple Body Systems .
## BodyPartBrain *
## BodyPartButtocks
## BodyPartChest
## BodyPartDisc-Trunk
## BodyPartEar(S)
## BodyPartElbow
## BodyPartEyes .
## BodyPartFacial Bones
## BodyPartFinger(S)
## BodyPartFoot
## BodyPartGreat Toe
## BodyPartHand
## BodyPartHeart
## BodyPartHip
## BodyPartInsufficient Info to Properly Identify?Unclassified .
## BodyPartInterl Organs
## BodyPartKnee
## BodyPartLarynx
## BodyPartLower Arm
## BodyPartLower Back Area
## BodyPartLower Leg
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)
## BodyPartLungs
## BodyPartMouth
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)
## BodyPartMultiple Head Injury
## BodyPartMultiple Lower Extremities
## BodyPartMultiple Neck Injury
## BodyPartMultiple Trunk
## BodyPartMultiple Upper Extremities
## BodyPartNo Physical Injury *
## BodyPartNon-Standard Code .
## BodyPartNose
## BodyPartNot Available
## BodyPartPelvis
## BodyPartSacrum And Coccyx
## BodyPartShoulder(S)
## BodyPartSkull
## BodyPartSoft Tissue-Head
## BodyPartSoft Tissue-Neck
## BodyPartSpil Cord-Trunk
## BodyPartTeeth
## BodyPartThumb
## BodyPartToes
## BodyPartTrachea
## BodyPartUpper Arm
## BodyPartUpper Back Area
## BodyPartUpper Leg
## BodyPartVertebrae
## BodyPartWhole Body
## BodyPartWrist
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 16870 on 71385 degrees of freedom
## Multiple R-squared: 0.1443, Adjusted R-squared: 0.143
## F-statistic: 111.5 on 108 and 71385 DF, p-value: < 2.2e-16
## ClaimID TotalPaid TotalReserves TotalRecovery
## Min. : 650915 Min. : -270 Min. : 0 Min. : 0.00
## 1st Qu.: 811125 1st Qu.: 60 1st Qu.: 0 1st Qu.: 0.00
## Median : 844626 Median : 235 Median : 0 Median : 0.00
## Mean :10149151 Mean : 6746 Mean : 2233 Mean : 68.88
## 3rd Qu.:22716506 3rd Qu.: 938 3rd Qu.: 0 3rd Qu.: 0.00
## Max. :62203891 Max. :4527291 Max. :2069575 Max. :130541.03
## IndemnityPaid OtherPaid ClaimStatus IncidentDate
## Min. : -475 Min. : -7820 Length:134004 Length:134004
## 1st Qu.: 0 1st Qu.: 58 Class :character Class :character
## Median : 0 Median : 230 Mode :character Mode :character
## Mean : 3061 Mean : 3685
## 3rd Qu.: 0 3rd Qu.: 855
## Max. :640732 Max. :4129915
## IncidentDescription ReturnToWorkDate AverageWeeklyWage ClaimantOpenedDate
## Length:134004 Length:134004 Length:134004 Length:134004
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## ClaimantClosedDate EmployerNotificationDate ReceivedDate
## Length:134004 Length:134004 Length:134004
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## IsDenied ClaimantAge_at_DOI Gender ClaimantType
## Min. :0.00000 Length:134004 Length:134004 Length:134004
## 1st Qu.:0.00000 Class :character Class :character Class :character
## Median :0.00000 Mode :character Mode :character Mode :character
## Mean :0.04474
## 3rd Qu.:0.00000
## Max. :1.00000
## Injuryture BodyPartRegion BodyPart
## Length:134004 Length:134004 Length:134004
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
#count(datos,ClaimID, sort=TRUE)
#count(datos,TotalPaid, sort=TRUE)
#count(datos,TotalReserves, sort=TRUE)
#count(datos,TotalRecovery, sort=TRUE)
#count(datos,IndemnityPaid, sort=TRUE)
#count(datos,OtherPaid, sort=TRUE)
#count(datos,ClaimStatus, sort=TRUE)
#count(datos,IncidentDate, sort=TRUE)
#count(datos,IncidentDescription, sort=TRUE)
#count(datos,ReturnToWorkDate, sort=TRUE)
#count(datos,AverageWeeklyWage, sort=TRUE)
#count(datos,ClaimantOpenedDate, sort=TRUE)
#count(datos,ClaimantClosedDate, sort=TRUE)
#count(datos,Gender, sort=TRUE)
#count(datos,ClaimantType, sort=TRUE)
#count(datos,Injuryture, sort=TRUE)
#count(datos,BodyPartRegion, sort=TRUE)
#count(datos,BodyPart, sort=TRUE)Observaciones: 1. Tenemos NAs en la base de datos 2. En el género hay una opción de no disponible
#Seleccionamos los datos que nos interesan
ad<- datos[,c("BodyPartRegion","Gender","IsDenied","ClaimStatus")]
#Cuanto Nas tenemos
sum(is.na(ad))## [1] 0
## BodyPartRegion Gender IsDenied ClaimStatus
## 0 0 0 0
## 'data.frame': 134004 obs. of 4 variables:
## $ BodyPartRegion: chr "Trunk" "Trunk" "Upper Extremities" "Upper Extremities" ...
## $ Gender : chr "Male" "Male" "Male" "Male" ...
## $ IsDenied : int 0 0 0 0 0 0 0 0 0 0 ...
## $ ClaimStatus : chr "C" "C" "C" "C" ...
#conertir las variables a factor las que sean categoricas
ad$BodyPartRegion <- as.factor(ad$BodyPartRegion)
ad$Gender <- as.factor(ad$Gender)
ad$IsDenied <- as.factor(ad$IsDenied)
str(ad)## 'data.frame': 134004 obs. of 4 variables:
## $ BodyPartRegion: Factor w/ 8 levels "Head","Lower Extremities",..: 7 7 8 8 7 2 7 8 3 3 ...
## $ Gender : Factor w/ 3 levels "Female","Male",..: 2 2 2 2 1 2 1 2 1 2 ...
## $ IsDenied : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
## $ ClaimStatus : chr "C" "C" "C" "C" ...
## n= 134004
##
## node), split, n, loss, yval, (yprob)
## * denotes terminal node
##
## 1) root 134004 68879 Male (0.441755470 0.485992955 0.072251575)
## 2) BodyPartRegion=Head,Lower Extremities,Multiple Body Parts,Neck,Not Available,Trunk,Upper Extremities 121353 59449 Male (0.484001220 0.510115119 0.005883662)
## 4) BodyPartRegion=Lower Extremities,Multiple Body Parts,Neck,Not Available,Upper Extremities 87298 43365 Female (0.503253225 0.491202548 0.005544228)
## 8) IsDenied=1 4491 1874 Female (0.582720998 0.413048319 0.004230684) *
## 9) IsDenied=0 82807 41491 Female (0.498943326 0.495441207 0.005615467)
## 18) BodyPartRegion=Lower Extremities,Multiple Body Parts 41527 19959 Female (0.519372938 0.476003564 0.004623498) *
## 19) BodyPartRegion=Neck,Not Available,Upper Extremities 41280 20021 Male (0.478391473 0.514995155 0.006613372) *
## 5) BodyPartRegion=Head,Trunk 34055 15032 Male (0.434649831 0.558596388 0.006753781) *
## 3) BodyPartRegion=Non-Standard Code 12651 3683 Not Available (0.036518852 0.254604379 0.708876769) *
## ClaimID TotalPaid TotalReserves TotalRecovery
## Min. : 650915 Min. : -22 Min. : 0 Min. : 0.00
## 1st Qu.: 814283 1st Qu.: 82 1st Qu.: 0 1st Qu.: 0.00
## Median : 845571 Median : 281 Median : 0 Median : 0.00
## Mean :12146395 Mean : 8368 Mean : 3365 Mean : 68.22
## 3rd Qu.:22725794 3rd Qu.: 1229 3rd Qu.: 0 3rd Qu.: 0.00
## Max. :62203891 Max. :4527291 Max. :2069575 Max. :130541.03
##
## IndemnityPaid OtherPaid ClaimStatus IncidentDate
## Min. : -475 Min. : -22 Length:88833 Min. :1968-09-27
## 1st Qu.: 0 1st Qu.: 79 Class :character 1st Qu.:2003-08-05
## Median : 0 Median : 275 Mode :character Median :2007-02-27
## Mean : 3698 Mean : 4670 Mean :2006-10-11
## 3rd Qu.: 0 3rd Qu.: 1126 3rd Qu.:2010-11-17
## Max. :640732 Max. :4129915 Max. :2014-06-27
##
## IncidentDescription ReturnToWorkDate AverageWeeklyWage
## Length:88833 Min. :1984-01-01 Min. : 0.0
## Class :character 1st Qu.:2005-12-09 1st Qu.: 300.0
## Mode :character Median :2009-04-29 Median : 502.6
## Mean :2008-07-19 Mean : 629.0
## 3rd Qu.:2012-02-14 3rd Qu.: 684.8
## Max. :2015-05-07 Max. :2024000.0
## NA's :30493 NA's :50480
## ClaimantOpenedDate ClaimantClosedDate EmployerNotificationDate
## Min. :1968-09-27 Min. :1999-06-01 Min. :1972-09-10
## 1st Qu.:2003-09-18 1st Qu.:2005-10-04 1st Qu.:2004-03-31
## Median :2007-04-18 Median :2008-12-11 Median :2007-09-26
## Mean :2006-11-22 Mean :2008-10-09 Mean :2007-10-07
## 3rd Qu.:2010-12-13 3rd Qu.:2011-06-10 3rd Qu.:2011-06-01
## Max. :2014-06-30 Max. :2014-06-30 Max. :9988-02-21
## NA's :4637 NA's :11756
## ReceivedDate IsDenied ClaimantAge_at_DOI Gender
## Min. :1968-09-27 Min. :0.00000 Min. : 0.00 Length:88833
## 1st Qu.:2003-09-16 1st Qu.:0.00000 1st Qu.:33.00 Class :character
## Median :2007-03-28 Median :0.00000 Median :42.00 Mode :character
## Mean :2007-01-28 Mean :0.05227 Mean :42.05
## 3rd Qu.:2010-12-17 3rd Qu.:0.00000 3rd Qu.:51.00
## Max. :5202-01-10 Max. :1.00000 Max. :94.00
##
## ClaimantType Injuryture BodyPartRegion BodyPart
## Length:88833 Length:88833 Length:88833 Length:88833
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
Observaciones
Modificamos el tipo de variable
bd$TotalReserves<-as.numeric(bd$TotalReserves)
bd$TotalPaid<-as.numeric(bd$TotalPaid)
bd$TotalRecovery<-as.numeric(bd$TotalRecovery)Eliminamos los negativos de total paid
Realizamos cálculos importantes
# Obtener el Tiempo de Procesamiento en días.
bd<-mutate(bd, TiempoProcesamiento=difftime(bd$ClaimantClosedDate,bd$ClaimantOpenedDate, units="days"))
# Obtener el Costo Total
bd <- mutate(bd,CostoTotal=TotalReserves+TotalPaid-TotalRecovery)Creamos una tabla nueva con las variables de interes: Tiempo de Procesamiento, Costo Total y ClaimID
Realizamos las modificaciones necesarias a nuestro data frame
# Cambiar el tipo de variable TiempoProcesamiento de difftime-numeric.
nueva_bd$TiempoProcesamiento <- as.numeric(nueva_bd$TiempoProcesamiento)
#Eliminamos los na
nueva_bd <- na.omit(nueva_bd)Guardamos la columna de ID en una variable temporal y la eliminamos del conjunto de datos
wss <- numeric(10)
for (i in 1:10) {
kmeans_result <- kmeans(nueva_bd, centers = i)
wss[i] <- kmeans_result$tot.withinss
}
plot(1:10, wss, type = "b", xlab = "Número de Clusters (k)", ylab = "Suma de Cuadrados Dentro del Clúster (WSS)")