library(readxl)
library(dplyr)

Regresión con todos los Datos

Import Data

#file.choose()

claims_data <- read_xlsx("C:\\Users\\usuario\\Documents\\1 Tec\\Módulo 4\\ClaimsData2018.xlsx")
transactions <- read.csv("C:\\Users\\usuario\\Documents\\1 Tec\\Módulo 4\\TransactionsSummary2018.csv")

Clean Data

claims_data$TotalReserves <- as.numeric(claims_data$TotalReserves)
claims_data$IndemnityPaid <- as.numeric(claims_data$IndemnityPaid)
claims_data$OtherPaid <- as.numeric(claims_data$OtherPaid)
claims_data$TotalRecovery <- as.numeric(claims_data$TotalRecovery)
claims_data$ClaimantOpenedDate <- as.Date(claims_data$ClaimantOpenedDate, format = "%Y/%m/%d")
claims_data$ClaimantClosedDate <- as.Date(claims_data$ClaimantClosedDate, format = "%Y/%m/%d")
claims_data$ClaimantAge_at_DOI <- as.numeric(claims_data$ClaimantAge_at_DOI)
## Warning: NAs introduced by coercion
claims_data$AverageWeeklyWage <- as.numeric(claims_data$AverageWeeklyWage)
## Warning: NAs introduced by coercion

Merge

df <- merge(claims_data, transactions, by="ClaimID", all = TRUE)

##Analysis

Create Total Incurred Cost per claim

df2 <- df
#summary(df2)
df2$TotalIncurredCost <- with(df2, TotalReserves + IndemnityPaid + OtherPaid - TotalRecovery)

Obtain the difference between closed and open dates to obtain the Claim Duration

df2$ClaimDuration  <- as.numeric(difftime(df2$ClaimantClosedDate, df2$ClaimantOpenedDate, units = c("days")))
#df2$ClaimDuration <- seq(from = df2$ClaimantOpenedDate, to = df2$ClaimantClosedDate, by = "day")
#summary(df2$ClaimDuration)

Multiple Regression

