Regresion Lineal

Entender la base de datos

df <- read.csv("C:\\Users\\maria\\OneDrive\\Desktop\\AD24\\Modulo 2\\seguros.csv")

resumen <- summary(df)
resumen
##     ClaimID           TotalPaid       TotalReserves     TotalRecovery      
##  Min.   :  777632   Min.   :      0   Min.   :      0   Min.   :     0.00  
##  1st Qu.:  800748   1st Qu.:     83   1st Qu.:      0   1st Qu.:     0.00  
##  Median :  812128   Median :    271   Median :      0   Median :     0.00  
##  Mean   : 1864676   Mean   :  10404   Mean   :   3368   Mean   :    66.05  
##  3rd Qu.:  824726   3rd Qu.:   1122   3rd Qu.:      0   3rd Qu.:     0.00  
##  Max.   :62203364   Max.   :4527291   Max.   :1529053   Max.   :100000.00  
##                                                                            
##  IndemnityPaid      OtherPaid       TotalIncurredCost ClaimStatus       
##  Min.   :     0   Min.   :      0   Min.   : -10400   Length:31619      
##  1st Qu.:     0   1st Qu.:     80   1st Qu.:     80   Class :character  
##  Median :     0   Median :    265   Median :    266   Mode  :character  
##  Mean   :  4977   Mean   :   5427   Mean   :  13706                     
##  3rd Qu.:     0   3rd Qu.:   1023   3rd Qu.:   1098                     
##  Max.   :640732   Max.   :4129915   Max.   :4734750                     
##                                                                         
##  IncidentDate       IncidentDescription ReturnToWorkDate   ClaimantOpenedDate
##  Length:31619       Length:31619        Length:31619       Length:31619      
##  Class :character   Class :character    Class :character   Class :character  
##  Mode  :character   Mode  :character    Mode  :character   Mode  :character  
##                                                                              
##                                                                              
##                                                                              
##                                                                              
##  ClaimantClosedDate EmployerNotificationDate ReceivedDate      
##  Length:31619       Length:31619             Length:31619      
##  Class :character   Class :character         Class :character  
##  Mode  :character   Mode  :character         Mode  :character  
##                                                                
##                                                                
##                                                                
##                                                                
##     IsDenied       Transaction_Time Procesing_Time     ClaimantAge_at_DOI
##  Min.   :0.00000   Min.   :    0    Min.   :    0.00   Min.   :14.0      
##  1st Qu.:0.00000   1st Qu.:  211    1st Qu.:    4.00   1st Qu.:33.0      
##  Median :0.00000   Median :  780    Median :   10.00   Median :42.0      
##  Mean   :0.04463   Mean   : 1004    Mean   :   62.99   Mean   :41.6      
##  3rd Qu.:0.00000   3rd Qu.: 1440    3rd Qu.:   24.00   3rd Qu.:50.0      
##  Max.   :1.00000   Max.   :16428    Max.   :11558.00   Max.   :94.0      
##                    NA's   :614                                           
##     Gender          ClaimantType       InjuryNature       BodyPartRegion    
##  Length:31619       Length:31619       Length:31619       Length:31619      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    BodyPart         AverageWeeklyWage1    ClaimID1        BillReviewALE    
##  Length:31619       Min.   : 100.0     Min.   :  777632   Min.   : -448.0  
##  Class :character   1st Qu.: 492.0     1st Qu.:  800748   1st Qu.:   16.0  
##  Mode  :character   Median : 492.0     Median :  812128   Median :   24.0  
##                     Mean   : 536.5     Mean   : 1864676   Mean   :  188.7  
##                     3rd Qu.: 492.0     3rd Qu.:  824726   3rd Qu.:   64.1  
##                     Max.   :8613.5     Max.   :62203364   Max.   :46055.3  
##                                                           NA's   :14912    
##     Hospital         PhysicianOutpatient       Rx          
##  Min.   : -12570.4   Min.   :   -549.5   Min.   :  -160.7  
##  1st Qu.:    210.5   1st Qu.:    105.8   1st Qu.:    22.9  
##  Median :    613.9   Median :    218.0   Median :    61.5  
##  Mean   :   5113.2   Mean   :   1813.2   Mean   :  1695.2  
##  3rd Qu.:   2349.1   3rd Qu.:    680.6   3rd Qu.:   189.0  
##  Max.   :2759604.0   Max.   :1219766.6   Max.   :631635.5  
##  NA's   :19655       NA's   :2329        NA's   :20730
str(df)
## 'data.frame':    31619 obs. of  30 variables:
##  $ ClaimID                 : int  777632 777646 777651 777661 777666 777668 777673 777676 777681 777694 ...
##  $ TotalPaid               : num  20 0 5407 288 235 ...
##  $ TotalReserves           : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ TotalRecovery           : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ IndemnityPaid           : num  0 0 2246 0 0 ...
##  $ OtherPaid               : num  20 0 3161 288 235 ...
##  $ TotalIncurredCost       : num  20 0 5407 288 235 ...
##  $ ClaimStatus             : chr  "C" "C" "C" "C" ...
##  $ IncidentDate            : chr  "01-jul-99" "01-jul-99" "02-jul-99" "02-jul-99" ...
##  $ IncidentDescription     : chr  "EE. States while going down the steps--EE foot slipped & she fell down to cement on ground--injurher rt. Knee, "| __truncated__ "Neck, arm, wrist and neck... On going for 20 yrs, repetitive, performing ultrasound exam on patients. Repetitiv"| __truncated__ "EE was removing items from freezer when items started to fall - EE had to get out of way of falling boxes- strained back" "EE states the fumes from a truck caused her to getan upset stomach and headache." ...
##  $ ReturnToWorkDate        : chr  "" "" "" "" ...
##  $ ClaimantOpenedDate      : chr  "12-jul-99" "29-sep-05" "14-jul-99" "20-jul-99" ...
##  $ ClaimantClosedDate      : chr  "31-mar-05" "22DEC2005" "31-mar-05" "17-jun-08" ...
##  $ EmployerNotificationDate: chr  "01-jul-99" "01-jul-99" "02-jul-99" "02-jul-99" ...
##  $ ReceivedDate            : chr  "12-jul-99" "29-sep-05" "13-jul-99" "20-jul-99" ...
##  $ IsDenied                : int  0 1 0 0 0 0 0 0 0 0 ...
##  $ Transaction_Time        : int  2089 84 2087 3255 2050 2195 2493 2058 2086 2900 ...
##  $ Procesing_Time          : int  11 2282 12 18 49 9 8 39 10 13 ...
##  $ ClaimantAge_at_DOI      : int  49 48 33 29 54 49 38 48 40 51 ...
##  $ Gender                  : chr  "Female" "Female" "Female" "Female" ...
##  $ ClaimantType            : chr  "Medical Only" "Indemnity" "Indemnity" "Medical Only" ...
##  $ InjuryNature            : chr  "Laceration" "All Other Specific Injuries, Noc" "Strain" "Respiratory Disorders" ...
##  $ BodyPartRegion          : chr  "Multiple Body Parts" "Multiple Body Parts" "Trunk" "Multiple Body Parts" ...
##  $ BodyPart                : chr  "Multiple Body Parts (Including Body Systems and Body Parts)" "Multiple Body Parts (Including Body Systems and Body Parts)" "Lower Back Area" "Multiple Body Parts (Including Body Systems and Body Parts)" ...
##  $ AverageWeeklyWage1      : num  492 673 328 492 492 ...
##  $ ClaimID1                : int  777632 777646 777651 777661 777666 777668 777673 777676 777681 777694 ...
##  $ BillReviewALE           : num  NA 592 NA NA NA ...
##  $ Hospital                : num  NA 36342 299 NA NA ...
##  $ PhysicianOutpatient     : num  NA 41773.4 155 65.5 221.6 ...
##  $ Rx                      : num  50.3 3108.5 NA NA NA ...

