Modelos de análisis predictivo: Caso Integrador

1. Llamar a las librerias e Importar datos

#Llamar a las librerias
library(tidyverse)
library(readxl)
library(dplyr)
library(rpart)
library(rpart.plot)
library(ggplot2)
library(factoextra)
library(cluster)
library(data.table)
library(VIM)

#Importar datos
claims_data <- read_excel("ClaimsData2018.xlsx")
transactions_summary <- read.csv("TransactionsSummary2018.csv")

1. Entender la base de datos

merged_df <- merge(claims_data, transactions_summary, by = "ClaimID", all = TRUE)
#summary(merged_df)
#count(merged_df, ClaimStatus, sort=TRUE)
#count(merged_df, IncidentDescription, sort=TRUE)
#count(merged_df, Gender, sort=TRUE)
#count(merged_df, ClaimantType, sort=TRUE)
#count(merged_df, InjuryNature, sort=TRUE)
#count(merged_df, BodyPartRegion, sort=TRUE)
#count(merged_df, BodyPart, sort=TRUE)
#count(merged_df, IsDenied, sort=TRUE)

2. Limpiar la base de datos

## Corregir el tipo de datos:

# as.Date
merged_df$IncidentDate <- as.Date(merged_df$IncidentDate,"%m/%d/%Y")
merged_df$ReturnToWorkDate <- as.Date(merged_df$ReturnToWorkDate,"%m/%d/%Y")
merged_df$ClaimantOpenedDate <- as.Date(merged_df$ClaimantOpenedDate,"%m/%d/%Y")
merged_df$ClaimantClosedDate <- as.Date(merged_df$ClaimantClosedDate,"%m/%d/%Y")
merged_df$EmployerNotificationDate <- as.Date(merged_df$EmployerNotificationDate,"%m/%d/%Y")
merged_df$ReceivedDate <- as.Date(merged_df$ReceivedDate,"%m/%d/%Y")

#as.numeric
merged_df$AverageWeeklyWage <- as.numeric(merged_df$AverageWeeklyWage)
merged_df$IsDenied <- as.character(merged_df$IsDenied)
merged_df$ClaimantAge_at_DOI <- as.numeric(merged_df$ClaimantAge_at_DOI)
merged_df$TotalPaid <- as.numeric(merged_df$TotalReserves)
merged_df$TotalRecovery <- as.numeric(merged_df$TotalRecovery)
merged_df$TotalReserves <- as.numeric(merged_df$TotalReserves)
merged_df$TotalPaid <- as.numeric(merged_df$TotalPaid)
merged_df$IndemnityPaid <- as.numeric(merged_df$IndemnityPaid)
merged_df$OtherPaid <- as.numeric(merged_df$OtherPaid)
merged_df$ClaimantAge_at_DOI <- as.numeric(merged_df$ClaimantAge_at_DOI)