df2.lm <- lm(TotalIncurredCost ~ ClaimStatus + ClaimantAge_at_DOI + Gender + AverageWeeklyWage + BodyPartRegion + BodyPart + InjuryNature, data = df2)
summary(df2.lm)
## 
## Call:
## lm(formula = TotalIncurredCost ~ ClaimStatus + ClaimantAge_at_DOI + 
##     Gender + AverageWeeklyWage + BodyPartRegion + BodyPart + 
##     InjuryNature, data = df2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -289205  -16987   -3489    5766 4757653 
## 
## Coefficients: (7 not defined because of singularities)
##                                                                           Estimate
## (Intercept)                                                             -1.766e+04
## ClaimStatusO                                                             1.650e+05
## ClaimStatusR                                                             1.754e+05
## ClaimantAge_at_DOI                                                       4.046e+00
## GenderMale                                                               2.605e+03
## GenderNot Available                                                      2.422e+04
## AverageWeeklyWage                                                        2.618e-03
## BodyPartRegionLower Extremities                                          1.458e+04
## BodyPartRegionMultiple Body Parts                                        5.952e+04
## BodyPartRegionNeck                                                       4.562e+04
## BodyPartRegionNon-Standard Code                                          6.831e+03
## BodyPartRegionNot Available                                              2.438e+04
## BodyPartRegionTrunk                                                      6.148e+03
## BodyPartRegionUpper Extremities                                          1.420e+04
## BodyPartAnkle                                                           -1.337e+03
## BodyPartArtificial Appliance                                            -4.247e+04
## BodyPartBody Systems and Multiple Body Systems                          -4.695e+04
## BodyPartBrain                                                            7.347e+04
## BodyPartButtocks                                                        -2.985e+02
## BodyPartChest                                                           -3.626e+02
## BodyPartDisc-Trunk                                                       3.403e+04
## BodyPartEar(S)                                                           1.445e+03
## BodyPartElbow                                                           -4.576e+03
## BodyPartEyes                                                             5.443e+03
## BodyPartFacial Bones                                                     1.300e+04
## BodyPartFinger(S)                                                       -1.013e+04
## BodyPartFoot                                                            -6.831e+03
## BodyPartGreat Toe                                                       -1.018e+04
## BodyPartHand                                                            -9.000e+03
## BodyPartHeart                                                            4.469e+03
## BodyPartHip                                                              4.306e+03
## BodyPartInsufficient Info to Properly Identify?Unclassified             -4.100e+04
## BodyPartInternal Organs                                                  1.903e+04
## BodyPartKnee                                                             4.109e+03
## BodyPartLarynx                                                          -3.683e+04
## BodyPartLower Arm                                                       -7.120e+03
## BodyPartLower Back Area                                                  3.467e+04
## BodyPartLower Leg                                                        8.986e+02
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              3.072e+04
## BodyPartLungs                                                           -1.036e+03
## BodyPartMouth                                                            9.086e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)     -2.590e+04
## BodyPartMultiple Head Injury                                             2.008e+04
## BodyPartMultiple Lower Extremities                                       1.203e+04
## BodyPartMultiple Neck Injury                                            -1.754e+04
## BodyPartMultiple Trunk                                                   1.723e+04
## BodyPartMultiple Upper Extremities                                       9.815e+03
## BodyPartNo Physical Injury                                              -4.008e+04
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                            -1.718e+03
## BodyPartNot Available                                                           NA
## BodyPartPelvis                                                           3.667e+03
## BodyPartSacrum And Coccyx                                                2.023e+04
## BodyPartShoulder(S)                                                      7.246e+03
## BodyPartSkull                                                            4.599e+03
## BodyPartSoft Tissue-Head                                                -2.094e+04
## BodyPartSoft Tissue-Neck                                                -5.241e+04
## BodyPartSpinal Cord-Trunk                                                1.404e+05
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                           -7.328e+03
## BodyPartToes                                                            -9.862e+03
## BodyPartTrachea                                                         -3.939e+04
## BodyPartUpper Arm                                                        5.325e+03
## BodyPartUpper Back Area                                                  2.012e+04
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## InjuryNatureAll Other Cumulative Injury, NOC                            -1.911e+04
## InjuryNatureAll Other Occupational Disease Injury, NOC                   1.069e+05
## InjuryNatureAll Other Specific Injuries, Noc                             1.434e+04
## InjuryNatureAmputation                                                   2.370e+04
## InjuryNatureAngina Pectoris                                              9.385e+03
## InjuryNatureAsbestosis                                                   1.830e+04
## InjuryNatureAsphyxiation                                                 3.520e+04
## InjuryNatureBurn                                                         1.256e+04
## InjuryNatureCancer                                                       2.455e+04
## InjuryNatureCarpal Tunnel Syndrome                                       1.035e+04
## InjuryNatureConcussion                                                   3.092e+04
## InjuryNatureContagious Disease                                           1.683e+04
## InjuryNatureContusion                                                    1.007e+04
## InjuryNatureCrushing                                                     6.976e+03
## InjuryNatureDermatitis                                                  -3.936e+03
## InjuryNatureDislocation                                                  4.992e+03
## InjuryNatureDust Disease, NOC                                           -1.884e+03
## InjuryNatureElectric Shock                                               4.657e+03
## InjuryNatureForeign Body                                                 6.205e+03
## InjuryNatureFracture                                                     1.778e+04
## InjuryNatureFreezing                                                    -1.010e+04
## InjuryNatureHearing Loss Or Impairment                                   1.282e+04
## InjuryNatureHeat Prostration                                            -7.442e+03
## InjuryNatureHernia                                                       1.008e+04
## InjuryNatureInfection                                                   -4.112e+03
## InjuryNatureInflammation                                                 9.181e+03
## InjuryNatureLaceration                                                   7.542e+03
## InjuryNatureLoss of Hearing                                              1.831e+04
## InjuryNatureMental Disorder                                              9.832e+03
## InjuryNatureMental Stress                                                2.095e+04
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  1.056e+05
## InjuryNatureMultiple Physical Injuries Only                              3.242e+03
## InjuryNatureMyocardial Infarction                                        8.407e+03
## InjuryNatureNo Physical Injury                                           4.773e+02
## InjuryNatureNon-Standard Code                                           -9.568e+03
## InjuryNatureNot Available                                                3.816e+03
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       2.088e+02
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)             -1.108e+04
## InjuryNaturePuncture                                                     8.092e+03
## InjuryNatureRadiation                                                    3.064e+04
## InjuryNatureRespiratory Disorders                                        1.329e+04
## InjuryNatureRupture                                                      1.216e+04
## InjuryNatureSeverance                                                    5.789e+04
## InjuryNatureSilicosis                                                   -7.988e+02
## InjuryNatureSprain                                                       4.469e+02
## InjuryNatureStrain                                                       3.497e+03
## InjuryNatureSyncope                                                      4.440e+03
## InjuryNatureVascular                                                     5.007e+03
## InjuryNatureVDT-Related Disease                                          6.596e+03
## InjuryNatureVision Loss                                                  1.075e+04
##                                                                         Std. Error
## (Intercept)                                                              5.532e+04
## ClaimStatusO                                                             1.874e+03
## ClaimStatusR                                                             3.334e+03
## ClaimantAge_at_DOI                                                       5.594e+00
## GenderMale                                                               9.881e+02
## GenderNot Available                                                      5.941e+03
## AverageWeeklyWage                                                        3.835e-02
## BodyPartRegionLower Extremities                                          1.082e+04
## BodyPartRegionMultiple Body Parts                                        1.580e+04
## BodyPartRegionNeck                                                       2.777e+04
## BodyPartRegionNon-Standard Code                                          1.134e+04
## BodyPartRegionNot Available                                              9.506e+04
## BodyPartRegionTrunk                                                      1.036e+04
## BodyPartRegionUpper Extremities                                          9.546e+03
## BodyPartAnkle                                                            6.092e+03
## BodyPartArtificial Appliance                                             6.798e+04
## BodyPartBody Systems and Multiple Body Systems                           1.465e+04
## BodyPartBrain                                                            1.948e+04
## BodyPartButtocks                                                         8.420e+03
## BodyPartChest                                                            5.958e+03
## BodyPartDisc-Trunk                                                       7.543e+03
## BodyPartEar(S)                                                           1.292e+04
## BodyPartElbow                                                            4.333e+03
## BodyPartEyes                                                             9.955e+03
## BodyPartFacial Bones                                                     1.105e+04
## BodyPartFinger(S)                                                        3.327e+03
## BodyPartFoot                                                             6.265e+03
## BodyPartGreat Toe                                                        1.228e+04
## BodyPartHand                                                             3.232e+03
## BodyPartHeart                                                            2.306e+04
## BodyPartHip                                                              6.985e+03
## BodyPartInsufficient Info to Properly Identify?Unclassified              1.433e+04
## BodyPartInternal Organs                                                  1.117e+04
## BodyPartKnee                                                             5.816e+03
## BodyPartLarynx                                                           3.872e+04
## BodyPartLower Arm                                                        4.063e+03
## BodyPartLower Back Area                                                  4.894e+03
## BodyPartLower Leg                                                        6.471e+03
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              6.323e+03
## BodyPartLungs                                                            9.280e+03
## BodyPartMouth                                                            1.204e+04
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      1.291e+04
## BodyPartMultiple Head Injury                                             9.846e+03
## BodyPartMultiple Lower Extremities                                       7.644e+03
## BodyPartMultiple Neck Injury                                             2.644e+04
## BodyPartMultiple Trunk                                                   1.174e+04
## BodyPartMultiple Upper Extremities                                       5.474e+03
## BodyPartNo Physical Injury                                               1.405e+04
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                             1.192e+04
## BodyPartNot Available                                                           NA
## BodyPartPelvis                                                           1.190e+04
## BodyPartSacrum And Coccyx                                                1.787e+04
## BodyPartShoulder(S)                                                      3.136e+03
## BodyPartSkull                                                            1.141e+04
## BodyPartSoft Tissue-Head                                                 1.049e+04
## BodyPartSoft Tissue-Neck                                                 2.633e+04
## BodyPartSpinal Cord-Trunk                                                1.455e+04
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                            4.580e+03
## BodyPartToes                                                             8.960e+03
## BodyPartTrachea                                                          4.671e+04
## BodyPartUpper Arm                                                        4.733e+03
## BodyPartUpper Back Area                                                  6.883e+03
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## InjuryNatureAll Other Cumulative Injury, NOC                             5.704e+04
## InjuryNatureAll Other Occupational Disease Injury, NOC                   6.401e+04
## InjuryNatureAll Other Specific Injuries, Noc                             5.458e+04
## InjuryNatureAmputation                                                   5.684e+04
## InjuryNatureAngina Pectoris                                              5.934e+04
## InjuryNatureAsbestosis                                                   5.699e+04
## InjuryNatureAsphyxiation                                                 6.896e+04
## InjuryNatureBurn                                                         5.475e+04
## InjuryNatureCancer                                                       7.220e+04
## InjuryNatureCarpal Tunnel Syndrome                                       5.478e+04
## InjuryNatureConcussion                                                   5.493e+04
## InjuryNatureContagious Disease                                           5.535e+04
## InjuryNatureContusion                                                    5.455e+04
## InjuryNatureCrushing                                                     5.486e+04
## InjuryNatureDermatitis                                                   5.469e+04
## InjuryNatureDislocation                                                  5.486e+04
## InjuryNatureDust Disease, NOC                                            6.011e+04
## InjuryNatureElectric Shock                                               5.598e+04
## InjuryNatureForeign Body                                                 5.476e+04
## InjuryNatureFracture                                                     5.459e+04
## InjuryNatureFreezing                                                     7.713e+04
## InjuryNatureHearing Loss Or Impairment                                   5.899e+04
## InjuryNatureHeat Prostration                                             5.544e+04
## InjuryNatureHernia                                                       5.527e+04
## InjuryNatureInfection                                                    5.501e+04
## InjuryNatureInflammation                                                 5.467e+04
## InjuryNatureLaceration                                                   5.457e+04
## InjuryNatureLoss of Hearing                                              5.917e+04
## InjuryNatureMental Disorder                                              6.532e+04
## InjuryNatureMental Stress                                                5.511e+04
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  5.619e+04
## InjuryNatureMultiple Physical Injuries Only                              5.460e+04
## InjuryNatureMyocardial Infarction                                        6.147e+04
## InjuryNatureNo Physical Injury                                           5.468e+04
## InjuryNatureNon-Standard Code                                            5.492e+04
## InjuryNatureNot Available                                                5.508e+04
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       5.568e+04
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              5.847e+04
## InjuryNaturePuncture                                                     5.462e+04
## InjuryNatureRadiation                                                    6.681e+04
## InjuryNatureRespiratory Disorders                                        5.490e+04
## InjuryNatureRupture                                                      5.523e+04
## InjuryNatureSeverance                                                    6.097e+04
## InjuryNatureSilicosis                                                    7.712e+04
## InjuryNatureSprain                                                       5.456e+04
## InjuryNatureStrain                                                       5.455e+04
## InjuryNatureSyncope                                                      5.562e+04
## InjuryNatureVascular                                                     6.681e+04
## InjuryNatureVDT-Related Disease                                          8.622e+04
## InjuryNatureVision Loss                                                  5.925e+04
##                                                                         t value
## (Intercept)                                                              -0.319
## ClaimStatusO                                                             88.042
## ClaimStatusR                                                             52.623
## ClaimantAge_at_DOI                                                        0.723
## GenderMale                                                                2.636
## GenderNot Available                                                       4.077
## AverageWeeklyWage                                                         0.068
## BodyPartRegionLower Extremities                                           1.348
## BodyPartRegionMultiple Body Parts                                         3.768
## BodyPartRegionNeck                                                        1.643
## BodyPartRegionNon-Standard Code                                           0.602
## BodyPartRegionNot Available                                               0.256
## BodyPartRegionTrunk                                                       0.593
## BodyPartRegionUpper Extremities                                           1.487
## BodyPartAnkle                                                            -0.219
## BodyPartArtificial Appliance                                             -0.625
## BodyPartBody Systems and Multiple Body Systems                           -3.204
## BodyPartBrain                                                             3.771
## BodyPartButtocks                                                         -0.035
## BodyPartChest                                                            -0.061
## BodyPartDisc-Trunk                                                        4.511
## BodyPartEar(S)                                                            0.112
## BodyPartElbow                                                            -1.056
## BodyPartEyes                                                              0.547
## BodyPartFacial Bones                                                      1.177
## BodyPartFinger(S)                                                        -3.045
## BodyPartFoot                                                             -1.090
## BodyPartGreat Toe                                                        -0.829
## BodyPartHand                                                             -2.785
## BodyPartHeart                                                             0.194
## BodyPartHip                                                               0.616
## BodyPartInsufficient Info to Properly Identify?Unclassified              -2.861
## BodyPartInternal Organs                                                   1.703
## BodyPartKnee                                                              0.707
## BodyPartLarynx                                                           -0.951
## BodyPartLower Arm                                                        -1.753
## BodyPartLower Back Area                                                   7.085
## BodyPartLower Leg                                                         0.139
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)               4.859
## BodyPartLungs                                                            -0.112
## BodyPartMouth                                                             0.755
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      -2.006
## BodyPartMultiple Head Injury                                              2.040
## BodyPartMultiple Lower Extremities                                        1.574
## BodyPartMultiple Neck Injury                                             -0.664
## BodyPartMultiple Trunk                                                    1.468
## BodyPartMultiple Upper Extremities                                        1.793
## BodyPartNo Physical Injury                                               -2.852
## BodyPartNon-Standard Code                                                    NA
## BodyPartNose                                                             -0.144
## BodyPartNot Available                                                        NA
## BodyPartPelvis                                                            0.308
## BodyPartSacrum And Coccyx                                                 1.132
## BodyPartShoulder(S)                                                       2.311
## BodyPartSkull                                                             0.403
## BodyPartSoft Tissue-Head                                                 -1.995
## BodyPartSoft Tissue-Neck                                                 -1.990
## BodyPartSpinal Cord-Trunk                                                 9.652
## BodyPartTeeth                                                                NA
## BodyPartThumb                                                            -1.600
## BodyPartToes                                                             -1.101
## BodyPartTrachea                                                          -0.843
## BodyPartUpper Arm                                                         1.125
## BodyPartUpper Back Area                                                   2.923
## BodyPartUpper Leg                                                            NA
## BodyPartVertebrae                                                            NA
## BodyPartWhole Body                                                           NA
## BodyPartWrist                                                                NA
## InjuryNatureAll Other Cumulative Injury, NOC                             -0.335
## InjuryNatureAll Other Occupational Disease Injury, NOC                    1.670
## InjuryNatureAll Other Specific Injuries, Noc                              0.263
## InjuryNatureAmputation                                                    0.417
## InjuryNatureAngina Pectoris                                               0.158
## InjuryNatureAsbestosis                                                    0.321
## InjuryNatureAsphyxiation                                                  0.510
## InjuryNatureBurn                                                          0.229
## InjuryNatureCancer                                                        0.340
## InjuryNatureCarpal Tunnel Syndrome                                        0.189
## InjuryNatureConcussion                                                    0.563
## InjuryNatureContagious Disease                                            0.304
## InjuryNatureContusion                                                     0.185
## InjuryNatureCrushing                                                      0.127
## InjuryNatureDermatitis                                                   -0.072
## InjuryNatureDislocation                                                   0.091
## InjuryNatureDust Disease, NOC                                            -0.031
## InjuryNatureElectric Shock                                                0.083
## InjuryNatureForeign Body                                                  0.113
## InjuryNatureFracture                                                      0.326
## InjuryNatureFreezing                                                     -0.131
## InjuryNatureHearing Loss Or Impairment                                    0.217
## InjuryNatureHeat Prostration                                             -0.134
## InjuryNatureHernia                                                        0.182
## InjuryNatureInfection                                                    -0.075
## InjuryNatureInflammation                                                  0.168
## InjuryNatureLaceration                                                    0.138
## InjuryNatureLoss of Hearing                                               0.309
## InjuryNatureMental Disorder                                               0.151
## InjuryNatureMental Stress                                                 0.380
## InjuryNatureMultiple Injuries Including Both Physical and Psychological   1.880
## InjuryNatureMultiple Physical Injuries Only                               0.059
## InjuryNatureMyocardial Infarction                                         0.137
## InjuryNatureNo Physical Injury                                            0.009
## InjuryNatureNon-Standard Code                                            -0.174
## InjuryNatureNot Available                                                 0.069
## InjuryNaturePoisoning?Chemical (Other Than Metals)                        0.004
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              -0.190
## InjuryNaturePuncture                                                      0.148
## InjuryNatureRadiation                                                     0.459
## InjuryNatureRespiratory Disorders                                         0.242
## InjuryNatureRupture                                                       0.220
## InjuryNatureSeverance                                                     0.950
## InjuryNatureSilicosis                                                    -0.010
## InjuryNatureSprain                                                        0.008
## InjuryNatureStrain                                                        0.064
## InjuryNatureSyncope                                                       0.080
## InjuryNatureVascular                                                      0.075
## InjuryNatureVDT-Related Disease                                           0.076
## InjuryNatureVision Loss                                                   0.182
##                                                                         Pr(>|t|)
## (Intercept)                                                             0.749540
## ClaimStatusO                                                             < 2e-16
## ClaimStatusR                                                             < 2e-16
## ClaimantAge_at_DOI                                                      0.469599
## GenderMale                                                              0.008391
## GenderNot Available                                                     4.58e-05
## AverageWeeklyWage                                                       0.945567
## BodyPartRegionLower Extremities                                         0.177755
## BodyPartRegionMultiple Body Parts                                       0.000165
## BodyPartRegionNeck                                                      0.100442
## BodyPartRegionNon-Standard Code                                         0.546850
## BodyPartRegionNot Available                                             0.797603
## BodyPartRegionTrunk                                                     0.552907
## BodyPartRegionUpper Extremities                                         0.136934
## BodyPartAnkle                                                           0.826310
## BodyPartArtificial Appliance                                            0.532099
## BodyPartBody Systems and Multiple Body Systems                          0.001355
## BodyPartBrain                                                           0.000163
## BodyPartButtocks                                                        0.971725
## BodyPartChest                                                           0.951476
## BodyPartDisc-Trunk                                                      6.46e-06
## BodyPartEar(S)                                                          0.910929
## BodyPartElbow                                                           0.290868
## BodyPartEyes                                                            0.584517
## BodyPartFacial Bones                                                    0.239139
## BodyPartFinger(S)                                                       0.002332
## BodyPartFoot                                                            0.275565
## BodyPartGreat Toe                                                       0.407044
## BodyPartHand                                                            0.005362
## BodyPartHeart                                                           0.846339
## BodyPartHip                                                             0.537572
## BodyPartInsufficient Info to Properly Identify?Unclassified             0.004225
## BodyPartInternal Organs                                                 0.088511
## BodyPartKnee                                                            0.479840
## BodyPartLarynx                                                          0.341562
## BodyPartLower Arm                                                       0.079672
## BodyPartLower Back Area                                                 1.42e-12
## BodyPartLower Leg                                                       0.889560
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)             1.18e-06
## BodyPartLungs                                                           0.911069
## BodyPartMouth                                                           0.450487
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)     0.044873
## BodyPartMultiple Head Injury                                            0.041391
## BodyPartMultiple Lower Extremities                                      0.115405
## BodyPartMultiple Neck Injury                                            0.507006
## BodyPartMultiple Trunk                                                  0.142101
## BodyPartMultiple Upper Extremities                                      0.072988
## BodyPartNo Physical Injury                                              0.004345
## BodyPartNon-Standard Code                                                     NA
## BodyPartNose                                                            0.885414
## BodyPartNot Available                                                         NA
## BodyPartPelvis                                                          0.758063
## BodyPartSacrum And Coccyx                                               0.257593
## BodyPartShoulder(S)                                                     0.020855
## BodyPartSkull                                                           0.686873
## BodyPartSoft Tissue-Head                                                0.045997
## BodyPartSoft Tissue-Neck                                                0.046570
## BodyPartSpinal Cord-Trunk                                                < 2e-16
## BodyPartTeeth                                                                 NA
## BodyPartThumb                                                           0.109607
## BodyPartToes                                                            0.271051
## BodyPartTrachea                                                         0.399162
## BodyPartUpper Arm                                                       0.260544
## BodyPartUpper Back Area                                                 0.003466
## BodyPartUpper Leg                                                             NA
## BodyPartVertebrae                                                             NA
## BodyPartWhole Body                                                            NA
## BodyPartWrist                                                                 NA
## InjuryNatureAll Other Cumulative Injury, NOC                            0.737666
## InjuryNatureAll Other Occupational Disease Injury, NOC                  0.094923
## InjuryNatureAll Other Specific Injuries, Noc                            0.792729
## InjuryNatureAmputation                                                  0.676655
## InjuryNatureAngina Pectoris                                             0.874325
## InjuryNatureAsbestosis                                                  0.748108
## InjuryNatureAsphyxiation                                                0.609757
## InjuryNatureBurn                                                        0.818582
## InjuryNatureCancer                                                      0.733794
## InjuryNatureCarpal Tunnel Syndrome                                      0.850073
## InjuryNatureConcussion                                                  0.573506
## InjuryNatureContagious Disease                                          0.761027
## InjuryNatureContusion                                                   0.853542
## InjuryNatureCrushing                                                    0.898810
## InjuryNatureDermatitis                                                  0.942629
## InjuryNatureDislocation                                                 0.927506
## InjuryNatureDust Disease, NOC                                           0.974993
## InjuryNatureElectric Shock                                              0.933699
## InjuryNatureForeign Body                                                0.909779
## InjuryNatureFracture                                                    0.744607
## InjuryNatureFreezing                                                    0.895808
## InjuryNatureHearing Loss Or Impairment                                  0.827956
## InjuryNatureHeat Prostration                                            0.893215
## InjuryNatureHernia                                                      0.855272
## InjuryNatureInfection                                                   0.940411
## InjuryNatureInflammation                                                0.866624
## InjuryNatureLaceration                                                  0.890093
## InjuryNatureLoss of Hearing                                             0.757051
## InjuryNatureMental Disorder                                             0.880357
## InjuryNatureMental Stress                                               0.703833
## InjuryNatureMultiple Injuries Including Both Physical and Psychological 0.060153
## InjuryNatureMultiple Physical Injuries Only                             0.952654
## InjuryNatureMyocardial Infarction                                       0.891225
## InjuryNatureNo Physical Injury                                          0.993035
## InjuryNatureNon-Standard Code                                           0.861708
## InjuryNatureNot Available                                               0.944763
## InjuryNaturePoisoning?Chemical (Other Than Metals)                      0.997008
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)             0.849692
## InjuryNaturePuncture                                                    0.882230
## InjuryNatureRadiation                                                   0.646486
## InjuryNatureRespiratory Disorders                                       0.808660
## InjuryNatureRupture                                                     0.825795
## InjuryNatureSeverance                                                   0.342350
## InjuryNatureSilicosis                                                   0.991737
## InjuryNatureSprain                                                      0.993465
## InjuryNatureStrain                                                      0.948886
## InjuryNatureSyncope                                                     0.936375
## InjuryNatureVascular                                                    0.940265
## InjuryNatureVDT-Related Disease                                         0.939023
## InjuryNatureVision Loss                                                 0.855965
##                                                                            
## (Intercept)                                                                
## ClaimStatusO                                                            ***
## ClaimStatusR                                                            ***
## ClaimantAge_at_DOI                                                         
## GenderMale                                                              ** 
## GenderNot Available                                                     ***
## AverageWeeklyWage                                                          
## 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                                                              
## InjuryNatureAll Other Cumulative Injury, NOC                               
## InjuryNatureAll Other Occupational Disease Injury, NOC                  .  
## InjuryNatureAll Other Specific Injuries, Noc                               
## InjuryNatureAmputation                                                     
## InjuryNatureAngina Pectoris                                                
## InjuryNatureAsbestosis                                                     
## InjuryNatureAsphyxiation                                                   
## 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                                                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 94380 on 38269 degrees of freedom
##   (148297 observations deleted due to missingness)
## Multiple R-squared:  0.2321, Adjusted R-squared:  0.2299 
## F-statistic: 105.2 on 110 and 38269 DF,  p-value: < 2.2e-16
par(mfrow=c(2,2))
plot(df2.lm)
## Warning: not plotting observations with leverage one:
##   36528