Generar regresión (modelo lineal)

# Convertir variables categóricas a factor
cate <- c("Gender", "ClaimantType", "InjuryNature", "BodyPartRegion", "BodyPart")
df[cate] <- lapply(df[cate], as.factor)
# Crear modelo con variables convertidas
reg <- lm(TotalIncurredCost ~ IsDenied + Gender + ClaimantType + InjuryNature + BodyPartRegion + BodyPart + Transaction_Time + Procesing_Time + ClaimantAge_at_DOI +AverageWeeklyWage1, data=df)
summary(reg)
## 
## Call:
## lm(formula = TotalIncurredCost ~ IsDenied + Gender + ClaimantType + 
##     InjuryNature + BodyPartRegion + BodyPart + Transaction_Time + 
##     Procesing_Time + ClaimantAge_at_DOI + AverageWeeklyWage1, 
##     data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -218634   -4921    -124    2933 1359517 
## 
## Coefficients: (6 not defined because of singularities)
##                                                                           Estimate
## (Intercept)                                                             -8.297e+03
## IsDenied                                                                -7.719e+03
## GenderMale                                                               3.464e+02
## GenderNot Available                                                      1.910e+04
## ClaimantTypeMedical Only                                                -2.145e+04
## ClaimantTypeReport Only                                                 -2.034e+04
## InjuryNatureAll Other Specific Injuries, Noc                             1.247e+04
## InjuryNatureAmputation                                                   2.060e+04
## InjuryNatureAngina Pectoris                                             -4.732e+03
## InjuryNatureAsbestosis                                                   1.893e+04
## InjuryNatureAsphyxiation                                                 1.144e+04
## InjuryNatureBlack Lung                                                   1.452e+04
## InjuryNatureBurn                                                         1.907e+04
## InjuryNatureCancer                                                       4.086e+04
## InjuryNatureCarpal Tunnel Syndrome                                       1.087e+04
## InjuryNatureConcussion                                                   2.125e+04
## InjuryNatureContagious Disease                                           1.097e+04
## InjuryNatureContusion                                                    1.459e+04
## InjuryNatureCrushing                                                     2.006e+04
## InjuryNatureDermatitis                                                   1.495e+04
## InjuryNatureDislocation                                                  1.439e+04
## InjuryNatureDust Disease, NOC                                            1.660e+04
## InjuryNatureElectric Shock                                               1.222e+04
## InjuryNatureForeign Body                                                 1.327e+04
## InjuryNatureFracture                                                     1.770e+04
## InjuryNatureFreezing                                                     1.055e+04
## InjuryNatureHearing Loss Or Impairment                                   5.991e+03
## InjuryNatureHeat Prostration                                             1.337e+04
## InjuryNatureHernia                                                       1.025e+04
## InjuryNatureInfection                                                    1.262e+04
## InjuryNatureInflammation                                                 1.614e+04
## InjuryNatureLaceration                                                   1.538e+04
## InjuryNatureLoss of Hearing                                              1.026e+04
## InjuryNatureMental Disorder                                              4.663e+03
## InjuryNatureMental Stress                                                9.083e+03
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  2.436e+04
## InjuryNatureMultiple Physical Injuries Only                              1.603e+04
## InjuryNatureMyocardial Infarction                                        1.784e+04
## InjuryNatureNo Physical Injury                                           1.397e+04
## InjuryNatureNon-Standard Code                                            1.260e+04
## InjuryNatureNot Available                                                2.020e+04
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       1.168e+04
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              1.499e+04
## InjuryNaturePuncture                                                     1.554e+04
## InjuryNatureRadiation                                                    1.634e+04
## InjuryNatureRespiratory Disorders                                        1.504e+04
## InjuryNatureRupture                                                      1.978e+04
## InjuryNatureSeverance                                                    4.431e+04
## InjuryNatureSprain                                                       1.603e+04
## InjuryNatureStrain                                                       1.420e+04
## InjuryNatureSyncope                                                      1.878e+04
## InjuryNatureVascular                                                    -5.688e+03
## InjuryNatureVDT-Related Disease                                         -6.460e+03
## InjuryNatureVision Loss                                                  1.726e+04
## BodyPartRegionLower Extremities                                          5.941e+03
## BodyPartRegionMultiple Body Parts                                        1.366e+05
## BodyPartRegionNeck                                                       7.045e+04
## BodyPartRegionNon-Standard Code                                         -7.611e+03
## BodyPartRegionTrunk                                                      3.842e+03
## BodyPartRegionUpper Extremities                                          4.280e+03
## BodyPartAnkle                                                           -2.347e+03
## BodyPartArtificial Appliance                                            -1.340e+05
## BodyPartBody Systems and Multiple Body Systems                          -1.328e+05
## BodyPartBrain                                                            7.677e+04
## BodyPartButtocks                                                         1.310e+03
## BodyPartChest                                                            1.935e+03
## BodyPartDisc-Trunk                                                       7.338e+03
## BodyPartEar(S)                                                           4.185e+03
## BodyPartElbow                                                            1.559e+03
## BodyPartEyes                                                             5.604e+03
## BodyPartFacial Bones                                                     4.260e+03
## BodyPartFinger(S)                                                       -1.706e+03
## BodyPartFoot                                                            -2.774e+03
## BodyPartGreat Toe                                                       -2.750e+03
## BodyPartHand                                                            -5.760e+02
## BodyPartHeart                                                            9.103e+03
## BodyPartHip                                                              1.086e+03
## BodyPartInsufficient Info to Properly Identify?Unclassified             -1.318e+05
## BodyPartInternal Organs                                                 -7.432e+03
## BodyPartKnee                                                             7.782e+02
## BodyPartLarynx                                                          -8.151e+04
## BodyPartLower Arm                                                        4.965e+02
## BodyPartLower Back Area                                                  3.649e+03
## BodyPartLower Leg                                                       -1.822e+03
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              4.508e+03
## BodyPartLungs                                                            1.540e+03
## BodyPartMouth                                                            4.116e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)     -1.301e+05
## BodyPartMultiple Head Injury                                             6.054e+03
## BodyPartMultiple Lower Extremities                                       3.767e+03
## BodyPartMultiple Neck Injury                                            -6.422e+04
## BodyPartMultiple Trunk                                                  -2.386e+03
## BodyPartMultiple Upper Extremities                                       7.155e+01
## BodyPartNo Physical Injury                                              -1.319e+05
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                             4.563e+03
## BodyPartPelvis                                                           4.726e+03
## BodyPartSacrum And Coccyx                                               -1.220e+03
## BodyPartShoulder(S)                                                      3.910e+03
## BodyPartSkull                                                            3.982e+03
## BodyPartSoft Tissue-Head                                                -4.966e+03
## BodyPartSoft Tissue-Neck                                                -6.540e+04
## BodyPartSpinal Cord-Trunk                                                6.031e+03
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                           -7.054e+02
## BodyPartToes                                                            -2.594e+03
## BodyPartTrachea                                                         -7.360e+04
## BodyPartUpper Arm                                                       -5.681e+02
## BodyPartUpper Back Area                                                  1.986e+03
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## Transaction_Time                                                         3.790e+00
## Procesing_Time                                                           2.684e+01
## ClaimantAge_at_DOI                                                       7.796e+01
## AverageWeeklyWage1                                                       4.747e+00
##                                                                         Std. Error
## (Intercept)                                                              2.535e+04
## IsDenied                                                                 7.199e+02
## GenderMale                                                               2.937e+02
## GenderNot Available                                                      2.818e+03
## ClaimantTypeMedical Only                                                 3.762e+02
## ClaimantTypeReport Only                                                  8.225e+02
## InjuryNatureAll Other Specific Injuries, Noc                             2.522e+04
## InjuryNatureAmputation                                                   2.694e+04
## InjuryNatureAngina Pectoris                                              3.133e+04
## InjuryNatureAsbestosis                                                   2.576e+04
## InjuryNatureAsphyxiation                                                 3.567e+04
## InjuryNatureBlack Lung                                                   3.567e+04
## InjuryNatureBurn                                                         2.524e+04
## InjuryNatureCancer                                                       2.818e+04
## InjuryNatureCarpal Tunnel Syndrome                                       2.527e+04
## InjuryNatureConcussion                                                   2.534e+04
## InjuryNatureContagious Disease                                           2.537e+04
## InjuryNatureContusion                                                    2.521e+04
## InjuryNatureCrushing                                                     2.530e+04
## InjuryNatureDermatitis                                                   2.523e+04
## InjuryNatureDislocation                                                  2.529e+04
## InjuryNatureDust Disease, NOC                                            2.917e+04
## InjuryNatureElectric Shock                                               2.554e+04
## InjuryNatureForeign Body                                                 2.523e+04
## InjuryNatureFracture                                                     2.522e+04
## InjuryNatureFreezing                                                     2.909e+04
## InjuryNatureHearing Loss Or Impairment                                   2.600e+04
## InjuryNatureHeat Prostration                                             2.547e+04
## InjuryNatureHernia                                                       2.543e+04
## InjuryNatureInfection                                                    2.533e+04
## InjuryNatureInflammation                                                 2.525e+04
## InjuryNatureLaceration                                                   2.521e+04
## InjuryNatureLoss of Hearing                                              2.613e+04
## InjuryNatureMental Disorder                                              2.774e+04
## InjuryNatureMental Stress                                                2.543e+04
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  2.603e+04
## InjuryNatureMultiple Physical Injuries Only                              2.523e+04
## InjuryNatureMyocardial Infarction                                        2.725e+04
## InjuryNatureNo Physical Injury                                           2.519e+04
## InjuryNatureNon-Standard Code                                            2.541e+04
## InjuryNatureNot Available                                                3.561e+04
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       2.541e+04
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              2.597e+04
## InjuryNaturePuncture                                                     2.522e+04
## InjuryNatureRadiation                                                    2.609e+04
## InjuryNatureRespiratory Disorders                                        2.527e+04
## InjuryNatureRupture                                                      2.556e+04
## InjuryNatureSeverance                                                    2.624e+04
## InjuryNatureSprain                                                       2.521e+04
## InjuryNatureStrain                                                       2.521e+04
## InjuryNatureSyncope                                                      2.545e+04
## InjuryNatureVascular                                                     3.560e+04
## InjuryNatureVDT-Related Disease                                          3.561e+04
## InjuryNatureVision Loss                                                  2.624e+04
## BodyPartRegionLower Extremities                                          3.099e+03
## BodyPartRegionMultiple Body Parts                                        1.476e+04
## BodyPartRegionNeck                                                       1.286e+04
## BodyPartRegionNon-Standard Code                                          4.346e+03
## BodyPartRegionTrunk                                                      3.057e+03
## BodyPartRegionUpper Extremities                                          2.752e+03
## BodyPartAnkle                                                            1.770e+03
## BodyPartArtificial Appliance                                             1.837e+04
## BodyPartBody Systems and Multiple Body Systems                           1.471e+04
## BodyPartBrain                                                            1.536e+04
## BodyPartButtocks                                                         2.965e+03
## BodyPartChest                                                            1.861e+03
## BodyPartDisc-Trunk                                                       2.326e+03
## BodyPartEar(S)                                                           3.859e+03
## BodyPartElbow                                                            1.336e+03
## BodyPartEyes                                                             2.810e+03
## BodyPartFacial Bones                                                     3.104e+03
## BodyPartFinger(S)                                                        9.262e+02
## BodyPartFoot                                                             1.802e+03
## BodyPartGreat Toe                                                        3.405e+03
## BodyPartHand                                                             9.348e+02
## BodyPartHeart                                                            1.110e+04
## BodyPartHip                                                              2.142e+03
## BodyPartInsufficient Info to Properly Identify?Unclassified              1.460e+04
## BodyPartInternal Organs                                                  4.093e+03
## BodyPartKnee                                                             1.665e+03
## BodyPartLarynx                                                           2.811e+04
## BodyPartLower Arm                                                        1.174e+03
## BodyPartLower Back Area                                                  1.571e+03
## BodyPartLower Leg                                                        1.861e+03
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              1.881e+03
## BodyPartLungs                                                            2.868e+03
## BodyPartMouth                                                            3.320e+03
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      1.452e+04
## BodyPartMultiple Head Injury                                             2.782e+03
## BodyPartMultiple Lower Extremities                                       2.073e+03
## BodyPartMultiple Neck Injury                                             1.263e+04
## BodyPartMultiple Trunk                                                   3.752e+03
## BodyPartMultiple Upper Extremities                                       1.351e+03
## BodyPartNo Physical Injury                                               1.465e+04
## BodyPartNon-Standard Code                                                       NA
## BodyPartNose                                                             3.333e+03
## BodyPartPelvis                                                           3.582e+03
## BodyPartSacrum And Coccyx                                                5.156e+03
## BodyPartShoulder(S)                                                      9.792e+02
## BodyPartSkull                                                            5.215e+03
## BodyPartSoft Tissue-Head                                                 2.537e+04
## BodyPartSoft Tissue-Neck                                                 1.269e+04
## BodyPartSpinal Cord-Trunk                                                4.695e+03
## BodyPartTeeth                                                                   NA
## BodyPartThumb                                                            1.198e+03
## BodyPartToes                                                             2.460e+03
## BodyPartTrachea                                                          1.584e+04
## BodyPartUpper Arm                                                        1.418e+03
## BodyPartUpper Back Area                                                  2.188e+03
## BodyPartUpper Leg                                                               NA
## BodyPartVertebrae                                                               NA
## BodyPartWhole Body                                                              NA
## BodyPartWrist                                                                   NA
## Transaction_Time                                                         1.631e-01
## Procesing_Time                                                           7.794e-01
## ClaimantAge_at_DOI                                                       1.284e+01
## AverageWeeklyWage1                                                       6.648e-01
##                                                                         t value
## (Intercept)                                                              -0.327
## IsDenied                                                                -10.723
## GenderMale                                                                1.179
## GenderNot Available                                                       6.779
## ClaimantTypeMedical Only                                                -57.011
## ClaimantTypeReport Only                                                 -24.731
## InjuryNatureAll Other Specific Injuries, Noc                              0.495
## InjuryNatureAmputation                                                    0.765
## InjuryNatureAngina Pectoris                                              -0.151
## InjuryNatureAsbestosis                                                    0.735
## InjuryNatureAsphyxiation                                                  0.321
## InjuryNatureBlack Lung                                                    0.407
## InjuryNatureBurn                                                          0.755
## InjuryNatureCancer                                                        1.450
## InjuryNatureCarpal Tunnel Syndrome                                        0.430
## InjuryNatureConcussion                                                    0.839
## InjuryNatureContagious Disease                                            0.432
## InjuryNatureContusion                                                     0.579
## InjuryNatureCrushing                                                      0.793
## InjuryNatureDermatitis                                                    0.593
## InjuryNatureDislocation                                                   0.569
## InjuryNatureDust Disease, NOC                                             0.569
## InjuryNatureElectric Shock                                                0.478
## InjuryNatureForeign Body                                                  0.526
## InjuryNatureFracture                                                      0.702
## InjuryNatureFreezing                                                      0.363
## InjuryNatureHearing Loss Or Impairment                                    0.230
## InjuryNatureHeat Prostration                                              0.525
## InjuryNatureHernia                                                        0.403
## InjuryNatureInfection                                                     0.498
## InjuryNatureInflammation                                                  0.639
## InjuryNatureLaceration                                                    0.610
## InjuryNatureLoss of Hearing                                               0.393
## InjuryNatureMental Disorder                                               0.168
## InjuryNatureMental Stress                                                 0.357
## InjuryNatureMultiple Injuries Including Both Physical and Psychological   0.936
## InjuryNatureMultiple Physical Injuries Only                               0.635
## InjuryNatureMyocardial Infarction                                         0.655
## InjuryNatureNo Physical Injury                                            0.555
## InjuryNatureNon-Standard Code                                             0.496
## InjuryNatureNot Available                                                 0.567
## InjuryNaturePoisoning?Chemical (Other Than Metals)                        0.460
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)               0.577
## InjuryNaturePuncture                                                      0.616
## InjuryNatureRadiation                                                     0.626
## InjuryNatureRespiratory Disorders                                         0.595
## InjuryNatureRupture                                                       0.774
## InjuryNatureSeverance                                                     1.688
## InjuryNatureSprain                                                        0.636
## InjuryNatureStrain                                                        0.563
## InjuryNatureSyncope                                                       0.738
## InjuryNatureVascular                                                     -0.160
## InjuryNatureVDT-Related Disease                                          -0.181
## InjuryNatureVision Loss                                                   0.658
## BodyPartRegionLower Extremities                                           1.917
## BodyPartRegionMultiple Body Parts                                         9.259
## BodyPartRegionNeck                                                        5.479
## BodyPartRegionNon-Standard Code                                          -1.751
## BodyPartRegionTrunk                                                       1.257
## BodyPartRegionUpper Extremities                                           1.555
## BodyPartAnkle                                                            -1.326
## BodyPartArtificial Appliance                                             -7.298
## BodyPartBody Systems and Multiple Body Systems                           -9.029
## BodyPartBrain                                                             4.999
## BodyPartButtocks                                                          0.442
## BodyPartChest                                                             1.040
## BodyPartDisc-Trunk                                                        3.155
## BodyPartEar(S)                                                            1.085
## BodyPartElbow                                                             1.166
## BodyPartEyes                                                              1.995
## BodyPartFacial Bones                                                      1.372
## BodyPartFinger(S)                                                        -1.842
## BodyPartFoot                                                             -1.540
## BodyPartGreat Toe                                                        -0.808
## BodyPartHand                                                             -0.616
## BodyPartHeart                                                             0.820
## BodyPartHip                                                               0.507
## BodyPartInsufficient Info to Properly Identify?Unclassified              -9.024
## BodyPartInternal Organs                                                  -1.816
## BodyPartKnee                                                              0.468
## BodyPartLarynx                                                           -2.900
## BodyPartLower Arm                                                         0.423
## BodyPartLower Back Area                                                   2.323
## BodyPartLower Leg                                                        -0.979
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)               2.397
## BodyPartLungs                                                             0.537
## BodyPartMouth                                                             1.240
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      -8.962
## BodyPartMultiple Head Injury                                              2.176
## BodyPartMultiple Lower Extremities                                        1.818
## BodyPartMultiple Neck Injury                                             -5.084
## BodyPartMultiple Trunk                                                   -0.636
## BodyPartMultiple Upper Extremities                                        0.053
## BodyPartNo Physical Injury                                               -9.008
## BodyPartNon-Standard Code                                                    NA
## BodyPartNose                                                              1.369
## BodyPartPelvis                                                            1.319
## BodyPartSacrum And Coccyx                                                -0.237
## BodyPartShoulder(S)                                                       3.993
## BodyPartSkull                                                             0.764
## BodyPartSoft Tissue-Head                                                 -0.196
## BodyPartSoft Tissue-Neck                                                 -5.154
## BodyPartSpinal Cord-Trunk                                                 1.285
## BodyPartTeeth                                                                NA
## BodyPartThumb                                                            -0.589
## BodyPartToes                                                             -1.054
## BodyPartTrachea                                                          -4.647
## BodyPartUpper Arm                                                        -0.400
## BodyPartUpper Back Area                                                   0.908
## BodyPartUpper Leg                                                            NA
## BodyPartVertebrae                                                            NA
## BodyPartWhole Body                                                           NA
## BodyPartWrist                                                                NA
## Transaction_Time                                                         23.241
## Procesing_Time                                                           34.437
## ClaimantAge_at_DOI                                                        6.069
## AverageWeeklyWage1                                                        7.142
##                                                                         Pr(>|t|)
## (Intercept)                                                              0.74347
## IsDenied                                                                 < 2e-16
## GenderMale                                                               0.23833
## GenderNot Available                                                     1.23e-11
## ClaimantTypeMedical Only                                                 < 2e-16
## ClaimantTypeReport Only                                                  < 2e-16
## InjuryNatureAll Other Specific Injuries, Noc                             0.62092
## InjuryNatureAmputation                                                   0.44447
## InjuryNatureAngina Pectoris                                              0.87995
## InjuryNatureAsbestosis                                                   0.46247
## InjuryNatureAsphyxiation                                                 0.74850
## InjuryNatureBlack Lung                                                   0.68385
## InjuryNatureBurn                                                         0.45004
## InjuryNatureCancer                                                       0.14709
## InjuryNatureCarpal Tunnel Syndrome                                       0.66718
## InjuryNatureConcussion                                                   0.40163
## InjuryNatureContagious Disease                                           0.66544
## InjuryNatureContusion                                                    0.56277
## InjuryNatureCrushing                                                     0.42772
## InjuryNatureDermatitis                                                   0.55351
## InjuryNatureDislocation                                                  0.56926
## InjuryNatureDust Disease, NOC                                            0.56929
## InjuryNatureElectric Shock                                               0.63246
## InjuryNatureForeign Body                                                 0.59882
## InjuryNatureFracture                                                     0.48279
## InjuryNatureFreezing                                                     0.71675
## InjuryNatureHearing Loss Or Impairment                                   0.81779
## InjuryNatureHeat Prostration                                             0.59969
## InjuryNatureHernia                                                       0.68692
## InjuryNatureInfection                                                    0.61831
## InjuryNatureInflammation                                                 0.52261
## InjuryNatureLaceration                                                   0.54194
## InjuryNatureLoss of Hearing                                              0.69462
## InjuryNatureMental Disorder                                              0.86649
## InjuryNatureMental Stress                                                0.72095
## InjuryNatureMultiple Injuries Including Both Physical and Psychological  0.34935
## InjuryNatureMultiple Physical Injuries Only                              0.52521
## InjuryNatureMyocardial Infarction                                        0.51254
## InjuryNatureNo Physical Injury                                           0.57920
## InjuryNatureNon-Standard Code                                            0.62017
## InjuryNatureNot Available                                                0.57045
## InjuryNaturePoisoning?Chemical (Other Than Metals)                       0.64576
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)              0.56380
## InjuryNaturePuncture                                                     0.53781
## InjuryNatureRadiation                                                    0.53122
## InjuryNatureRespiratory Disorders                                        0.55171
## InjuryNatureRupture                                                      0.43919
## InjuryNatureSeverance                                                    0.09137
## InjuryNatureSprain                                                       0.52498
## InjuryNatureStrain                                                       0.57338
## InjuryNatureSyncope                                                      0.46060
## InjuryNatureVascular                                                     0.87306
## InjuryNatureVDT-Related Disease                                          0.85607
## InjuryNatureVision Loss                                                  0.51072
## BodyPartRegionLower Extremities                                          0.05521
## BodyPartRegionMultiple Body Parts                                        < 2e-16
## BodyPartRegionNeck                                                      4.32e-08
## BodyPartRegionNon-Standard Code                                          0.07990
## BodyPartRegionTrunk                                                      0.20881
## BodyPartRegionUpper Extremities                                          0.11998
## BodyPartAnkle                                                            0.18479
## BodyPartArtificial Appliance                                            2.98e-13
## BodyPartBody Systems and Multiple Body Systems                           < 2e-16
## BodyPartBrain                                                           5.80e-07
## BodyPartButtocks                                                         0.65857
## BodyPartChest                                                            0.29850
## BodyPartDisc-Trunk                                                       0.00161
## BodyPartEar(S)                                                           0.27810
## BodyPartElbow                                                            0.24351
## BodyPartEyes                                                             0.04608
## BodyPartFacial Bones                                                     0.17005
## BodyPartFinger(S)                                                        0.06546
## BodyPartFoot                                                             0.12365
## BodyPartGreat Toe                                                        0.41920
## BodyPartHand                                                             0.53779
## BodyPartHeart                                                            0.41210
## BodyPartHip                                                              0.61203
## BodyPartInsufficient Info to Properly Identify?Unclassified              < 2e-16
## BodyPartInternal Organs                                                  0.06940
## BodyPartKnee                                                             0.64014
## BodyPartLarynx                                                           0.00374
## BodyPartLower Arm                                                        0.67244
## BodyPartLower Back Area                                                  0.02020
## BodyPartLower Leg                                                        0.32750
## BodyPartLumbar and/or Sacral Vertebrae (Vertebra NOC Trunk)              0.01653
## BodyPartLungs                                                            0.59146
## BodyPartMouth                                                            0.21513
## BodyPartMultiple Body Parts (Including Body Systems and Body Parts)      < 2e-16
## BodyPartMultiple Head Injury                                             0.02956
## BodyPartMultiple Lower Extremities                                       0.06913
## BodyPartMultiple Neck Injury                                            3.72e-07
## BodyPartMultiple Trunk                                                   0.52480
## BodyPartMultiple Upper Extremities                                       0.95777
## BodyPartNo Physical Injury                                               < 2e-16
## BodyPartNon-Standard Code                                                     NA
## BodyPartNose                                                             0.17095
## BodyPartPelvis                                                           0.18702
## BodyPartSacrum And Coccyx                                                0.81288
## BodyPartShoulder(S)                                                     6.55e-05
## BodyPartSkull                                                            0.44510
## BodyPartSoft Tissue-Head                                                 0.84478
## BodyPartSoft Tissue-Neck                                                2.57e-07
## BodyPartSpinal Cord-Trunk                                                0.19893
## BodyPartTeeth                                                                 NA
## BodyPartThumb                                                            0.55583
## BodyPartToes                                                             0.29171
## BodyPartTrachea                                                         3.38e-06
## BodyPartUpper Arm                                                        0.68880
## BodyPartUpper Back Area                                                  0.36399
## BodyPartUpper Leg                                                             NA
## BodyPartVertebrae                                                             NA
## BodyPartWhole Body                                                            NA
## BodyPartWrist                                                                 NA
## Transaction_Time                                                         < 2e-16
## Procesing_Time                                                           < 2e-16
## ClaimantAge_at_DOI                                                      1.30e-09
## AverageWeeklyWage1                                                      9.43e-13
##                                                                            
## (Intercept)                                                                
## IsDenied                                                                ***
## GenderMale                                                                 
## GenderNot Available                                                     ***
## ClaimantTypeMedical Only                                                ***
## ClaimantTypeReport Only                                                 ***
## InjuryNatureAll Other Specific Injuries, Noc                               
## InjuryNatureAmputation                                                     
## InjuryNatureAngina Pectoris                                                
## InjuryNatureAsbestosis                                                     
## InjuryNatureAsphyxiation                                                   
## InjuryNatureBlack Lung                                                     
## InjuryNatureBurn                                                           
## InjuryNatureCancer                                                         
## InjuryNatureCarpal Tunnel Syndrome                                         
## InjuryNatureConcussion                                                     
## InjuryNatureContagious Disease                                             
## InjuryNatureContusion                                                      
## InjuryNatureCrushing                                                       
## InjuryNatureDermatitis                                                     
## InjuryNatureDislocation                                                    
## InjuryNatureDust Disease, NOC                                              
## InjuryNatureElectric Shock                                                 
## InjuryNatureForeign Body                                                   
## InjuryNatureFracture                                                       
## InjuryNatureFreezing                                                       
## InjuryNatureHearing Loss Or Impairment                                     
## InjuryNatureHeat Prostration                                               
## InjuryNatureHernia                                                         
## InjuryNatureInfection                                                      
## InjuryNatureInflammation                                                   
## InjuryNatureLaceration                                                     
## InjuryNatureLoss of Hearing                                                
## InjuryNatureMental Disorder                                                
## InjuryNatureMental Stress                                                  
## InjuryNatureMultiple Injuries Including Both Physical and Psychological    
## InjuryNatureMultiple Physical Injuries Only                                
## InjuryNatureMyocardial Infarction                                          
## InjuryNatureNo Physical Injury                                             
## InjuryNatureNon-Standard Code                                              
## InjuryNatureNot Available                                                  
## InjuryNaturePoisoning?Chemical (Other Than Metals)                         
## InjuryNaturePoisoning?General (NOT OD or Cumulative Injury)                
## InjuryNaturePuncture                                                       
## InjuryNatureRadiation                                                      
## InjuryNatureRespiratory Disorders                                          
## InjuryNatureRupture                                                        
## InjuryNatureSeverance                                                   .  
## InjuryNatureSprain                                                         
## InjuryNatureStrain                                                         
## InjuryNatureSyncope                                                        
## InjuryNatureVascular                                                       
## InjuryNatureVDT-Related Disease                                            
## InjuryNatureVision Loss                                                    
## 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                                                              
## Transaction_Time                                                        ***
## Procesing_Time                                                          ***
## ClaimantAge_at_DOI                                                      ***
## AverageWeeklyWage1                                                      ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25130 on 30894 degrees of freedom
##   (614 observations deleted due to missingness)
## Multiple R-squared:  0.1901, Adjusted R-squared:  0.1872 
## F-statistic: 65.91 on 110 and 30894 DF,  p-value: < 2.2e-16