# ¿Cuántos NA tengo en al base de datos?
sum(is.na(merged_df$EmployerNotificationDate))
## [1] 74961
sum(is.na(merged_df$ReceivedDate))
## [1] 52673
sum(is.na(merged_df$ClaimantClosedDate))
## [1] 57351
sum(is.na(merged_df$TotalRecovery))
## [1] 52673
sum(is.na(merged_df$TotalReserves))
## [1] 52673
# ¿Cuántos NA tengo por variable?
sapply(merged_df, function(x) sum(is.na(x)))
##                  ClaimID                TotalPaid            TotalReserves 
##                        0                    52673                    52673 
##            TotalRecovery            IndemnityPaid                OtherPaid 
##                    52673                    52673                    52673 
##              ClaimStatus             IncidentDate      IncidentDescription 
##                    52673                    52673                    52673 
##         ReturnToWorkDate        AverageWeeklyWage       ClaimantOpenedDate 
##                   111310                   137597                    52673 
##       ClaimantClosedDate EmployerNotificationDate             ReceivedDate 
##                    57351                    74961                    52673 
##                 IsDenied       ClaimantAge_at_DOI                   Gender 
##                    52673                    97751                    52673 
##             ClaimantType             InjuryNature           BodyPartRegion 
##                    52673                    52673                    52673 
##                 BodyPart            BillReviewALE                 Hospital 
##                    52673                   139865                   145262 
##      PhysicianOutpatient                       Rx 
##                    84986                   145752
summary(merged_df)
##     ClaimID           TotalPaid       TotalReserves     TotalRecovery      
##  Min.   :  633915   Min.   :      0   Min.   :      0   Min.   :     0.00  
##  1st Qu.:  810246   1st Qu.:      0   1st Qu.:      0   1st Qu.:     0.00  
##  Median :  856915   Median :      0   Median :      0   Median :     0.00  
##  Mean   :12344572   Mean   :   2233   Mean   :   2233   Mean   :    68.88  
##  3rd Qu.:22716420   3rd Qu.:      0   3rd Qu.:      0   3rd Qu.:     0.00  
##  Max.   :62246496   Max.   :2069575   Max.   :2069575   Max.   :130541.03  
##                     NA's   :52673     NA's   :52673     NA's   :52673      
##  IndemnityPaid      OtherPaid       ClaimStatus         IncidentDate       
##  Min.   :  -475   Min.   :  -7820   Length:186677      Min.   :1947-02-24  
##  1st Qu.:     0   1st Qu.:     58   Class :character   1st Qu.:1998-12-21  
##  Median :     0   Median :    230   Mode  :character   Median :2004-01-05  
##  Mean   :  3061   Mean   :   3685                      Mean   :2003-12-08  
##  3rd Qu.:     0   3rd Qu.:    855                      3rd Qu.:2009-02-02  
##  Max.   :640732   Max.   :4129915                      Max.   :2014-06-27  
##  NA's   :52673    NA's   :52673                        NA's   :52673       
##  IncidentDescription ReturnToWorkDate     AverageWeeklyWage  
##  Length:186677       Min.   :1976-10-29   Min.   :      0.0  
##  Class :character    1st Qu.:2002-04-25   1st Qu.:    300.0  
##  Mode  :character    Median :2007-07-09   Median :    492.0  
##                      Mean   :2006-06-01   Mean   :    587.3  
##                      3rd Qu.:2011-06-01   3rd Qu.:    660.4  
##                      Max.   :2015-05-07   Max.   :2024000.0  
##                      NA's   :111310       NA's   :137597     
##  ClaimantOpenedDate   ClaimantClosedDate   EmployerNotificationDate
##  Min.   :1947-02-24   Min.   :1999-06-01   Min.   :1972-09-10      
##  1st Qu.:1999-02-09   1st Qu.:2005-03-31   1st Qu.:2000-03-13      
##  Median :2004-02-17   Median :2006-04-04   Median :2004-12-28      
##  Mean   :2004-01-23   Mean   :2007-05-24   Mean   :2005-08-29      
##  3rd Qu.:2009-04-09   3rd Qu.:2009-11-11   3rd Qu.:2009-11-03      
##  Max.   :2014-06-30   Max.   :2014-06-30   Max.   :9999-07-21      
##  NA's   :52673        NA's   :57351        NA's   :74961           
##   ReceivedDate          IsDenied         ClaimantAge_at_DOI    Gender         
##  Min.   :1947-02-24   Length:186677      Min.   :-8000.00   Length:186677     
##  1st Qu.:1999-02-09   Class :character   1st Qu.:   33.00   Class :character  
##  Median :2004-02-13   Mode  :character   Median :   42.00   Mode  :character  
##  Mean   :2004-07-19                      Mean   :   39.85                     
##  3rd Qu.:2009-02-27                      3rd Qu.:   51.00                     
##  Max.   :9999-07-21                      Max.   :   94.00                     
##  NA's   :52673                           NA's   :97751                        
##  ClaimantType       InjuryNature       BodyPartRegion       BodyPart        
##  Length:186677      Length:186677      Length:186677      Length:186677     
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  BillReviewALE        Hospital         PhysicianOutpatient       Rx          
##  Min.   : -456.0   Min.   : -12570.4   Min.   :  -4655.7   Min.   :  -469.5  
##  1st Qu.:   16.0   1st Qu.:    193.9   1st Qu.:    107.6   1st Qu.:    23.3  
##  Median :   32.0   Median :    559.1   Median :    221.6   Median :    58.3  
##  Mean   :  191.2   Mean   :   4394.7   Mean   :   1752.3   Mean   :  1140.4  
##  3rd Qu.:   80.0   3rd Qu.:   2253.4   3rd Qu.:    710.5   3rd Qu.:   174.5  
##  Max.   :56475.3   Max.   :2759604.0   Max.   :1481468.5   Max.   :631635.5  
##  NA's   :139865    NA's   :145262      NA's   :84986       NA's   :145752

Agregar columnas

Se agregan las columnas con los cálculos necesarios para mostrar nuestro objetivo, que es el costo total y los días transcurridos de los procedimientos.

merged_df$TotalIncurredCost <- merged_df$TotalReserves + merged_df$Indemnity + merged_df$OtherPaid - merged_df$TotalRecovery


merged_df$TimeProcesses <- as.numeric(difftime(merged_df$ClaimantClosedDate, merged_df$ClaimantOpenedDate, unit="days"))

Regresión Lineal

Se utilizaron las variables de mayor relevancia para el modelo predictivo.

regresion <- lm(TotalIncurredCost ~ BodyPartRegion + BodyPart + ClaimantType + Gender + ClaimantAge_at_DOI + TimeProcesses + InjuryNature + IsDenied , data = merged_df)