Regresión con merge all FALSE

library(readxl)
library(dplyr)

##Regresión

Import Data

#file.choose()

claims_data <- read_xlsx("C:\\Users\\usuario\\Documents\\1 Tec\\Módulo 4\\ClaimsData2018.xlsx")
transactions <- read.csv("C:\\Users\\usuario\\Documents\\1 Tec\\Módulo 4\\TransactionsSummary2018.csv")

Clean Data

claims_data$TotalReserves <- as.numeric(claims_data$TotalReserves)
claims_data$IndemnityPaid <- as.numeric(claims_data$IndemnityPaid)
claims_data$OtherPaid <- as.numeric(claims_data$OtherPaid)
claims_data$TotalRecovery <- as.numeric(claims_data$TotalRecovery)
claims_data$ClaimantOpenedDate <- as.Date(claims_data$ClaimantOpenedDate, format = "%Y/%m/%d")
claims_data$ClaimantClosedDate <- as.Date(claims_data$ClaimantClosedDate, format = "%Y/%m/%d")
claims_data$ClaimantAge_at_DOI <- as.numeric(claims_data$ClaimantAge_at_DOI)
## Warning: NAs introduced by coercion
claims_data$AverageWeeklyWage <- as.numeric(claims_data$AverageWeeklyWage)
## Warning: NAs introduced by coercion