Evaluar, y en caso necesario, ajustar la regresión

regr2 <- lm(TotalIncurredCost ~ IsDenied + Gender + ClaimantType + 
                          BodyPartRegion + Transaction_Time + Procesing_Time + 
                          ClaimantAge_at_DOI + AverageWeeklyWage1, 
                          data = df)
summary(regr2)
## 
## Call:
## lm(formula = TotalIncurredCost ~ IsDenied + Gender + ClaimantType + 
##     BodyPartRegion + Transaction_Time + Procesing_Time + ClaimantAge_at_DOI + 
##     AverageWeeklyWage1, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -223788   -4421      27    2735 1367299 
## 
## Coefficients:
##                                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        1.207e+04  8.993e+02  13.421  < 2e-16 ***
## IsDenied                          -8.124e+03  6.996e+02 -11.612  < 2e-16 ***
## GenderMale                         3.614e+02  2.904e+02   1.245   0.2133    
## GenderNot Available                1.989e+04  2.819e+03   7.056 1.75e-12 ***
## ClaimantTypeMedical Only          -2.210e+04  3.630e+02 -60.877  < 2e-16 ***
## ClaimantTypeReport Only           -2.087e+04  8.157e+02 -25.585  < 2e-16 ***
## BodyPartRegionLower Extremities    4.122e+02  5.496e+02   0.750   0.4532    
## BodyPartRegionMultiple Body Parts  7.791e+02  6.046e+02   1.289   0.1975    
## BodyPartRegionNeck                 7.423e+02  9.439e+02   0.786   0.4316    
## BodyPartRegionNon-Standard Code   -1.495e+04  1.224e+03 -12.212  < 2e-16 ***
## BodyPartRegionTrunk                1.367e+03  5.703e+02   2.397   0.0165 *  
## BodyPartRegionUpper Extremities   -6.385e+02  5.216e+02  -1.224   0.2210    
## Transaction_Time                   3.664e+00  1.582e-01  23.159  < 2e-16 ***
## Procesing_Time                     2.676e+01  7.757e-01  34.504  < 2e-16 ***
## ClaimantAge_at_DOI                 8.259e+01  1.282e+01   6.443 1.19e-10 ***
## AverageWeeklyWage1                 4.885e+00  6.645e-01   7.351 2.02e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25230 on 30989 degrees of freedom
##   (614 observations deleted due to missingness)
## Multiple R-squared:  0.1812, Adjusted R-squared:  0.1808 
## F-statistic: 457.3 on 15 and 30989 DF,  p-value: < 2.2e-16

Construir un modelo de predicción

df2 <- data.frame(IsDenied= 1, ClaimantType= "Indemnity", Gender= "Male", Transaction_Time= 2087, Procesing_Time= 12, ClaimantAge_at_DOI= 100, AverageWeeklyWage1= 312, BodyPartRegion="Neck")
predict(regr2,df2)
##        1 
## 22801.18

Conclusiones

El código realiza un análisis predictivo utilizando regresión lineal para estimar los costos incurridos en seguros basado en diversas características del asegurado y del proceso de reclamación. Tras ajustar el modelo eliminando variables no significativas, se obtiene un modelo más eficiente y posiblemente más preciso