summary(regresion)
## 
## Call:
## lm(formula = TotalIncurredCost ~ BodyPartRegion + BodyPart + 
##     ClaimantType + Gender + ClaimantAge_at_DOI + TimeProcesses + 
##     InjuryNature + IsDenied, data = merged_df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
##  -36378   -4488    -181    2034 1372079 
## 
## Coefficients: (7 not defined because of singularities)
##                                                                           Estimate
## (Intercept)                                                              6.146e+03
## BodyPartRegionLower Extremities                                          5.359e+03
## BodyPartRegionMultiple Body Parts                                        1.019e+04
## BodyPartRegionNeck                                                       1.743e+04
## BodyPartRegionNon-Standard Code                                         -1.247e+03
## BodyPartRegionNot Available                                              6.159e+03
## BodyPartRegionTrunk                                                      3.122e+03
## BodyPartRegionUpper Extremities                                          3.625e+03
## BodyPartAnkle                                                           -2.849e+03
## BodyPartArtificial Appliance                                            -7.514e+03
## BodyPartBody Systems and Multiple Body Systems                          -5.912e+03
## BodyPartBrain                                                            1.310e+04
## BodyPartButtocks                                                         1.322e+03
## BodyPartChest                                                            9.705e+02
## BodyPartDisc-Trunk                                                       3.218e+03
## BodyPartEar(S)                                                           5.206e+03
## BodyPartElbow                                                            7.283e+02
## BodyPartEyes                                                             4.096e+03
## BodyPartFacial Bones                                                     3.635e+03
## BodyPartFinger(S)                                                       -1.122e+03
## BodyPartFoot                                                            -2.672e+03
## BodyPartGreat Toe                                                       -2.910e+03
## BodyPartHand                                                             1.234e+02
## BodyPartHeart                                                           -2.176e+03
## BodyPartHip                                                             -3.151e+02
## BodyPartInsufficient Info to Properly Identify?Unclassified             -5.318e+03
## BodyPartInternal Organs                                                  9.073e+02
## BodyPartKnee                                                             5.605e+02
## BodyPartLarynx                                                          -1.643e+04
## BodyPartLower Arm                                                        9.104e+02
## BodyPartLower Back Area                                                  2.486e+03
## BodyPartLower Leg                                                       -1.515e+03
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              3.709e+03
## BodyPartLungs                                                            1.887e+03
## BodyPartMouth                                                            2.828e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)     -4.624e+03
## BodyPartMultiple Head Injury                                             4.898e+03
## BodyPartMultiple Lower Extremities                                       9.111e+02
## BodyPartMultiple Neck Injury                                            -1.188e+04
## BodyPartMultiple Trunk                                                  -2.326e+03
## BodyPartMultiple Upper Extremities                                      -1.997e+02
## BodyPartNo Physical Injury                                              -5.873e+03
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                             4.148e+03
## BodyPartNot Available                                                           NA
## BodyPartPelvis                                                           4.300e+03
## BodyPartSacrum And Coccyx                                               -1.360e+03
## BodyPartShoulder(S)                                                      4.516e+03
## BodyPartSkull                                                            5.048e+03
## BodyPartSoft Tissue-Head                                                 5.909e+03
## BodyPartSoft Tissue-Neck                                                -1.260e+04
## BodyPartSpinal Cord-Trunk                                               -2.440e+03
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                           -7.469e+02
## BodyPartToes                                                            -3.214e+03
## BodyPartTrachea                                                         -1.522e+04
## BodyPartUpper Arm                                                        7.993e+02
## BodyPartUpper Back Area                                                  9.297e+02
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## ClaimantTypeMedical Only                                                -1.592e+04
## ClaimantTypeReport Only                                                 -1.568e+04
## GenderMale                                                               4.392e+01
## GenderNot Available                                                      6.146e+03
## ClaimantAge_at_DOI                                                       1.190e+00
## TimeProcesses                                                            3.010e+00
## InjuryNatureAll Other Cumulative Injury, NOC                             3.540e+03
## InjuryNatureAll Other Occupational Disease Injury, NOC                   1.061e+04
## InjuryNatureAll Other Specific Injuries, Noc                             1.802e+03
## InjuryNatureAmputation                                                   7.231e+03
## InjuryNatureAngina Pectoris                                              3.799e+03
## InjuryNatureAsbestosis                                                   1.148e+04
## InjuryNatureAsphyxiation                                                 1.952e+04
## InjuryNatureBlack Lung                                                   3.581e+03
## InjuryNatureBurn                                                         5.314e+03
## InjuryNatureCancer                                                       2.729e+04
## InjuryNatureCarpal Tunnel Syndrome                                       4.976e+03
## InjuryNatureConcussion                                                   5.730e+03
## InjuryNatureContagious Disease                                           2.469e+03
## InjuryNatureContusion                                                    3.594e+03
## InjuryNatureCrushing                                                     4.969e+03
## InjuryNatureDermatitis                                                   3.760e+03
## InjuryNatureDislocation                                                  5.658e+03
## InjuryNatureDust Disease, NOC                                            4.414e+03
## InjuryNatureElectric Shock                                               2.151e+03
## InjuryNatureForeign Body                                                 2.734e+03
## InjuryNatureFracture                                                     7.607e+03
## InjuryNatureFreezing                                                     6.342e+02
## InjuryNatureHearing Loss Or Impairment                                  -3.411e+03
## InjuryNatureHeat Prostration                                             2.407e+03
## InjuryNatureHernia                                                       2.547e+01
## InjuryNatureInfection                                                    3.882e+03
## InjuryNatureInflammation                                                 4.711e+03
## InjuryNatureLaceration                                                   3.920e+03
## InjuryNatureLoss of Hearing                                              3.696e+03
## InjuryNatureMental Disorder                                              8.590e+03
## InjuryNatureMental Stress                                                1.688e+03
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  7.785e+03
## InjuryNatureMultiple Physical Injuries Only                              6.007e+03
## InjuryNatureMyocardial Infarction                                        9.194e+03
## InjuryNatureNo Physical Injury                                           3.952e+03
## InjuryNatureNon-Standard Code                                            4.599e+02
## InjuryNatureNot Available                                                4.948e+03
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       2.532e+03
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              3.357e+03
## InjuryNaturePuncture                                                     3.992e+03
## InjuryNatureRadiation                                                    7.610e+03
## InjuryNatureRespiratory Disorders                                        4.188e+03
## InjuryNatureRupture                                                      1.333e+04
## InjuryNatureSeverance                                                    1.898e+04
## InjuryNatureSilicosis                                                    3.613e+03
## InjuryNatureSprain                                                       4.689e+03
## InjuryNatureStrain                                                       4.043e+03
## InjuryNatureSyncope                                                      4.911e+03
## InjuryNatureVascular                                                     4.217e+03
## InjuryNatureVDT-Related Disease                                         -3.269e+03
## InjuryNatureVision Loss                                                  3.589e+03
## IsDenied1                                                               -5.993e+03
##                                                                         Std. Error
## (Intercept)                                                              9.588e+03
## BodyPartRegionLower Extremities                                          1.654e+03
## BodyPartRegionMultiple Body Parts                                        2.734e+03
## BodyPartRegionNeck                                                       4.950e+03
## BodyPartRegionNon-Standard Code                                          1.576e+03
## BodyPartRegionNot Available                                              8.155e+03
## BodyPartRegionTrunk                                                      1.595e+03
## BodyPartRegionUpper Extremities                                          1.478e+03
## BodyPartAnkle                                                            9.045e+02
## BodyPartArtificial Appliance                                             8.960e+03
## BodyPartBody Systems and Multiple Body Systems                           2.577e+03
## BodyPartBrain                                                            4.100e+03
## BodyPartButtocks                                                         1.382e+03
## BodyPartChest                                                            8.844e+02
## BodyPartDisc-Trunk                                                       1.239e+03
## BodyPartEar(S)                                                           1.902e+03
## BodyPartElbow                                                            6.484e+02
## BodyPartEyes                                                             1.505e+03
## BodyPartFacial Bones                                                     1.639e+03
## BodyPartFinger(S)                                                        4.656e+02
## BodyPartFoot                                                             9.279e+02
## BodyPartGreat Toe                                                        1.846e+03
## BodyPartHand                                                             4.731e+02
## BodyPartHeart                                                            4.629e+03
## BodyPartHip                                                              1.067e+03
## BodyPartInsufficient Info to Properly Identify?Unclassified              2.528e+03
## BodyPartInternal Organs                                                  1.860e+03
## BodyPartKnee                                                             8.599e+02
## BodyPartLarynx                                                           7.744e+03
## BodyPartLower Arm                                                        5.710e+02
## BodyPartLower Back Area                                                  7.388e+02
## BodyPartLower Leg                                                        9.451e+02
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              1.010e+03
## BodyPartLungs                                                            1.443e+03
## BodyPartMouth                                                            1.798e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      2.340e+03
## BodyPartMultiple Head Injury                                             1.525e+03
## BodyPartMultiple Lower Extremities                                       1.162e+03
## BodyPartMultiple Neck Injury                                             4.780e+03
## BodyPartMultiple Trunk                                                   1.967e+03
## BodyPartMultiple Upper Extremities                                       7.876e+02
## BodyPartNo Physical Injury                                               2.463e+03
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                             1.800e+03
## BodyPartNot Available                                                           NA
## BodyPartPelvis                                                           1.968e+03
## BodyPartSacrum And Coccyx                                                2.781e+03
## BodyPartShoulder(S)                                                      4.930e+02
## BodyPartSkull                                                            1.656e+03
## BodyPartSoft Tissue-Head                                                 1.624e+03
## BodyPartSoft Tissue-Neck                                                 4.767e+03
## BodyPartSpinal Cord-Trunk                                                1.400e+03
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                            6.239e+02
## BodyPartToes                                                             1.304e+03
## BodyPartTrachea                                                          7.762e+03
## BodyPartUpper Arm                                                        6.978e+02
## BodyPartUpper Back Area                                                  1.047e+03
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## ClaimantTypeMedical Only                                                 1.856e+02
## ClaimantTypeReport Only                                                  3.302e+02
## GenderMale                                                               1.514e+02
## GenderNot Available                                                      9.800e+02
## ClaimantAge_at_DOI                                                       6.006e-01
## TimeProcesses                                                            8.358e-02
## InjuryNatureAll Other Cumulative Injury, NOC                             1.012e+04
## InjuryNatureAll Other Occupational Disease Injury, NOC                   1.086e+04
## InjuryNatureAll Other Specific Injuries, Noc                             9.484e+03
## InjuryNatureAmputation                                                   9.942e+03
## InjuryNatureAngina Pectoris                                              1.082e+04
## InjuryNatureAsbestosis                                                   9.919e+03
## InjuryNatureAsphyxiation                                                 1.143e+04
## InjuryNatureBlack Lung                                                   1.549e+04
## InjuryNatureBurn                                                         9.504e+03
## InjuryNatureCancer                                                       1.284e+04
## InjuryNatureCarpal Tunnel Syndrome                                       9.529e+03
## InjuryNatureConcussion                                                   9.527e+03
## InjuryNatureContagious Disease                                           9.575e+03
## InjuryNatureContusion                                                    9.480e+03
## InjuryNatureCrushing                                                     9.521e+03
## InjuryNatureDermatitis                                                   9.499e+03
## InjuryNatureDislocation                                                  9.553e+03
## InjuryNatureDust Disease, NOC                                            1.060e+04
## InjuryNatureElectric Shock                                               9.725e+03
## InjuryNatureForeign Body                                                 9.496e+03
## InjuryNatureFracture                                                     9.489e+03
## InjuryNatureFreezing                                                     1.422e+04
## InjuryNatureHearing Loss Or Impairment                                   9.897e+03
## InjuryNatureHeat Prostration                                             9.643e+03
## InjuryNatureHernia                                                       9.613e+03
## InjuryNatureInfection                                                    9.558e+03
## InjuryNatureInflammation                                                 9.500e+03
## InjuryNatureLaceration                                                   9.482e+03
## InjuryNatureLoss of Hearing                                              1.012e+04
## InjuryNatureMental Disorder                                              1.167e+04
## InjuryNatureMental Stress                                                9.639e+03
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  9.994e+03
## InjuryNatureMultiple Physical Injuries Only                              9.492e+03
## InjuryNatureMyocardial Infarction                                        1.090e+04
## InjuryNatureNo Physical Injury                                           9.494e+03
## InjuryNatureNon-Standard Code                                            9.494e+03
## InjuryNatureNot Available                                                9.550e+03
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       9.630e+03
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              9.696e+03
## InjuryNaturePuncture                                                     9.486e+03
## InjuryNatureRadiation                                                    1.055e+04
## InjuryNatureRespiratory Disorders                                        9.536e+03
## InjuryNatureRupture                                                      9.734e+03
## InjuryNatureSeverance                                                    1.046e+04
## InjuryNatureSilicosis                                                    1.548e+04
## InjuryNatureSprain                                                       9.482e+03
## InjuryNatureStrain                                                       9.480e+03
## InjuryNatureSyncope                                                      9.680e+03
## InjuryNatureVascular                                                     1.161e+04
## InjuryNatureVDT-Related Disease                                          1.773e+04
## InjuryNatureVision Loss                                                  1.022e+04
## IsDenied1                                                                3.389e+02
##                                                                         t value
## (Intercept)                                                               0.641
## BodyPartRegionLower Extremities                                           3.241
## BodyPartRegionMultiple Body Parts                                         3.727
## BodyPartRegionNeck                                                        3.521
## BodyPartRegionNon-Standard Code                                          -0.791
## BodyPartRegionNot Available                                               0.755
## BodyPartRegionTrunk                                                       1.957
## BodyPartRegionUpper Extremities                                           2.453
## BodyPartAnkle                                                            -3.150
## BodyPartArtificial Appliance                                             -0.839
## BodyPartBody Systems and Multiple Body Systems                           -2.294
## BodyPartBrain                                                             3.196
## BodyPartButtocks                                                          0.956
## BodyPartChest                                                             1.097
## BodyPartDisc-Trunk                                                        2.596
## BodyPartEar(S)                                                            2.738
## BodyPartElbow                                                             1.123
## BodyPartEyes                                                              2.721
## BodyPartFacial Bones                                                      2.218
## BodyPartFinger(S)                                                        -2.409
## BodyPartFoot                                                             -2.880
## BodyPartGreat Toe                                                        -1.576
## BodyPartHand                                                              0.261
## BodyPartHeart                                                            -0.470
## BodyPartHip                                                              -0.295
## BodyPartInsufficient Info to Properly Identify?Unclassified              -2.104
## BodyPartInternal Organs                                                   0.488
## BodyPartKnee                                                              0.652
## BodyPartLarynx                                                           -2.121
## BodyPartLower Arm                                                         1.594
## BodyPartLower Back Area                                                   3.365
## BodyPartLower Leg                                                        -1.603
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)               3.671
## BodyPartLungs                                                             1.308
## BodyPartMouth                                                             1.572
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      -1.977
## BodyPartMultiple Head Injury                                              3.212
## BodyPartMultiple Lower Extremities                                        0.784
## BodyPartMultiple Neck Injury                                             -2.485
## BodyPartMultiple Trunk                                                   -1.182
## BodyPartMultiple Upper Extremities                                       -0.254
## BodyPartNo Physical Injury                                               -2.384
## BodyPartNon-Standard Code                                                    NA
## BodyPartNose                                                              2.304
## BodyPartNot Available                                                        NA
## BodyPartPelvis                                                            2.185
## BodyPartSacrum And Coccyx                                                -0.489
## BodyPartShoulder(S)                                                       9.161
## BodyPartSkull                                                             3.048
## BodyPartSoft Tissue-Head                                                  3.639
## BodyPartSoft Tissue-Neck                                                 -2.644
## BodyPartSpinal Cord-Trunk                                                -1.743
## BodyPartTeeth                                                                NA
## BodyPartThumb                                                            -1.197
## BodyPartToes                                                             -2.465
## BodyPartTrachea                                                          -1.961
## BodyPartUpper Arm                                                         1.145
## BodyPartUpper Back Area                                                   0.888
## BodyPartUpper Leg                                                            NA
## BodyPartVertebrae                                                            NA
## BodyPartWhole Body                                                           NA
## BodyPartWrist                                                                NA
## ClaimantTypeMedical Only                                                -85.771
## ClaimantTypeReport Only                                                 -47.495
## GenderMale                                                                0.290
## GenderNot Available                                                       6.271
## ClaimantAge_at_DOI                                                        1.981
## TimeProcesses                                                            36.009
## InjuryNatureAll Other Cumulative Injury, NOC                              0.350
## InjuryNatureAll Other Occupational Disease Injury, NOC                    0.977
## InjuryNatureAll Other Specific Injuries, Noc                              0.190
## InjuryNatureAmputation                                                    0.727
## InjuryNatureAngina Pectoris                                               0.351
## InjuryNatureAsbestosis                                                    1.157
## InjuryNatureAsphyxiation                                                  1.707
## InjuryNatureBlack Lung                                                    0.231
## InjuryNatureBurn                                                          0.559
## InjuryNatureCancer                                                        2.125
## InjuryNatureCarpal Tunnel Syndrome                                        0.522
## InjuryNatureConcussion                                                    0.601
## InjuryNatureContagious Disease                                            0.258
## InjuryNatureContusion                                                     0.379
## InjuryNatureCrushing                                                      0.522
## InjuryNatureDermatitis                                                    0.396
## InjuryNatureDislocation                                                   0.592
## InjuryNatureDust Disease, NOC                                             0.416
## InjuryNatureElectric Shock                                                0.221
## InjuryNatureForeign Body                                                  0.288
## InjuryNatureFracture                                                      0.802
## InjuryNatureFreezing                                                      0.045
## InjuryNatureHearing Loss Or Impairment                                   -0.345
## InjuryNatureHeat Prostration                                              0.250
## InjuryNatureHernia                                                        0.003
## InjuryNatureInfection                                                     0.406
## InjuryNatureInflammation                                                  0.496
## InjuryNatureLaceration                                                    0.413
## InjuryNatureLoss of Hearing                                               0.365
## InjuryNatureMental Disorder                                               0.736
## InjuryNatureMental Stress                                                 0.175
## InjuryNatureMultiple Injuries Including Both Physical and Psychological   0.779
## InjuryNatureMultiple Physical Injuries Only                               0.633
## InjuryNatureMyocardial Infarction                                         0.844
## InjuryNatureNo Physical Injury                                            0.416
## InjuryNatureNon-Standard Code                                             0.048
## InjuryNatureNot Available                                                 0.518
## InjuryNaturePoisoning?Chemical (Other Than Metals)                        0.263
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)               0.346
## InjuryNaturePuncture                                                      0.421
## InjuryNatureRadiation                                                     0.722
## InjuryNatureRespiratory Disorders                                         0.439
## InjuryNatureRupture                                                       1.369
## InjuryNatureSeverance                                                     1.815
## InjuryNatureSilicosis                                                     0.233
## InjuryNatureSprain                                                        0.495
## InjuryNatureStrain                                                        0.426
## InjuryNatureSyncope                                                       0.507
## InjuryNatureVascular                                                      0.363
## InjuryNatureVDT-Related Disease                                          -0.184
## InjuryNatureVision Loss                                                   0.351
## IsDenied1                                                               -17.683
##                                                                         Pr(>|t|)
## (Intercept)                                                             0.521539
## BodyPartRegionLower Extremities                                         0.001193
## BodyPartRegionMultiple Body Parts                                       0.000194
## BodyPartRegionNeck                                                      0.000429
## BodyPartRegionNon-Standard Code                                         0.428948
## BodyPartRegionNot Available                                             0.450150
## BodyPartRegionTrunk                                                     0.050339
## BodyPartRegionUpper Extremities                                         0.014162
## BodyPartAnkle                                                           0.001632
## BodyPartArtificial Appliance                                            0.401686
## BodyPartBody Systems and Multiple Body Systems                          0.021802
## BodyPartBrain                                                           0.001394
## BodyPartButtocks                                                        0.338882
## BodyPartChest                                                           0.272502
## BodyPartDisc-Trunk                                                      0.009427
## BodyPartEar(S)                                                          0.006186
## BodyPartElbow                                                           0.261376
## BodyPartEyes                                                            0.006515
## BodyPartFacial Bones                                                    0.026560
## BodyPartFinger(S)                                                       0.015979
## BodyPartFoot                                                            0.003975
## BodyPartGreat Toe                                                       0.114927
## BodyPartHand                                                            0.794200
## BodyPartHeart                                                           0.638229
## BodyPartHip                                                             0.767623
## BodyPartInsufficient Info to Properly Identify?Unclassified             0.035377
## BodyPartInternal Organs                                                 0.625742
## BodyPartKnee                                                            0.514562
## BodyPartLarynx                                                          0.033919
## BodyPartLower Arm                                                       0.110858
## BodyPartLower Back Area                                                 0.000767
## BodyPartLower Leg                                                       0.109007
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)             0.000242
## BodyPartLungs                                                           0.190776
## BodyPartMouth                                                           0.115857
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)     0.048096
## BodyPartMultiple Head Injury                                            0.001318
## BodyPartMultiple Lower Extremities                                      0.432944
## BodyPartMultiple Neck Injury                                            0.012956
## BodyPartMultiple Trunk                                                  0.237167
## BodyPartMultiple Upper Extremities                                      0.799840
## BodyPartNo Physical Injury                                              0.017122
## BodyPartNon-Standard Code                                                     NA
## BodyPartNose                                                            0.021200
## BodyPartNot Available                                                         NA
## BodyPartPelvis                                                          0.028870
## BodyPartSacrum And Coccyx                                               0.624797
## BodyPartShoulder(S)                                                      < 2e-16
## BodyPartSkull                                                           0.002301
## BodyPartSoft Tissue-Head                                                0.000274
## BodyPartSoft Tissue-Neck                                                0.008206
## BodyPartSpinal Cord-Trunk                                               0.081382
## BodyPartTeeth                                                                 NA
## BodyPartThumb                                                           0.231234
## BodyPartToes                                                            0.013715
## BodyPartTrachea                                                         0.049854
## BodyPartUpper Arm                                                       0.252027
## BodyPartUpper Back Area                                                 0.374689
## BodyPartUpper Leg                                                             NA
## BodyPartVertebrae                                                             NA
## BodyPartWhole Body                                                            NA
## BodyPartWrist                                                                 NA
## ClaimantTypeMedical Only                                                 < 2e-16
## ClaimantTypeReport Only                                                  < 2e-16
## GenderMale                                                              0.771804
## GenderNot Available                                                      3.6e-10
## ClaimantAge_at_DOI                                                      0.047642
## TimeProcesses                                                            < 2e-16
## InjuryNatureAll Other Cumulative Injury, NOC                            0.726343
## InjuryNatureAll Other Occupational Disease Injury, NOC                  0.328678
## InjuryNatureAll Other Specific Injuries, Noc                            0.849328
## InjuryNatureAmputation                                                  0.467071
## InjuryNatureAngina Pectoris                                             0.725474
## InjuryNatureAsbestosis                                                  0.247293
## InjuryNatureAsphyxiation                                                0.087743
## InjuryNatureBlack Lung                                                  0.817149
## InjuryNatureBurn                                                        0.576054
## InjuryNatureCancer                                                      0.033571
## InjuryNatureCarpal Tunnel Syndrome                                      0.601530
## InjuryNatureConcussion                                                  0.547522
## InjuryNatureContagious Disease                                          0.796485
## InjuryNatureContusion                                                   0.704583
## InjuryNatureCrushing                                                    0.601722
## InjuryNatureDermatitis                                                  0.692204
## InjuryNatureDislocation                                                 0.553676
## InjuryNatureDust Disease, NOC                                           0.677129
## InjuryNatureElectric Shock                                              0.824949
## InjuryNatureForeign Body                                                0.773451
## InjuryNatureFracture                                                    0.422787
## InjuryNatureFreezing                                                    0.964416
## InjuryNatureHearing Loss Or Impairment                                  0.730387
## InjuryNatureHeat Prostration                                            0.802867
## InjuryNatureHernia                                                      0.997886
## InjuryNatureInfection                                                   0.684654
## InjuryNatureInflammation                                                0.619971
## InjuryNatureLaceration                                                  0.679272
## InjuryNatureLoss of Hearing                                             0.714871
## InjuryNatureMental Disorder                                             0.461558
## InjuryNatureMental Stress                                               0.860990
## InjuryNatureMultiple Injuries Including Both Physical and Psychological 0.436005
## InjuryNatureMultiple Physical Injuries Only                             0.526815
## InjuryNatureMyocardial Infarction                                       0.398759
## InjuryNatureNo Physical Injury                                          0.677243
## InjuryNatureNon-Standard Code                                           0.961362
## InjuryNatureNot Available                                               0.604356
## InjuryNaturePoisoning?Chemical (Other Than Metals)                      0.792599
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)             0.729167
## InjuryNaturePuncture                                                    0.673853
## InjuryNatureRadiation                                                   0.470543
## InjuryNatureRespiratory Disorders                                       0.660549
## InjuryNatureRupture                                                     0.170875
## InjuryNatureSeverance                                                   0.069597
## InjuryNatureSilicosis                                                   0.815463
## InjuryNatureSprain                                                      0.620942
## InjuryNatureStrain                                                      0.669775
## InjuryNatureSyncope                                                     0.611897
## InjuryNatureVascular                                                    0.716419
## InjuryNatureVDT-Related Disease                                         0.853744
## InjuryNatureVision Loss                                                 0.725530
## IsDenied1                                                                < 2e-16
##                                                                            
## (Intercept)                                                                
## 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             *  
## BodyPartInternal 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                                                ** 
## BodyPartSpinal Cord-Trunk                                               .  
## BodyPartTeeth                                                              
## BodyPartThumb                                                              
## BodyPartToes                                                            *  
## BodyPartTrachea                                                         *  
## BodyPartUpper Arm                                                          
## BodyPartUpper Back Area                                                    
## BodyPartUpper Leg                                                          
## BodyPartVertebrae                                                          
## BodyPartWhole Body                                                         
## BodyPartWrist                                                              
## ClaimantTypeMedical Only                                                ***
## ClaimantTypeReport Only                                                 ***
## GenderMale                                                                 
## GenderNot Available                                                     ***
## ClaimantAge_at_DOI                                                      *  
## TimeProcesses                                                           ***
## InjuryNatureAll Other Cumulative Injury, NOC                               
## InjuryNatureAll Other Occupational Disease Injury, NOC                     
## InjuryNatureAll Other Specific Injuries, Noc                               
## InjuryNatureAmputation                                                     
## InjuryNatureAngina Pectoris                                                
## InjuryNatureAsbestosis                                                     
## InjuryNatureAsphyxiation                                                .  
## InjuryNatureBlack Lung                                                     
## InjuryNatureBurn                                                           
## InjuryNatureCancer                                                      *  
## InjuryNatureCarpal Tunnel Syndrome                                         
## InjuryNatureConcussion                                                     
## InjuryNatureContagious Disease                                             
## InjuryNatureContusion                                                      
## InjuryNatureCrushing                                                       
## InjuryNatureDermatitis                                                     
## InjuryNatureDislocation                                                    
## InjuryNatureDust Disease, NOC                                              
## InjuryNatureElectric Shock                                                 
## InjuryNatureForeign Body                                                   
## InjuryNatureFracture                                                       
## InjuryNatureFreezing                                                       
## InjuryNatureHearing Loss Or Impairment                                     
## InjuryNatureHeat Prostration                                               
## InjuryNatureHernia                                                         
## InjuryNatureInfection                                                      
## InjuryNatureInflammation                                                   
## InjuryNatureLaceration                                                     
## InjuryNatureLoss of Hearing                                                
## InjuryNatureMental Disorder                                                
## InjuryNatureMental Stress                                                  
## InjuryNatureMultiple Injuries Including Both Physical and Psychological    
## InjuryNatureMultiple Physical Injuries Only                                
## InjuryNatureMyocardial Infarction                                          
## InjuryNatureNo Physical Injury                                             
## InjuryNatureNon-Standard Code                                              
## InjuryNatureNot Available                                                  
## InjuryNaturePoisoning?Chemical (Other Than Metals)                         
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)                
## InjuryNaturePuncture                                                       
## InjuryNatureRadiation                                                      
## InjuryNatureRespiratory Disorders                                          
## InjuryNatureRupture                                                        
## InjuryNatureSeverance                                                   .  
## InjuryNatureSilicosis                                                      
## InjuryNatureSprain                                                         
## InjuryNatureStrain                                                         
## InjuryNatureSyncope                                                        
## InjuryNatureVascular                                                       
## InjuryNatureVDT-Related Disease                                            
## InjuryNatureVision Loss                                                    
## IsDenied1                                                               ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21190 on 84176 degrees of freedom
##   (102388 observations deleted due to missingness)
## Multiple R-squared:  0.126,  Adjusted R-squared:  0.1248 
## F-statistic: 108.3 on 112 and 84176 DF,  p-value: < 2.2e-16