Merge

df <- merge(claims_data, transactions, by="ClaimID")

###Analysis

Create Total Incurred Cost per claim

df2 <- df
#summary(df2)
df2$TotalIncurredCost <- with(df2, TotalReserves + IndemnityPaid + OtherPaid - TotalRecovery)

Obtain the difference between closed and open dates to obtain the Claim Duration

df2$ClaimDuration  <- as.numeric(difftime(df2$ClaimantClosedDate, df2$ClaimantOpenedDate, units = c("days")))
#df2$ClaimDuration <- seq(from = df2$ClaimantOpenedDate, to = df2$ClaimantClosedDate, by = "day")
#summary(df2$ClaimDuration)

Multiple Regression

df2.lm <- lm(TotalIncurredCost ~ ClaimStatus + ClaimantAge_at_DOI + Gender + AverageWeeklyWage + BodyPartRegion + BodyPart + InjuryNature, data = df2)
summary(df2.lm)
## 
## Call:
## lm(formula = TotalIncurredCost ~ ClaimStatus + ClaimantAge_at_DOI + 
##     Gender + AverageWeeklyWage + BodyPartRegion + BodyPart + 
##     InjuryNature, data = df2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -551429  -14491   -5598    1450 4388096 
## 
## Coefficients: (6 not defined because of singularities)
##                                                                           Estimate
## (Intercept)                                                             -1.380e+04
## ClaimStatusO                                                             4.683e+05
## ClaimStatusR                                                             3.140e+05
## ClaimantAge_at_DOI                                                       2.465e+00
## GenderMale                                                               1.472e+03
## GenderNot Available                                                      6.876e+03
## AverageWeeklyWage                                                        1.562e+00
## BodyPartRegionLower Extremities                                          2.082e+04
## BodyPartRegionMultiple Body Parts                                        3.120e+04
## BodyPartRegionNeck                                                       1.082e+04
## BodyPartRegionNon-Standard Code                                         -1.049e+05
## BodyPartRegionTrunk                                                      1.399e+04
## BodyPartRegionUpper Extremities                                          1.516e+04
## BodyPartAnkle                                                           -1.001e+04
## BodyPartArtificial Appliance                                            -2.032e+04
## BodyPartBody Systems and Multiple Body Systems                          -2.204e+04
## BodyPartBrain                                                            2.893e+05
## BodyPartButtocks                                                         6.621e+03
## BodyPartChest                                                           -2.573e+03
## BodyPartDisc-Trunk                                                       7.555e+03
## BodyPartEar(S)                                                           8.138e+03
## BodyPartElbow                                                            1.638e+03
## BodyPartEyes                                                             6.534e+03
## BodyPartFacial Bones                                                     1.553e+04
## BodyPartFinger(S)                                                       -4.413e+03
## BodyPartFoot                                                            -1.056e+04
## BodyPartGreat Toe                                                       -1.586e+04
## BodyPartHand                                                            -3.314e+03
## BodyPartHeart                                                            9.716e+03
## BodyPartHip                                                              1.366e+04
## BodyPartInsufficient Info to Properly Identify?Unclassified             -1.921e+04
## BodyPartInternal Organs                                                  1.563e+03
## BodyPartKnee                                                            -9.204e+02
## BodyPartLarynx                                                           1.193e+03
## BodyPartLower Arm                                                       -3.095e+03
## BodyPartLower Back Area                                                  1.749e+04
## BodyPartLower Leg                                                        8.123e+03
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              1.174e+04
## BodyPartLungs                                                           -4.555e+03
## BodyPartMouth                                                            1.028e+04
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)     -3.367e+03
## BodyPartMultiple Head Injury                                             1.716e+04
## BodyPartMultiple Lower Extremities                                       3.655e+03
## BodyPartMultiple Neck Injury                                             7.373e+03
## BodyPartMultiple Trunk                                                  -5.047e+03
## BodyPartMultiple Upper Extremities                                       2.638e+03
## BodyPartNo Physical Injury                                              -1.163e+04
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                             1.253e+04
## BodyPartPelvis                                                          -2.266e+03
## BodyPartSacrum And Coccyx                                                1.989e+04
## BodyPartShoulder(S)                                                      4.195e+03
## BodyPartSkull                                                            3.431e+05
## BodyPartSoft Tissue-Head                                                 3.603e+04
## BodyPartSoft Tissue-Neck                                                 2.309e+03
## BodyPartSpinal Cord-Trunk                                                1.904e+05
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                           -2.846e+03
## BodyPartToes                                                            -1.867e+04
## BodyPartTrachea                                                          1.376e+03
## BodyPartUpper Arm                                                        1.318e+04
## BodyPartUpper Back Area                                                  2.898e+03
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## InjuryNatureAll Other Specific Injuries, Noc                             1.530e+04
## InjuryNatureAmputation                                                  -4.851e+03
## InjuryNatureAngina Pectoris                                             -6.129e+02
## InjuryNatureAsbestosis                                                   3.628e+04
## InjuryNatureAsphyxiation                                                -5.984e+03
## InjuryNatureBurn                                                         8.923e+03
## InjuryNatureCancer                                                       5.177e+04
## InjuryNatureCarpal Tunnel Syndrome                                       3.722e+03
## InjuryNatureConcussion                                                   3.789e+04
## InjuryNatureContagious Disease                                           1.927e+04
## InjuryNatureContusion                                                    5.713e+03
## InjuryNatureCrushing                                                     2.762e+03
## InjuryNatureDermatitis                                                  -7.598e+03
## InjuryNatureDislocation                                                 -2.871e+03
## InjuryNatureDust Disease, NOC                                           -5.205e+03
## InjuryNatureElectric Shock                                              -1.175e+04
## InjuryNatureForeign Body                                                 4.219e+03
## InjuryNatureFracture                                                     1.765e+04
## InjuryNatureHearing Loss Or Impairment                                  -8.284e+03
## InjuryNatureHeat Prostration                                            -7.248e+02
## InjuryNatureHernia                                                       4.244e+03
## InjuryNatureInfection                                                   -1.496e+03
## InjuryNatureInflammation                                                 5.371e+03
## InjuryNatureLaceration                                                   6.439e+02
## InjuryNatureLoss of Hearing                                              1.258e+04
## InjuryNatureMental Disorder                                             -1.752e+04
## InjuryNatureMental Stress                                               -6.199e+03
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  1.443e+04
## InjuryNatureMultiple Physical Injuries Only                              1.562e+03
## InjuryNatureMyocardial Infarction                                        1.280e+04
## InjuryNatureNo Physical Injury                                          -2.527e+03
## InjuryNatureNon-Standard Code                                           -2.257e+05
## InjuryNatureNot Available                                                2.269e+03
## InjuryNaturePoisoning?Chemical (Other Than Metals)                      -7.585e+03
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)             -1.675e+03
## InjuryNaturePuncture                                                    -1.877e+03
## InjuryNatureRadiation                                                    3.822e+04
## InjuryNatureRespiratory Disorders                                        6.727e+03
## InjuryNatureRupture                                                      5.642e+03
## InjuryNatureSeverance                                                    3.241e+04
## InjuryNatureSprain                                                       3.215e+03
## InjuryNatureStrain                                                       6.812e+02
## InjuryNatureSyncope                                                      7.100e+03
## InjuryNatureVascular                                                     2.160e+03
## InjuryNatureVDT-Related Disease                                         -1.241e+04
## InjuryNatureVision Loss                                                  5.509e+03
##                                                                         Std. Error
## (Intercept)                                                              6.114e+04
## ClaimStatusO                                                             4.452e+03
## ClaimStatusR                                                             5.669e+03
## ClaimantAge_at_DOI                                                       5.414e+00
## GenderMale                                                               1.413e+03
## GenderNot Available                                                      9.639e+03
## AverageWeeklyWage                                                        7.212e-01
## BodyPartRegionLower Extremities                                          1.421e+04
## BodyPartRegionMultiple Body Parts                                        3.225e+04
## BodyPartRegionNeck                                                       4.389e+04
## BodyPartRegionNon-Standard Code                                          6.110e+04
## BodyPartRegionTrunk                                                      1.372e+04
## BodyPartRegionUpper Extremities                                          1.223e+04
## BodyPartAnkle                                                            8.691e+03
## BodyPartArtificial Appliance                                             6.696e+04
## BodyPartBody Systems and Multiple Body Systems                           3.189e+04
## BodyPartBrain                                                            4.071e+04
## BodyPartButtocks                                                         1.256e+04
## BodyPartChest                                                            8.947e+03
## BodyPartDisc-Trunk                                                       9.764e+03
## BodyPartEar(S)                                                           1.898e+04
## BodyPartElbow                                                            6.720e+03
## BodyPartEyes                                                             1.310e+04
## BodyPartFacial Bones                                                     1.553e+04
## BodyPartFinger(S)                                                        4.644e+03
## BodyPartFoot                                                             8.900e+03
## BodyPartGreat Toe                                                        1.658e+04
## BodyPartHand                                                             4.547e+03
## BodyPartHeart                                                            4.244e+04
## BodyPartHip                                                              1.027e+04
## BodyPartInsufficient Info to Properly Identify?Unclassified              3.100e+04
## BodyPartInternal Organs                                                  1.772e+04
## BodyPartKnee                                                             8.235e+03
## BodyPartLarynx                                                           9.458e+04
## BodyPartLower Arm                                                        5.854e+03
## BodyPartLower Back Area                                                  7.291e+03
## BodyPartLower Leg                                                        9.268e+03
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              8.692e+03
## BodyPartLungs                                                            1.351e+04
## BodyPartMouth                                                            1.562e+04
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      3.007e+04
## BodyPartMultiple Head Injury                                             1.239e+04
## BodyPartMultiple Lower Extremities                                       9.831e+03
## BodyPartMultiple Neck Injury                                             4.252e+04
## BodyPartMultiple Trunk                                                   1.820e+04
## BodyPartMultiple Upper Extremities                                       6.966e+03
## BodyPartNo Physical Injury                                               3.128e+04
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                             1.613e+04
## BodyPartPelvis                                                           1.452e+04
## BodyPartSacrum And Coccyx                                                2.541e+04
## BodyPartShoulder(S)                                                      4.477e+03
## BodyPartSkull                                                            5.024e+04
## BodyPartSoft Tissue-Head                                                 8.590e+04
## BodyPartSoft Tissue-Neck                                                 4.286e+04
## BodyPartSpinal Cord-Trunk                                                2.459e+04
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                            6.305e+03
## BodyPartToes                                                             1.300e+04
## BodyPartTrachea                                                          6.496e+04
## BodyPartUpper Arm                                                        7.024e+03
## BodyPartUpper Back Area                                                  1.031e+04
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## InjuryNatureAll Other Specific Injuries, Noc                             6.006e+04
## InjuryNatureAmputation                                                   6.478e+04
## InjuryNatureAngina Pectoris                                              6.638e+04
## InjuryNatureAsbestosis                                                   6.393e+04
## InjuryNatureAsphyxiation                                                 1.037e+05
## InjuryNatureBurn                                                         6.037e+04
## InjuryNatureCancer                                                       8.483e+04
## InjuryNatureCarpal Tunnel Syndrome                                       6.036e+04
## InjuryNatureConcussion                                                   6.095e+04
## InjuryNatureContagious Disease                                           6.127e+04
## InjuryNatureContusion                                                    6.000e+04
## InjuryNatureCrushing                                                     6.066e+04
## InjuryNatureDermatitis                                                   6.033e+04
## InjuryNatureDislocation                                                  6.050e+04
## InjuryNatureDust Disease, NOC                                            8.489e+04
## InjuryNatureElectric Shock                                               6.216e+04
## InjuryNatureForeign Body                                                 6.039e+04
## InjuryNatureFracture                                                     6.007e+04
## InjuryNatureHearing Loss Or Impairment                                   7.246e+04
## InjuryNatureHeat Prostration                                             6.186e+04
## InjuryNatureHernia                                                       6.132e+04
## InjuryNatureInfection                                                    6.101e+04
## InjuryNatureInflammation                                                 6.027e+04
## InjuryNatureLaceration                                                   6.004e+04
## InjuryNatureLoss of Hearing                                              6.865e+04
## InjuryNatureMental Disorder                                              7.125e+04
## InjuryNatureMental Stress                                                6.075e+04
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  6.341e+04
## InjuryNatureMultiple Physical Injuries Only                              6.015e+04
## InjuryNatureMyocardial Infarction                                        7.387e+04
## InjuryNatureNo Physical Injury                                           6.019e+04
## InjuryNatureNon-Standard Code                                            8.492e+04
## InjuryNatureNot Available                                                1.037e+05
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       6.206e+04
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              6.625e+04
## InjuryNaturePuncture                                                     6.010e+04
## InjuryNatureRadiation                                                    7.346e+04
## InjuryNatureRespiratory Disorders                                        6.072e+04
## InjuryNatureRupture                                                      6.164e+04
## InjuryNatureSeverance                                                    6.799e+04
## InjuryNatureSprain                                                       6.004e+04
## InjuryNatureStrain                                                       6.001e+04
## InjuryNatureSyncope                                                      6.162e+04
## InjuryNatureVascular                                                     1.037e+05
## InjuryNatureVDT-Related Disease                                          1.039e+05
## InjuryNatureVision Loss                                                  6.819e+04
##                                                                         t value
## (Intercept)                                                              -0.226
## ClaimStatusO                                                            105.201
## ClaimStatusR                                                             55.382
## ClaimantAge_at_DOI                                                        0.455
## GenderMale                                                                1.041
## GenderNot Available                                                       0.713
## AverageWeeklyWage                                                         2.166
## BodyPartRegionLower Extremities                                           1.465
## BodyPartRegionMultiple Body Parts                                         0.967
## BodyPartRegionNeck                                                        0.246
## BodyPartRegionNon-Standard Code                                          -1.717
## BodyPartRegionTrunk                                                       1.020
## BodyPartRegionUpper Extremities                                           1.239
## BodyPartAnkle                                                            -1.152
## BodyPartArtificial Appliance                                             -0.303
## BodyPartBody Systems and Multiple Body Systems                           -0.691
## BodyPartBrain                                                             7.106
## BodyPartButtocks                                                          0.527
## BodyPartChest                                                            -0.288
## BodyPartDisc-Trunk                                                        0.774
## BodyPartEar(S)                                                            0.429
## BodyPartElbow                                                             0.244
## BodyPartEyes                                                              0.499
## BodyPartFacial Bones                                                      1.000
## BodyPartFinger(S)                                                        -0.950
## BodyPartFoot                                                             -1.186
## BodyPartGreat Toe                                                        -0.957
## BodyPartHand                                                             -0.729
## BodyPartHeart                                                             0.229
## BodyPartHip                                                               1.329
## BodyPartInsufficient Info to Properly Identify?Unclassified              -0.620
## BodyPartInternal Organs                                                   0.088
## BodyPartKnee                                                             -0.112
## BodyPartLarynx                                                            0.013
## BodyPartLower Arm                                                        -0.529
## BodyPartLower Back Area                                                   2.399
## BodyPartLower Leg                                                         0.876
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)               1.351
## BodyPartLungs                                                            -0.337
## BodyPartMouth                                                             0.658
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      -0.112
## BodyPartMultiple Head Injury                                              1.384
## BodyPartMultiple Lower Extremities                                        0.372
## BodyPartMultiple Neck Injury                                              0.173
## BodyPartMultiple Trunk                                                   -0.277
## BodyPartMultiple Upper Extremities                                        0.379
## BodyPartNo Physical Injury                                               -0.372
## BodyPartNon-Standard Code                                                    NA
## BodyPartNose                                                              0.777
## BodyPartPelvis                                                           -0.156
## BodyPartSacrum And Coccyx                                                 0.783
## BodyPartShoulder(S)                                                       0.937
## BodyPartSkull                                                             6.829
## BodyPartSoft Tissue-Head                                                  0.419
## BodyPartSoft Tissue-Neck                                                  0.054
## BodyPartSpinal Cord-Trunk                                                 7.743
## BodyPartTeeth                                                                NA
## BodyPartThumb                                                            -0.451
## BodyPartToes                                                             -1.436
## BodyPartTrachea                                                           0.021
## BodyPartUpper Arm                                                         1.876
## BodyPartUpper Back Area                                                   0.281
## BodyPartUpper Leg                                                            NA
## BodyPartVertebrae                                                            NA
## BodyPartWhole Body                                                           NA
## BodyPartWrist                                                                NA
## InjuryNatureAll Other Specific Injuries, Noc                              0.255
## InjuryNatureAmputation                                                   -0.075
## InjuryNatureAngina Pectoris                                              -0.009
## InjuryNatureAsbestosis                                                    0.567
## InjuryNatureAsphyxiation                                                 -0.058
## InjuryNatureBurn                                                          0.148
## InjuryNatureCancer                                                        0.610
## InjuryNatureCarpal Tunnel Syndrome                                        0.062
## InjuryNatureConcussion                                                    0.622
## InjuryNatureContagious Disease                                            0.315
## InjuryNatureContusion                                                     0.095
## InjuryNatureCrushing                                                      0.046
## InjuryNatureDermatitis                                                   -0.126
## InjuryNatureDislocation                                                  -0.047
## InjuryNatureDust Disease, NOC                                            -0.061
## InjuryNatureElectric Shock                                               -0.189
## InjuryNatureForeign Body                                                  0.070
## InjuryNatureFracture                                                      0.294
## InjuryNatureHearing Loss Or Impairment                                   -0.114
## InjuryNatureHeat Prostration                                             -0.012
## InjuryNatureHernia                                                        0.069
## InjuryNatureInfection                                                    -0.025
## InjuryNatureInflammation                                                  0.089
## InjuryNatureLaceration                                                    0.011
## InjuryNatureLoss of Hearing                                               0.183
## InjuryNatureMental Disorder                                              -0.246
## InjuryNatureMental Stress                                                -0.102
## InjuryNatureMultiple Injuries Including Both Physical and Psychological   0.228
## InjuryNatureMultiple Physical Injuries Only                               0.026
## InjuryNatureMyocardial Infarction                                         0.173
## InjuryNatureNo Physical Injury                                           -0.042
## InjuryNatureNon-Standard Code                                            -2.657
## InjuryNatureNot Available                                                 0.022
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       -0.122
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              -0.025
## InjuryNaturePuncture                                                     -0.031
## InjuryNatureRadiation                                                     0.520
## InjuryNatureRespiratory Disorders                                         0.111
## InjuryNatureRupture                                                       0.092
## InjuryNatureSeverance                                                     0.477
## InjuryNatureSprain                                                        0.054
## InjuryNatureStrain                                                        0.011
## InjuryNatureSyncope                                                       0.115
## InjuryNatureVascular                                                      0.021
## InjuryNatureVDT-Related Disease                                          -0.120
## InjuryNatureVision Loss                                                   0.081
##                                                                         Pr(>|t|)
## (Intercept)                                                              0.82135
## ClaimStatusO                                                             < 2e-16
## ClaimStatusR                                                             < 2e-16
## ClaimantAge_at_DOI                                                       0.64894
## GenderMale                                                               0.29766
## GenderNot Available                                                      0.47560
## AverageWeeklyWage                                                        0.03036
## BodyPartRegionLower Extremities                                          0.14307
## BodyPartRegionMultiple Body Parts                                        0.33337
## BodyPartRegionNeck                                                       0.80534
## BodyPartRegionNon-Standard Code                                          0.08606
## BodyPartRegionTrunk                                                      0.30784
## BodyPartRegionUpper Extremities                                          0.21518
## BodyPartAnkle                                                            0.24929
## BodyPartArtificial Appliance                                             0.76157
## BodyPartBody Systems and Multiple Body Systems                           0.48960
## BodyPartBrain                                                           1.25e-12
## BodyPartButtocks                                                         0.59810
## BodyPartChest                                                            0.77365
## BodyPartDisc-Trunk                                                       0.43911
## BodyPartEar(S)                                                           0.66811
## BodyPartElbow                                                            0.80746
## BodyPartEyes                                                             0.61787
## BodyPartFacial Bones                                                     0.31719
## BodyPartFinger(S)                                                        0.34193
## BodyPartFoot                                                             0.23559
## BodyPartGreat Toe                                                        0.33867
## BodyPartHand                                                             0.46612
## BodyPartHeart                                                            0.81893
## BodyPartHip                                                              0.18372
## BodyPartInsufficient Info to Properly Identify?Unclassified              0.53555
## BodyPartInternal Organs                                                  0.92971
## BodyPartKnee                                                             0.91101
## BodyPartLarynx                                                           0.98994
## BodyPartLower Arm                                                        0.59706
## BodyPartLower Back Area                                                  0.01647
## BodyPartLower Leg                                                        0.38079
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              0.17669
## BodyPartLungs                                                            0.73598
## BodyPartMouth                                                            0.51034
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      0.91086
## BodyPartMultiple Head Injury                                             0.16632
## BodyPartMultiple Lower Extremities                                       0.71005
## BodyPartMultiple Neck Injury                                             0.86234
## BodyPartMultiple Trunk                                                   0.78162
## BodyPartMultiple Upper Extremities                                       0.70488
## BodyPartNo Physical Injury                                               0.70993
## BodyPartNon-Standard Code                                                     NA
## BodyPartNose                                                             0.43713
## BodyPartPelvis                                                           0.87598
## BodyPartSacrum And Coccyx                                                0.43379
## BodyPartShoulder(S)                                                      0.34880
## BodyPartSkull                                                           8.88e-12
## BodyPartSoft Tissue-Head                                                 0.67490
## BodyPartSoft Tissue-Neck                                                 0.95704
## BodyPartSpinal Cord-Trunk                                               1.03e-14
## BodyPartTeeth                                                                 NA
## BodyPartThumb                                                            0.65175
## BodyPartToes                                                             0.15106
## BodyPartTrachea                                                          0.98310
## BodyPartUpper Arm                                                        0.06063
## BodyPartUpper Back Area                                                  0.77875
## BodyPartUpper Leg                                                             NA
## BodyPartVertebrae                                                             NA
## BodyPartWhole Body                                                            NA
## BodyPartWrist                                                                 NA
## InjuryNatureAll Other Specific Injuries, Noc                             0.79894
## InjuryNatureAmputation                                                   0.94030
## InjuryNatureAngina Pectoris                                              0.99263
## InjuryNatureAsbestosis                                                   0.57042
## InjuryNatureAsphyxiation                                                 0.95398
## InjuryNatureBurn                                                         0.88250
## InjuryNatureCancer                                                       0.54170
## InjuryNatureCarpal Tunnel Syndrome                                       0.95084
## InjuryNatureConcussion                                                   0.53420
## InjuryNatureContagious Disease                                           0.75311
## InjuryNatureContusion                                                    0.92414
## InjuryNatureCrushing                                                     0.96369
## InjuryNatureDermatitis                                                   0.89979
## InjuryNatureDislocation                                                  0.96216
## InjuryNatureDust Disease, NOC                                            0.95111
## InjuryNatureElectric Shock                                               0.85012
## InjuryNatureForeign Body                                                 0.94431
## InjuryNatureFracture                                                     0.76887
## InjuryNatureHearing Loss Or Impairment                                   0.90898
## InjuryNatureHeat Prostration                                             0.99065
## InjuryNatureHernia                                                       0.94482
## InjuryNatureInfection                                                    0.98043
## InjuryNatureInflammation                                                 0.92898
## InjuryNatureLaceration                                                   0.99144
## InjuryNatureLoss of Hearing                                              0.85462
## InjuryNatureMental Disorder                                              0.80580
## InjuryNatureMental Stress                                                0.91873
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  0.81994
## InjuryNatureMultiple Physical Injuries Only                              0.97929
## InjuryNatureMyocardial Infarction                                        0.86246
## InjuryNatureNo Physical Injury                                           0.96650
## InjuryNatureNon-Standard Code                                            0.00788
## InjuryNatureNot Available                                                0.98254
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       0.90274
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              0.97983
## InjuryNaturePuncture                                                     0.97509
## InjuryNatureRadiation                                                    0.60289
## InjuryNatureRespiratory Disorders                                        0.91178
## InjuryNatureRupture                                                      0.92707
## InjuryNatureSeverance                                                    0.63362
## InjuryNatureSprain                                                       0.95729
## InjuryNatureStrain                                                       0.99094
## InjuryNatureSyncope                                                      0.90826
## InjuryNatureVascular                                                     0.98339
## InjuryNatureVDT-Related Disease                                          0.90487
## InjuryNatureVision Loss                                                  0.93561
##                                                                            
## (Intercept)                                                                
## ClaimStatusO                                                            ***
## ClaimStatusR                                                            ***
## ClaimantAge_at_DOI                                                         
## GenderMale                                                                 
## GenderNot Available                                                        
## AverageWeeklyWage                                                       *  
## BodyPartRegionLower Extremities                                            
## BodyPartRegionMultiple Body Parts                                          
## BodyPartRegionNeck                                                         
## BodyPartRegionNon-Standard Code                                         .  
## 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                                                               
## 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                                                              
## InjuryNatureAll Other Specific Injuries, Noc                               
## InjuryNatureAmputation                                                     
## InjuryNatureAngina Pectoris                                                
## InjuryNatureAsbestosis                                                     
## InjuryNatureAsphyxiation                                                   
## InjuryNatureBurn                                                           
## InjuryNatureCancer                                                         
## InjuryNatureCarpal Tunnel Syndrome                                         
## InjuryNatureConcussion                                                     
## InjuryNatureContagious Disease                                             
## InjuryNatureContusion                                                      
## InjuryNatureCrushing                                                       
## InjuryNatureDermatitis                                                     
## InjuryNatureDislocation                                                    
## InjuryNatureDust Disease, NOC                                              
## InjuryNatureElectric Shock                                                 
## InjuryNatureForeign Body                                                   
## InjuryNatureFracture                                                       
## 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                                                      
## InjuryNatureSprain                                                         
## InjuryNatureStrain                                                         
## InjuryNatureSyncope                                                        
## InjuryNatureVascular                                                       
## InjuryNatureVDT-Related Disease                                            
## InjuryNatureVision Loss                                                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 84570 on 15020 degrees of freedom
##   (40870 observations deleted due to missingness)
## Multiple R-squared:  0.5016, Adjusted R-squared:  0.4981 
## F-statistic:   144 on 105 and 15020 DF,  p-value: < 2.2e-16
par(mfrow=c(2,2))
plot(df2.lm)
## Warning: not plotting observations with leverage one:
##   773, 1285, 2195, 3588, 3749, 15116