Construcción de Modelo Predictivo

data <- data.frame(BodyPartRegion = "Trunk", BodyPart = "Lumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)", ClaimantType = "Medical Only", Gender = "Male", ClaimantAge_at_DOI = 23, TimeProcesses = 381, InjuryNature = "Cancer", IsDenied = "0" )

predict(regresion, data)
##        1 
## 25564.86

Arbol de Decisiones

# Bases de datos nuevas

cuerpo <- merged_df %>% select(Gender, BodyPartRegion)
denied <- merged_df %>% select(Gender, IsDenied)

#Árboles de predicción
arbol <- rpart(formula = Gender ~ ., data=cuerpo)
rpart.plot(arbol)

prp(arbol, extra = 3)

tree <- rpart(formula = Gender ~ ., data=denied)
rpart.plot(tree)

prp(tree, extra = 3)

Clusters

Preparar los datos

cluster <- merged_df %>% select(TotalIncurredCost, TimeProcesses) %>% na.omit() %>% filter(TotalIncurredCost>0) 

summary(cluster)
##  TotalIncurredCost   TimeProcesses  
##  Min.   :      0.0   Min.   :    0  
##  1st Qu.:    146.8   1st Qu.:  194  
##  Median :    332.4   Median :  992  
##  Mean   :   5122.2   Mean   : 1306  
##  3rd Qu.:   1201.6   3rd Qu.: 2057  
##  Max.   :1758919.5   Max.   :16428
# Los datos fuera de lo normal están fuera de los siguientes límites: 
# Límite inferior = q1 -1.5*IQR
# Límite superior = Q3 + 1.5*IQR
# Q1: Cuartil 1, Q3  

IQR_C <- IQR(cluster$TotalIncurredCost)
LI_C <- 146.8-1.5*IQR_C
LS_C <- 1201.6+1.5*IQR_C
cluster <- cluster[cluster$TotalIncurredCost <=2783.74,]

IQR_T <- IQR(cluster$TimeProcesses)
LI_T<- 160-1.5*IQR_T
LS_T <- 2040+1.5*IQR_T
cluster <- cluster[cluster$TimeProcesses<=4860,]

cluster <- as.data.frame(scale(cluster))

grupos <- 3
segmentos <- kmeans(cluster, grupos)
asignación <- cbind(cluster, cluster=segmentos$cluster)

Gráfica

fviz_cluster(segmentos, data=cluster)

Optimización

Para la optimización del gráfico de clusters se utilizó el Elbow Method. El cálculo se intento en RStudio, RCloud y Python, para probar cuál de los tres soportaba el tamaño de los datos. Al final el resultado se pudo obtener de ambos RCloud y Python.

El procedimiento seguido para obtener el resultado fue el siguiente:

#Se trasladaron solo los datos necesarios con la siguiente formula, la cual nos permite pasar un dataframe de R a un excel.
#write.xlsx(cluster, "Cluster.xlsx")

# Utiliza la visualización del codo para determinar el número óptimo de clústeres
#visualizer = KElbowVisualizer(model, k=(1, 10), metric='distortion', timings=False)
#visualizer.fit(datos)  # Ajusta el modelo a tus datos