Árbol de decisión

1. Importar bases de datos

library(readxl)
claims <- claims_data
transactions <- transactions

Unir bases de datos

df <- merge(claims, transactions, by="ClaimID", all=TRUE)
View(df)

2. Entender la base de datos

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

3. Limpiar la base de datos

#library(dplyr)
#Convertir a numericos
df$IndemnityPaid <- as.numeric(df$IndemnityPaid)
df$TotalPaid <- as.numeric(df$TotalPaid)
df$TotalReserves <- as.numeric(df$TotalReserves)
df$TotalRecovery <- as.numeric(df$TotalRecovery)
df$IndemnityPaid <- as.numeric(df$IndemnityPaid)
df$OtherPaid <- as.numeric(df$OtherPaid)
df$AverageWeeklyWage <- as.numeric(df$AverageWeeklyWage)
df$ClaimantAge_at_DOI <- as.numeric(df$ClaimantAge_at_DOI)

df$TotalIncurredCost <- with(df, TotalReserves + IndemnityPaid + OtherPaid - TotalRecovery)

# Eliminar Totales negativos
df <- df[df$TotalIncurredCost>=0,]
df <- df[df$BillReviewALE>=0,]
df <- df[df$Hospital>=0,]
df <- df[df$PhysicianOutpatient>=0,]
df <- df[df$Rx>=0,]
# Cuantos NA's hay por variable
sapply(df, function(x) sum(is.na(x)))
##                  ClaimID                TotalPaid            TotalReserves 
##                   181492                   181492                   181492 
##            TotalRecovery            IndemnityPaid                OtherPaid 
##                   181492                   181492                   181492 
##              ClaimStatus             IncidentDate      IncidentDescription 
##                   181492                   181492                   181492 
##         ReturnToWorkDate        AverageWeeklyWage       ClaimantOpenedDate 
##                   184160                   184958                   181492 
##       ClaimantClosedDate EmployerNotificationDate             ReceivedDate 
##                   181529                   181685                   181492 
##                 IsDenied       ClaimantAge_at_DOI                   Gender 
##                   181492                   183099                   181492 
##             ClaimantType             InjuryNature           BodyPartRegion 
##                   181492                   181492                   181492 
##                 BodyPart            BillReviewALE                 Hospital 
##                   181492                   181492                   181492 
##      PhysicianOutpatient                       Rx        TotalIncurredCost 
##                   181492                   181492                   181492
summary(df)
##     ClaimID           TotalPaid        TotalReserves    TotalRecovery     
##  Min.   :  777625   Min.   :     0.0   Min.   :     0   Min.   :    0.00  
##  1st Qu.:  793154   1st Qu.:    67.4   1st Qu.:     0   1st Qu.:    0.00  
##  Median :  803511   Median :   240.7   Median :     0   Median :    0.00  
##  Mean   : 1672130   Mean   :  6187.5   Mean   :  1707   Mean   :   50.73  
##  3rd Qu.:  813440   3rd Qu.:   851.9   3rd Qu.:     0   3rd Qu.:    0.00  
##  Max.   :36094375   Max.   :755038.3   Max.   :899411   Max.   :25044.20  
##  NA's   :181492     NA's   :181492     NA's   :181492   NA's   :181492    
##  IndemnityPaid      OtherPaid        ClaimStatus       
##  Min.   :     0   Min.   :     0.0   Length:186571     
##  1st Qu.:     0   1st Qu.:    66.7   Class :character  
##  Median :     0   Median :   235.7   Mode  :character  
##  Mean   :  2852   Mean   :  3335.7                     
##  3rd Qu.:     0   3rd Qu.:   783.3                     
##  Max.   :314577   Max.   :623298.0                     
##  NA's   :181492   NA's   :181492                       
##   IncidentDate                    IncidentDescription
##  Min.   :1982-09-16 00:00:00.00   Length:186571      
##  1st Qu.:2001-05-24 00:00:00.00   Class :character   
##  Median :2003-06-03 00:00:00.00   Mode  :character   
##  Mean   :2002-12-19 00:57:33.27                      
##  3rd Qu.:2005-02-23 00:00:00.00                      
##  Max.   :2013-09-12 00:00:00.00                      
##  NA's   :181492                                      
##  ReturnToWorkDate                 AverageWeeklyWage ClaimantOpenedDate  
##  Min.   :1992-05-01 00:00:00.00   Min.   :   0.23   Min.   :1982-09-16  
##  1st Qu.:2003-05-28 00:00:00.00   1st Qu.: 346.40   1st Qu.:2001-06-19  
##  Median :2004-11-18 00:00:00.00   Median : 472.79   Median :2003-07-11  
##  Mean   :2004-03-29 03:13:30.77   Mean   : 490.53   Mean   :2003-02-07  
##  3rd Qu.:2005-10-25 00:00:00.00   3rd Qu.: 616.81   3rd Qu.:2005-04-11  
##  Max.   :2013-09-12 00:00:00.00   Max.   :7409.77   Max.   :2013-09-18  
##  NA's   :184160                   NA's   :184958    NA's   :181492      
##  ClaimantClosedDate   EmployerNotificationDate        
##  Min.   :1999-07-12   Min.   :1990-10-10 00:00:00.00  
##  1st Qu.:2005-03-31   1st Qu.:2001-08-01 12:00:00.00  
##  Median :2005-04-25   Median :2003-07-17 00:00:00.00  
##  Mean   :2006-05-07   Mean   :2003-04-23 08:55:30.33  
##  3rd Qu.:2007-07-20   3rd Qu.:2005-03-22 00:00:00.00  
##  Max.   :2014-06-25   Max.   :2013-09-12 00:00:00.00  
##  NA's   :181529       NA's   :181685                  
##   ReceivedDate                     IsDenied         ClaimantAge_at_DOI
##  Min.   :1982-09-16 00:00:00.0   Length:186571      Min.   :-80.00    
##  1st Qu.:2001-06-19 00:00:00.0   Class :character   1st Qu.: 33.00    
##  Median :2003-07-10 00:00:00.0   Mode  :character   Median : 42.00    
##  Mean   :2003-10-13 12:02:24.6                      Mean   : 41.46    
##  3rd Qu.:2005-04-06 00:00:00.0                      3rd Qu.: 50.00    
##  Max.   :5202-01-10 00:00:00.0                      Max.   : 94.00    
##  NA's   :181492                                     NA's   :183099    
##     Gender          ClaimantType       InjuryNature       BodyPartRegion    
##  Length:186571      Length:186571      Length:186571      Length:186571     
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    BodyPart         BillReviewALE        Hospital         PhysicianOutpatient
##  Length:186571      Min.   :    0.0   Min.   :      0.0   Min.   :      0    
##  Class :character   1st Qu.:   40.0   1st Qu.:    775.9   1st Qu.:    627    
##  Mode  :character   Median :  144.0   Median :   3609.9   Median :   3897    
##                     Mean   :  722.6   Mean   :  14363.7   Mean   :  10604    
##                     3rd Qu.:  516.8   3rd Qu.:  12562.1   3rd Qu.:  10990    
##                     Max.   :56475.3   Max.   :2759604.0   Max.   :1481469    
##                     NA's   :181492    NA's   :181492      NA's   :181492     
##        Rx           TotalIncurredCost  
##  Min.   :     0.0   Min.   :      0.0  
##  1st Qu.:    48.3   1st Qu.:     65.3  
##  Median :   183.3   Median :    235.1  
##  Mean   :  4900.2   Mean   :   7843.8  
##  3rd Qu.:   953.9   3rd Qu.:    832.8  
##  Max.   :631635.5   Max.   :1654449.4  
##  NA's   :181492     NA's   :181492
library(rpart)
library(rpart.plot)
arbol1 <- rpart(formula = InjuryNature~TotalIncurredCost, data=df)
rpart.plot(arbol1)

arbol2 <- rpart(formula = AverageWeeklyWage~TotalIncurredCost, data=df)
rpart.plot(arbol2)

LS0tDQp0aXRsZTogIkFjdGl2aWRhZCA0LjYiDQphdXRob3I6ICJFcXVpcG8gMSINCmRhdGU6ICIyMDIzLTA5LTI2Ig0Kb3V0cHV0OiAgDQogIGh0bWxfZG9jdW1lbnQ6DQogICAgdG9jOiBUUlVFDQogICAgdG9jX2Zsb2F0OiBUUlVFDQogICAgY29kZV9kb3dubG9hZDogVFJVRQ0KICAgIHRoZW1lOiAic2ltcGxleCINCiAgICBoaWdobGlnaHQ6ICJtb25vY2hyb21lIg0KLS0tDQoNCmBgYHtyIG1lc3NhZ2U9RkFMU0V9DQpsaWJyYXJ5KHJlYWR4b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