# Muestra el gráfico
#visualizer.show()
LS0tCnRpdGxlOiAiQ2FzbyBOb3J0aCBDYXJvbGluYS4iCmF1dGhvcjogIkVxdWlwbyA2IgpkYXRlOiAiOC8xMC8yMDIzIgpvdXRwdXQ6IAogIGh0bWxfZG9jdW1lbnQ6CiAgICB0b2M6IHllcwogICAgdG9jX2Zsb2F0OiB5ZXMKICAgIGNvZGVfZG93bmxvYWQ6IFRSVUUKICAgIHRoZW1lOiAic2ltcGxleCIKICAgIGhpZ2hsaWdodDogInB5Z21lbnRzIgotLS0KCiMgPHNwYW4gc3R5bGU9ImNvbG9yOiBvcmFuZ2U7Ij5Nb2RlbG9zIGRlIGFuw6FsaXNpcyBwcmVkaWN0aXZvOiBDYXNvIEludGVncmFkb3I8L3NwYW4+CgojIyA8c3BhbiBzdHlsZT0iY29sb3I6IG9yYW5nZTsiPjEuIExsYW1hciBhIGxhcyBsaWJyZXJpYXMgZSBJbXBvcnRhciBkYXRvczwvc3Bhbj4KCmBgYHtyIG1lc3NhZ2U9RkFMU0V9CiNMbGFtYXIgYSBsYXM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