Correlation Function

corfunction=function(d){
  mycorr=cor(d[, 1:ncol(d)]); p.mat=ggcorrplot::cor_pmat(d[,1:ncol(d)])
  myplot=ggcorrplot(mycorr, hc.order=TRUE,type="lower",
                    colors=c("red", "white","green"),tl.cex = 8, 
                    tl.col = "black", lab=TRUE, lab_size=2, p.mat=p.mat,
                    insig="pch", pch=4)
  print(myplot)}

Load Libraries

######################
require(Amelia)      #  
## Loading required package: Amelia
## Loading required package: Rcpp
## ## 
## ## Amelia II: Multiple Imputation
## ## (Version 1.8.1, built: 2022-11-18)
## ## Copyright (C) 2005-2023 James Honaker, Gary King and Matthew Blackwell
## ## Refer to http://gking.harvard.edu/amelia/ for more information
## ##
require(dplyr)       #
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
require(e1071)       #
## Loading required package: e1071
require(kableExtra)  #
## Loading required package: kableExtra
## Warning in !is.null(rmarkdown::metadata$output) && rmarkdown::metadata$output
## %in% : 'length(x) = 2 > 1' in coercion to 'logical(1)'
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
require(magrittr)    #
## Loading required package: magrittr
require(tidyverse)   #
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.4
## ✔ ggplot2   3.4.1     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.1     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::extract()         masks magrittr::extract()
## ✖ dplyr::filter()          masks stats::filter()
## ✖ kableExtra::group_rows() masks dplyr::group_rows()
## ✖ dplyr::lag()             masks stats::lag()
## ✖ purrr::set_names()       masks magrittr::set_names()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
require(fpp3)        #
## Loading required package: fpp3
## ── Attaching packages ────────────────────────────────────────────── fpp3 0.5 ──
## ✔ tsibble     1.1.3     ✔ fable       0.3.3
## ✔ tsibbledata 0.4.1     ✔ fabletools  0.3.2
## ✔ feasts      0.3.1     
## ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
## ✖ lubridate::date()         masks base::date()
## ✖ tidyr::extract()          masks magrittr::extract()
## ✖ dplyr::filter()           masks stats::filter()
## ✖ kableExtra::group_rows()  masks dplyr::group_rows()
## ✖ fabletools::interpolate() masks e1071::interpolate()
## ✖ tsibble::intersect()      masks base::intersect()
## ✖ tsibble::interval()       masks lubridate::interval()
## ✖ dplyr::lag()              masks stats::lag()
## ✖ purrr::set_names()        masks magrittr::set_names()
## ✖ tsibble::setdiff()        masks base::setdiff()
## ✖ tsibble::union()          masks base::union()
require(glmm)        #  
## Loading required package: glmm
## Loading required package: trust
## Loading required package: mvtnorm
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## Loading required package: parallel
## Loading required package: doParallel
## Loading required package: foreach
## 
## Attaching package: 'foreach'
## 
## The following objects are masked from 'package:purrr':
## 
##     accumulate, when
## 
## Loading required package: iterators
require(MASS)        #
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## 
## The following object is masked from 'package:dplyr':
## 
##     select
require(car)         #
## Loading required package: car
## Loading required package: carData
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:purrr':
## 
##     some
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
require(elsa)        #
## Loading required package: elsa
## Loading required package: sp
## Loading required package: raster
## 
## Attaching package: 'raster'
## 
## The following object is masked from 'package:MASS':
## 
##     select
## 
## The following object is masked from 'package:dplyr':
## 
##     select
require(fastDummies) #
## Loading required package: fastDummies
require(ggplot2)     #
require(ggcorrplot)  #
## Loading required package: ggcorrplot
require(ggExtra)     #
## Loading required package: ggExtra
require(glmmML)      #
## Loading required package: glmmML
require(grid)        #
## Loading required package: grid
require(gridExtra)   #
## Loading required package: gridExtra
## 
## Attaching package: 'gridExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     combine
require(imbalance)   #
## Loading required package: imbalance
library(leaflet)     #
library(leaflet.extras)
require(psych)       #
## Loading required package: psych
## 
## Attaching package: 'psych'
## 
## The following object is masked from 'package:raster':
## 
##     distance
## 
## The following object is masked from 'package:car':
## 
##     logit
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
require(raster)      #
require(RColorBrewer)#
## Loading required package: RColorBrewer
require(rgdal)       #
## Loading required package: rgdal
## Please note that rgdal will be retired during 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## See https://r-spatial.org/r/2022/04/12/evolution.html and https://github.com/r-spatial/evolution
## rgdal: version: 1.6-5, (SVN revision 1199)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.5.2, released 2022/09/02
## Path to GDAL shared files: C:/Users/lfult/AppData/Local/R/win-library/4.2/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821]
## Path to PROJ shared files: C:/Users/lfult/AppData/Local/R/win-library/4.2/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.6-0
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
require(rgeos)       #
## Loading required package: rgeos
## rgeos version: 0.6-2, (SVN revision 693)
##  GEOS runtime version: 3.9.3-CAPI-1.14.3 
##  Please note that rgeos will be retired during 2023,
## plan transition to sf functions using GEOS at your earliest convenience.
##  GEOS using OverlayNG
##  Linking to sp version: 1.6-0 
##  Polygon checking: TRUE 
## 
## 
## Attaching package: 'rgeos'
## 
## The following object is masked from 'package:dplyr':
## 
##     symdiff
require(shiny)       #
## Loading required package: shiny
## 
## Attaching package: 'shiny'
## 
## The following object is masked from 'package:ggExtra':
## 
##     runExample
require(sf)          #
## Loading required package: sf
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
require(sp)          #
require(spatialreg)  #
## Loading required package: spatialreg
## Loading required package: spData
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source')`
## 
## Attaching package: 'spatialreg'
## 
## The following object is masked from 'package:fabletools':
## 
##     ME
require(spData)      #
require(spdep)       #
## Loading required package: spdep
## 
## Attaching package: 'spdep'
## 
## The following objects are masked from 'package:spatialreg':
## 
##     get.ClusterOption, get.coresOption, get.mcOption,
##     get.VerboseOption, get.ZeroPolicyOption, set.ClusterOption,
##     set.coresOption, set.mcOption, set.VerboseOption,
##     set.ZeroPolicyOption
## 
## The following objects are masked from 'package:elsa':
## 
##     geary, moran
require(tmap)        #
## Loading required package: tmap
require(tmaptools)   #
## Loading required package: tmaptools
require(spdep)       #
require(tidyverse)   #
require(leaps)       #
## Loading required package: leaps
require(caret)       #
## Loading required package: caret
## Loading required package: lattice
## 
## Attaching package: 'caret'
## 
## The following objects are masked from 'package:fabletools':
## 
##     MAE, RMSE
## 
## The following object is masked from 'package:purrr':
## 
##     lift
require(glmnet)      #
## Loading required package: glmnet
## Loaded glmnet 4.1-7
require(lmSupport)   #
## Loading required package: lmSupport
require(lars)        #
## Loading required package: lars
## Loaded lars 1.3
## 
## 
## Attaching package: 'lars'
## 
## The following object is masked from 'package:psych':
## 
##     error.bars
require(glmpath)     #
## Loading required package: glmpath
## Loading required package: survival
## 
## Attaching package: 'survival'
## 
## The following object is masked from 'package:caret':
## 
##     cluster
require(covTest)     #
## Loading required package: covTest
gc()
##           used  (Mb) gc trigger  (Mb) max used  (Mb)
## Ncells 5723441 305.7    8964568 478.8  8231709 439.7
## Vcells 7973149  60.9   12255594  93.6 10146269  77.5

Set Directory / Load Data / EDA

setwd('C:/Users/lfult/Documents/Bankruptcy Study/')
bankrupt=read.csv('bankrupt4cleaningwithFIPS.csv', stringsAsFactors = T)
bankrupt$ForProfit=as.numeric(bankrupt$ForProfit)-1
bankrupt$Govt=as.numeric(bankrupt$Govt)-1
bankrupt$Urban_No=as.numeric(bankrupt$Urban_No)-1
bankrupt$Name=NULL
bankrupt$County=NULL
missmap(bankrupt, x.cex=.5)

Missing by Column

myc = function(x){
  co=rep(0,ncol(bankrupt))
  for (i in 1:ncol(x)){co[i]=sum(is.na(x[1:nrow(x), i]))}
  names(co)=colnames(bankrupt)
  co=sort(co, decreasing=T)/nrow(bankrupt)
  print(length(co[co>.2]))
  tmp=co[1:13]
  barplot(tmp, las=2, cex.names=.5, space=0)
  print(names(tmp))
  return(co)
}

myc(bankrupt)
## [1] 0

##  [1] "MedicarePerPatient"      "DSHPaymentMedicare"     
##  [3] "TPS"                     "MedicareAllowDSHPercent"
##  [5] "HospCompare"             "HCAHPSStar"             
##  [7] "MCI"                     "Debt2Equity"            
##  [9] "CharityCareCost"         "MedicaidDays"           
## [11] "MedicareDays"            "OtherDays"              
## [13] "SeriousComplRate"
##      MedicarePerPatient      DSHPaymentMedicare                     TPS 
##            1.992234e-01            1.580887e-01            1.553903e-01 
## MedicareAllowDSHPercent             HospCompare              HCAHPSStar 
##            1.517046e-01            1.176780e-01            1.070817e-01 
##                     MCI             Debt2Equity         CharityCareCost 
##            7.855074e-02            7.177175e-02            5.788469e-02 
##            MedicaidDays            MedicareDays               OtherDays 
##            5.676583e-02            5.150059e-02            5.150059e-02 
##        SeriousComplRate          NetMedicaidRev                 SurgCMI 
##            4.429380e-02            3.586942e-02            3.234830e-02 
##          LaborCompRatio          BadDebtARRatio         BadDebtNPRRatio 
##            3.215085e-02            2.734632e-02            2.010662e-02 
##                 BadDebt                  MedCMI              CashOnHand 
##            1.954719e-02            1.382125e-02            1.260366e-02 
##           TotalFreeCare    DaysSalesOutstanding      AccountsReceivable 
##            9.247071e-03            8.490193e-03            7.930762e-03 
##             CC_MCC_Rate                     CMI            TotalRevenue 
##            5.561406e-03            5.462683e-03            4.936159e-03 
##             OtherIncome           OutpatientRev     PctPatientDiscounts 
##            4.804528e-03            4.113466e-03            2.171910e-03 
##          AvgDailyCensus                    ALOS              Discharges 
##            1.085955e-03            7.897854e-04            7.568777e-04 
##            InpatientRev            IncomeMargin              NetPxRatio 
##            7.239700e-04            6.581545e-04            5.594314e-04 
##       NetOpProfitMargin                  EBITDA        LiabFundBalRatio 
##            5.594314e-04            5.594314e-04            4.936159e-04 
##          NetMedicareRev              QuickRatio             StaffedBeds 
##            4.607082e-04            3.619850e-04            3.619850e-04 
##           CurrentAssets               NetIncome                  NewIDX 
##            1.645386e-04            9.872318e-05            0.000000e+00 
##                     IDX                Hospital                   State 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##                   GEOID        Years_2_Bankrupt                Bankrupt 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##                    Year                 CurLiab               TotalLiab 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##      TotLiabFundBalance             FundBalance             EquityProxy 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##                 BedUtil               AdjPxDays            CurrentRatio 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##                Overhead              Loss2Years              OpExpenses 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##                OpIncome                NetDelta          DaysCashOnHand 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##             TotalAssets               ForProfit                    Govt 
##            0.000000e+00            0.000000e+00            0.000000e+00 
##                Urban_No 
##            0.000000e+00

Missing by Row

myr = function (x){
  temp=rep(0,nrow(x))
  for (i in 1:nrow(x)){
    temp[i]=
    sum(is.na(x[i, 1:ncol(x)]))/ncol(x)}
  x$ROWMISS=temp
  x=x[order(-x$ROWMISS), ]
  return(x)
}

bankrupt=myr(bankrupt)
tmp=bankrupt$ROWMISS[1:50]
names(tmp)=bankrupt$HOSPITAL_NAME[1:50]
barplot(tmp, cex.names=.4, las=2)

Deleted Unreliable Observations

Villa Feliciano: 4 observations, 50 to 55% missing, Not bankrupt Florida State Hospital: 10 observations, 41 to 45% missing, Not bankrupt San Juan City Hospital: 10 observations, 28 to 41% missing, Not bankrupt Patients Choice Medical Center of Smith County in 2012: Average 25% missing (all 10 observations), Not bankrupt Texas Center for Infectious Disease (FKA San Antonio State Chest Hospital). 9 observations, 27 to 34% missing, Not Bankrupt Monroe Community Hospital. 8 observations, 21 to 35% missing, not bankrupt The University of Kansas Health - Indian Creek Campus (FKA Heartland Surgical Specialty Hospital): 2observations, 24 to 35% missing, not bankrupt University District Hospital (Puerto Rico): 6 observations, 27 to 33% missing, not bankrupt Kaiser Permanente Central Hospital Capitol Hill Campus: 6 observations (early), average 20% missing (max 32%), not bankrupt Porterville Developmental Center: 10 observations, average 28% missing, not bankrupt Hospital Universitario Dr Ruiz Arnau: 10 observations, average 27% missing, not bankrupt Walter B Jones Lakeside Psychiatric Hospital, 4 observations, 26 to 28 % missing, not bankrupt The Specialty Hospital at ArchCare at Terence Cardinal Cooke Health Care Center (AKA ArchCare), 10 observations, 24 to 27% missing, not bankrupt Apire Hospital (FKA Aspire Behavioral Health of Conroe), 10 observations average 22% missing, not bankrupt Phillips Eye Institute - a campus of Abbott Northwestern Hospital (Closed), 8 observations (last 2019), 21% missing max but closure status / year not indicated (data entry error) DOCS Surgical Hospital (Opening - Mid 2023), 2 observations yet not open Southeast Regional Medical Center, 2 obs, 27% missing, not bankrupt Hiram W Davis Medical Center, 10 obs, 21.4% mean missing, not bankrupt MISH Hospital and Clinics (AKA Institute for Advanced Bariatric Surgery), 10 obs, 22% mean missing, not bankrupt Hospital General Castaner, 6 obs, 22% mean missing, not bankrupt Harmon Hospital, 3 obs, 25% mean missing, not bankrupt The Woodlands Specialty Hospital, 2 obs, 21% missing, not bankrupt Spring Hospital (FKA Spring Central Hospital), 1 obs, 26% missing, not bankrupt Altus Baytown Hospital, 5 obs, 22.3% missing, not bankrupt THOP Horizon City Campus, 3 obs, 22.2% missing, not bankrupt SE Texas ER & Hospital, 1 obs, 24% missing, not bankrupt Mayhill Hospital, 10 obs, 21% missing, not bankrupt Comprehensive Cancer Center of UPR, 1 obs, 23% missing, not bankrupt Eastern State Hospital, 4 obs, max 23% missing, but years 12-14 and 16. Nothing afterwards, not bankrupt Altus Houston Hospital, 2 obs, 23.1% missing, not bankrupt Kingwood Emergency Hospital (AKA Facilities Management Group). 1 obs, 23.1% missing, not bankrupt. Altus Lumberton Hospital, 2 obs, 21% missing, not bankrupt Methodist Midlothian Medical Center, 1 obs, 21% missing, not bankrupt Comprehensive Cancer Center of UPR, 1 obs, 23% missing, not bankrupt Altus Houston Hospital, 2 obs, 23% missing, not bankrupt Kingwood Emergency Hospital (AKA Facilities Management Group), 1 year, 23% missing, not bankrupt Other 1, 2, 3, 4, 5, 6, or 7 year only non-bankrupt eliminated Arkansas Heart Hospital Encore Medical Center Banner Ocotillo Medical Center Ascension Seton Bastrop AHN Hempfield Neighborhood Hospital Baylor Scott & White Medical Center - Buda Geisinger St Lukes Hospital Grand Island Regional Medical Center Froedtert Community Hospital - New Berlin (AKA Moorland Reserve Health Center) Grove Creek Medical Center HonorHealth Sonoran Crossing Medical Center Intermountain Spanish Fork Hospital LBJ Tropical Medical Center Idaho Falls Community Hospital Methodist Midlothian Medical Center Northside Hospital Duluth (FKA Gwinnett Medical Center - Duluth) Northwest Medical Center Sahuarita Ochsner LSU Health Shreveport - St Mary Medical Center St Charles Redmond Texas Health Frisco Texas Health Mansfield Townsen Memorial Hospital Arroyo Grande Community Hospital Acadian Medical Center Avail Health Lake Charles Hospital Altus Lumberton Hospital Baton Rouge General Medical Center - Mid City Campus Baylor Scott & White Medical Center - Austin Dignity Health Arizona General Hospital - Mesa Halifax Health UF Health Medical Center of Deltona Hospital Los Angeles Community Hospital at Bellflower (FKA Bellflower Medical Center) Layton Hospital LincolnHealth - Miles Campus and Hospital (FKA Miles Memorial Hospital) INTEGRIS Community Hospital - Council Crossing Marshfield Medical Center - Minocqua Methodist Southlake Medical Center (FKA Methodist Southlake Hospital) NewYork-Presbyterian Lower Manhattan Hospital (AKA New York Downtown Hospital) Northeast Georgia Medical Center Lumpkin Novant Health Mint Hill Medical Center Rock Regional Hospital Presbyterian Santa Fe Medical Center Roper St Francis Healthcare - Berkeley Hospital St Charles Bend UCHealth Greeley Hospital Thomasville Regional Medical Center UCHealth Highlands Ranch Hospital Arkansas Continued Care Hospital of Jonesboro Baylor Scott & White Medical Center - Pflugerville (AKA Pflugerville Medical Center) Baptist Memorial Hospital Crittenden Dignity Health St Rose Dominican - North Las Vegas Campus East Alabama Medical Center - Lanier First Surgical Hospital Kettering Health Troy (FKA Troy Hospital) Marshfield Medical Center - Eau Claire UCHealth Longs Peak Hospital UCHealth Grandview Hospital UCHealth Broomfield Hospital University Hospitals Beachwood Medical Center (FKA Beachwood Medical Center) Wills Eye Hospital Advanced Diagnostics Hospital East (FKA Victory Surgical Hospital East Houston) Carson Tahoe Sierra Surgery Hospital Baylor Scott & White Emergency Hospital - Rockwall Eastern State Hospital Fresno Heart & Surgical Hospital Ontario Hospital Northwest Surgical Hospital (FKA Northwest Texas Surgery Center) MultiCare Covington Medical Center NYU Langone Hospital - Brooklyn (FKA NYU Lutheran Medical Center) PeaceHealth Sacred Heart Medical Center at RiverBend (FKA Sacred Heart Riverbend) PeaceHealth Sacred Heart Medical Center University District (FKA Sacred Heart University Dist) St Lukes Nampa Medical Center St Vincents Chilton THOP Transmountain Campus Trinity Health Muskegon (AKA Mercy Health Muskegon - Mercy Campus) St Lukes Monroe Campus Summa Health System - Barberton Campus Unity Health - Newport (FKA Unity Health - Harris Medical Center) Valley Health Specialty Hospital (FKA Orthopedic Specialty Hospital of Nevada) Baptist Health - Conway Ascension Sacred Heart Hospital on the Emerald Coast Avon Hospital CHI St Joseph Health College Station Hospital (FKA College Station Medical Center) Doctors Hospital Doctors Center Hospital San Fernando de la Carolina (FKA Doctors Center Hospital Carolina) Henderson Hospital Houston Methodist the Woodlands Hospital Memorial Hospital Shiloh (FKA Memorial Hospital East) Oviedo Medical Center St Charles Surgical Hospital Ascension NE Wisconsin - Mercy Campus Avera Surgical Hospital (FKA Lewis and Clark Specialty Hospital) Arizona General Hospital - Laveen Baylor Scott & White Emergency Hospital - Burleson Bradford Regional Medical Center Baylor Scott & White Medical Center - Marble Falls CHRISTUS Good Shepherd Medical Center - Longview Guam Regional Medical City Holy Cross Germantown Hospital Franciscan Health Carmel (FKA Franciscan St Francis Health - Carmel) HCA Houston Healthcare Pearland (FKA Pearland Medical Center) Loma Linda University Childrens Hospital Medical City Alliance Martin Luther King Jr Community Hospital New Orleans East Hospital Samaritan Hospital - St Marys Campus StoneSprings Hospital Center Stony Brook Southampton Hospital (FKA Southampton Hospital) WK Bossier Health Center UMass Memorial HealthAlliance Clinton Hospital - Clinton Campus Banner Fort Collins Medical Center Ascension SE Wisconsin Hospital - Franklin Campus (FKA Ascension Wheaton Franciscan Healthcare - Franklin) Bergen New Bridge Medical Center (FKA Bergen Regional Medical Center) Cape Fear Valley - Hoke Hospital El Campo Memorial Hospital Crescent Regional Hospital (FKA Crescent Medical Center Lancaster) Community Hospital Long Beach (FKA MemorialCare Community Medical Center Long Beach) HCA Florida West Tampa Hospital (FKA Tampa Community Hospital) Highland Hills Medical Center (AKA Delta Health-Highland Hills) Kearney Regional Medical Center Legent Orthopedic and Spine Hospital (FKA Cumberland Surgical Hospital) Lehigh Valley Hospital - Muhlenberg INTEGRIS Baptist Medical Center Portland Avenue (FKA INTEGRIS Deaconess) Lehigh Valley Hospital - Schuylkill E Norwegian Street (FKA Schuylkill Medical Center - E Norwegian Street) NewYork-Presbyterian Westchester (FKA NewYork-Presbyterian Lawrence Hospital) North Hospital (FKA Tennova Healthcare - Regional Jackson) NYU Langone Hospital - Long Island (FKA NYU Winthrop Hospital) OConnor Hospital PeaceHealth St Joseph Medical Center Resolute Health Hospital ProMedica Flower Hospital Samaritan Hospital - Albany Memorial Campus (FKA Albany Memorial Hospital) San Leandro Hospital St Francis P&S Surgery & Heart Center St Louise Regional Hospital Temecula Valley Hospital The University of Kansas Health System St Francis Campus (FKA St Francis Health St Francis Health Center) The Heart Hospital at Deaconess Gateway

Impute Missing

for(i in 1:ncol(bankrupt)){
  if(is.numeric(bankrupt[,i])){
    bankrupt[is.na(bankrupt[,i]), i] <- median(bankrupt[,i], na.rm = TRUE)
  }
}

Final Missing Map

missmap(bankrupt)

Proxies for Altman and Ohlson

#Owners' equity, argued by Brad...calculate changes for hospital t-(t-1) for the change in equity
bankrupt$AltmanX1=(bankrupt$CurrentAssets-bankrupt$CurLiab)/(bankrupt$TotalAssets-min(bankrupt$TotalAssets)+.01) #Altman X1 
bankrupt$AltmanX2=(bankrupt$EquityProxy)/bankrupt$TotalAssets
bankrupt$AltmanX3=bankrupt$EBITDA/bankrupt$TotalAssets
bankrupt$AltmanX4=1/(bankrupt$Debt2Equity-min(bankrupt$Debt2Equity+.01)) #location shift
bankrupt$OhlsonX1=log(bankrupt$TotalAssets-min(bankrupt$TotalAssets)+.01)/696
bankrupt$OhlsonX2=bankrupt$TotalLiab/bankrupt$TotalAssets
bankrupt$OhlsonX3=(bankrupt$CurrentAssets-bankrupt$CurLiab)/bankrupt$TotalAssets
bankrupt$OhlsonX4=(bankrupt$CurLiab/bankrupt$CurrentAssets)
bankrupt$OhlsonX5=ifelse(bankrupt$TotalLiab/bankrupt$TotalAssets>1,1,0)
bankrupt$OhlsonX6=bankrupt$NetIncome/bankrupt$TotalAssets
bankrupt$OhlsonX7=bankrupt$EBITDA/bankrupt$TotalLiab
bankrupt$OhlsonX8=bankrupt$Loss2Years
bankrupt$OhlsonX9=bankrupt$NetDelta

Save Data

bankrupt$Loss2Years=NULL
bankrupt$ROWMISS=NULL
bankrupt$Impute=NULL
write.csv(bankrupt, 'c:/users/lfult/documents/bankruptcy study/cleaned data.csv', row.names=F )

Read Data

bankrupt=read.csv('c:/users/lfult/documents/bankruptcy study/cleaned data.csv', stringsAsFactors = T)
bankrupt$Year=as.numeric(bankrupt$Year)

Describe Data

bankrupt$Hospital=as.factor(bankrupt$Hospital)
describe(bankrupt)
##                         vars     n         mean           sd       median
## NewIDX                     1 30388     15194.50 8.772400e+03     15194.50
## IDX                        2 30388     23394.19 1.353092e+04     23346.50
## Hospital*                  3 30388      1522.06 8.784500e+02      1522.00
## State                      4 30388        29.07 1.663000e+01        28.00
## GEOID                      5 30388     28830.53 1.590857e+04     27173.00
## Years_2_Bankrupt           6 30388        98.51 7.000000e+00        99.00
## Bankrupt                   7 30388         0.00 7.000000e-02         0.00
## Year                       8 30388      2016.50 2.870000e+00      2016.00
## CurLiab                    9 30388  59410166.41 2.254424e+08  22183324.50
## TotalLiab                 10 30388 160059125.70 5.129319e+08  53763348.50
## TotLiabFundBalance        11 30388 378982688.84 1.006031e+09 142778823.50
## FundBalance               12 30388 219078861.78 6.108464e+08  78183644.00
## EquityProxy               13 30388  16471680.38 2.068335e+08   1774074.50
## BedUtil                   14 30388         0.50 2.000000e-01         0.51
## AdjPxDays                 15 30388     93496.69 1.045033e+05     61478.85
## CurrentRatio              16 30388        41.17 3.757870e+03         1.84
## Debt2Equity               17 30388         0.51 1.003600e+02         0.27
## LiabFundBalRatio          18 30388     15501.95 2.702244e+06         0.52
## Overhead                  19 30388 123880639.61 1.910174e+08  66718557.00
## LaborCompRatio            20 30388         0.45 2.500000e-01         0.43
## QuickRatio                21 30388        40.61 3.728400e+03         1.69
## BadDebt                   22 30388  18015950.75 2.973117e+07   9654303.50
## BadDebtARRatio            23 30388         7.59 1.380490e+03         0.23
## BadDebtNPRRatio           24 30388         0.09 1.200000e-01         0.06
## NetPxRatio                25 30388 273861940.91 3.899837e+08 153006935.00
## NetOpProfitMargin         26 30388        -0.02 5.300000e-01         0.00
## OutpatientRev             27 30388 489554592.46 6.891405e+08 297906216.00
## InpatientRev              28 30388 541078010.08 8.573176e+08 244474372.50
## NetMedicaidRev            29 30388  37436233.93 1.016582e+08  14821635.00
## NetMedicareRev            30 30388  53926983.40 7.274938e+07  30833761.00
## TotalRevenue              31 30388 300824575.97 4.480332e+08 162131299.00
## PctPatientDiscounts       32 30388         0.69 1.400000e-01         0.70
## Discharges                33 30388      9706.74 1.047075e+04      6417.00
## StaffedBeds               34 30388       205.47 2.960800e+02       144.00
## AvgDailyCensus            35 30388       124.54 3.044200e+02        71.40
## ALOS                      36 30388         5.75 8.881000e+01         4.31
## MCI                       37 30388         0.34 3.100000e-01         0.23
## OpExpenses                38 30388 277582464.52 4.113836e+08 150237655.00
## OpIncome                  39 30388  -3806120.49 9.848047e+07   -538699.00
## OtherIncome               40 30388  27514477.42 1.001188e+08   6234315.00
## NetIncome                 41 30388  21790131.16 7.775249e+07   7343907.00
## NetDelta                  42 30388         0.02 5.200000e-01         0.00
## IncomeMargin              43 30388         0.06 2.000000e+00         0.05
## EBITDA                    44 30388  11035491.59 9.476817e+07   6500068.00
## CashOnHand                45 30388  27710106.08 1.338324e+08   2698366.00
## DaysCashOnHand            46 30388        52.00 1.367900e+02        13.53
## AccountsReceivable        47 30388  91299298.76 1.714220e+08  39711155.00
## DaysSalesOutstanding      48 30388        57.79 1.140500e+02        48.06
## CurrentAssets             49 30388 123885796.49 2.884520e+08  40951206.00
## TotalAssets               50 30388 381166575.84 1.007780e+09 143284161.00
## MedicareDays              51 30388     13167.15 1.531508e+04      8219.00
## MedicaidDays              52 30388      4652.45 8.848380e+03      1654.00
## OtherDays                 53 30388     31132.87 4.093597e+04     17435.00
## CMI                       54 30388         1.61 3.700000e-01         1.57
## MedCMI                    55 30388         1.20 1.400000e-01         1.20
## SurgCMI                   56 30388         2.80 5.400000e-01         2.75
## CC_MCC_Rate               57 30388         0.02 4.000000e-02         0.01
## CharityCareCost           58 30388   8078692.57 2.731580e+07   2819809.00
## TotalFreeCare             59 30388  19826803.36 5.061379e+07   9411325.00
## DSHPaymentMedicare        60 30388   1717652.96 3.257290e+06    752547.50
## MedicareAllowDSHPercent   61 30388         0.15 1.200000e-01         0.12
## MedicarePerPatient        62 30388     21598.82 3.063800e+03     21531.00
## TPS                       63 30388        33.36 1.043000e+01        32.25
## SeriousComplRate          64 30388         0.89 1.800000e-01         0.87
## HCAHPSStar                65 30388         3.02 8.000000e-01         3.00
## HospCompare               66 30388         3.17 1.070000e+00         3.00
## ForProfit                 67 30388         0.24 4.300000e-01         0.00
## Govt                      68 30388         0.14 3.500000e-01         0.00
## Urban_No                  69 30388         0.11 3.100000e-01         0.00
## AltmanX1                  70 30388  -4984389.09 8.688864e+08         0.01
## AltmanX2                  71 30388     -2041.65 3.177603e+05         0.02
## AltmanX3                  72 30388      -334.54 4.621523e+04         0.05
## AltmanX4                  73 30388         0.00 5.700000e-01         0.00
## OhlsonX1                  74 30388         0.03 0.000000e+00         0.03
## OhlsonX2                  75 30388       313.38 3.880470e+04         0.43
## OhlsonX3                  76 30388      -312.82 3.880469e+04         0.14
## OhlsonX4                  77 30388       313.62 3.880470e+04         0.49
## OhlsonX5                  78 30388         0.11 3.100000e-01         0.00
## OhlsonX6                  79 30388      -312.90 3.880470e+04         0.05
## OhlsonX7                  80 30388       -41.07 8.130560e+03         0.06
## OhlsonX8                  81 30388         0.42 4.900000e-01         0.00
## OhlsonX9                  82 30388         0.02 5.200000e-01         0.00
##                              trimmed          mad           min          max
## NewIDX                      15194.50     11263.31  1.000000e+00 3.038800e+04
## IDX                         23386.67     17362.73  7.000000e+00 4.713600e+04
## Hospital*                    1522.08      1128.26  1.000000e+00 3.043000e+03
## State                          28.88        20.76  1.000000e+00 7.800000e+01
## GEOID                       29043.51     21986.96  1.001000e+03 7.803000e+04
## Years_2_Bankrupt               99.00         0.00 -8.000000e+00 9.900000e+01
## Bankrupt                        0.00         0.00  0.000000e+00 1.000000e+00
## Year                         2016.50         2.97  2.012000e+03 2.021000e+03
## CurLiab                  33394977.35  25736859.63 -2.006499e+09 1.054064e+10
## TotalLiab                89100560.32  72013769.38 -2.904918e+09 1.737507e+10
## TotLiabFundBalance      211614980.40 162872342.51 -3.397588e+09 2.313856e+10
## FundBalance             122133264.43 108163509.99 -4.518236e+09 1.433098e+10
## EquityProxy               7696823.60  10636779.52 -1.165456e+10 1.052168e+10
## BedUtil                         0.50         0.22  0.000000e+00 1.000000e+00
## AdjPxDays                   74132.50     59723.96  1.570000e+00 2.551466e+06
## CurrentRatio                    2.03         1.35 -1.181660e+03 3.901420e+05
## Debt2Equity                     0.37         0.40 -1.171676e+04 6.134700e+03
## LiabFundBalRatio                0.64         0.76 -1.320090e+04 4.710594e+08
## Overhead                 85164276.76  66911250.25 -5.277931e+07 4.569577e+09
## LaborCompRatio                  0.44         0.13 -1.715000e+01 1.920000e+01
## QuickRatio                      1.88         1.25 -1.089080e+03 3.869345e+05
## BadDebt                  12436839.43   9881205.05 -4.084278e+07 1.025930e+09
## BadDebtARRatio                  0.28         0.21 -8.989680e+03 2.402618e+05
## BadDebtNPRRatio                 0.07         0.05 -3.800000e+00 5.810000e+00
## NetPxRatio              195372698.62 154836636.43 -2.109178e+09 6.418542e+09
## NetOpProfitMargin              -0.01         0.12 -4.001000e+01 4.709000e+01
## OutpatientRev           362967901.57 295158187.04 -2.981246e+06 1.942125e+10
## InpatientRev            365419899.06 300842226.00 -6.974000e+01 1.517090e+10
## NetMedicaidRev           21466422.04  15949857.50  8.600000e-01 9.262182e+09
## NetMedicareRev           39539528.82  33279787.28  6.798000e+03 1.142517e+09
## TotalRevenue            210342627.96 162993282.64 -2.104824e+09 8.952038e+09
## PctPatientDiscounts             0.70         0.12  0.000000e+00 7.080000e+00
## Discharges                   7865.11      6846.65  1.000000e+00 1.686750e+05
## StaffedBeds                   167.74       136.40  1.000000e+00 2.840100e+04
## AvgDailyCensus                 92.24        82.47  0.000000e+00 3.780200e+04
## ALOS                            4.32         0.90  4.200000e-01 6.932000e+03
## MCI                             0.30         0.26  3.000000e-02 1.000000e+00
## OpExpenses              193928692.09 150380278.86 -1.398714e+06 7.240896e+09
## OpIncome                  1247445.15  15654459.83 -2.235644e+09 2.979588e+09
## OtherIncome              11362219.93   7998250.42 -2.211753e+09 5.575550e+09
## NetIncome                13086630.68  14830545.65 -2.231291e+09 3.644555e+09
## NetDelta                        0.03         0.33 -1.000000e+00 1.000000e+00
## IncomeMargin                    0.06         0.09 -1.538900e+02 3.110900e+02
## EBITDA                   11195354.12  17509426.68 -2.235396e+09 3.015184e+09
## CashOnHand                8789867.56   4149730.68 -3.134619e+09 5.328738e+09
## DaysCashOnHand                 28.70        20.21 -1.576700e+03 3.928350e+03
## AccountsReceivable       56775354.82  42963734.63 -2.635397e+08 5.047349e+09
## DaysSalesOutstanding           49.18        12.26 -1.690840e+03 4.328960e+03
## CurrentAssets            65233887.03  45794556.21 -1.982150e+09 1.126050e+10
## TotalAssets             212323254.48 163183332.69 -1.341507e+09 2.313856e+10
## MedicareDays                10233.61      8796.27  1.000000e+00 1.638080e+05
## MedicaidDays                 2678.45      2086.02  1.000000e+00 1.165550e+05
## OtherDays                   22846.01     19856.46  0.000000e+00 5.645940e+05
## CMI                             1.58         0.29  6.000000e-01 5.690000e+00
## MedCMI                          1.20         0.12  3.800000e-01 2.170000e+00
## SurgCMI                         2.77         0.46  4.200000e-01 1.895000e+01
## CC_MCC_Rate                     0.02         0.01  0.000000e+00 9.800000e-01
## CharityCareCost           4234292.98   3439763.95 -2.107557e+07 1.793379e+09
## TotalFreeCare            12420187.80   9938741.05 -6.996236e+06 3.826112e+09
## DSHPaymentMedicare        1038090.29    820206.94  1.000000e+00 1.048547e+08
## MedicareAllowDSHPercent         0.13         0.05 -4.000000e-02 1.330000e+00
## MedicarePerPatient          21522.21      2206.11  1.041400e+04 4.209100e+04
## TPS                            32.60         8.52  6.000000e+00 9.267000e+01
## SeriousComplRate                0.87         0.13  4.400000e-01 2.140000e+00
## HCAHPSStar                      3.02         0.00  1.000000e+00 5.000000e+00
## HospCompare                     3.17         1.48  1.000000e+00 5.000000e+00
## ForProfit                       0.17         0.00  0.000000e+00 1.000000e+00
## Govt                            0.05         0.00  0.000000e+00 1.000000e+00
## Urban_No                        0.01         0.00  0.000000e+00 1.000000e+00
## AltmanX1                        0.02         0.02 -1.514656e+11 1.430000e+00
## AltmanX2                        0.03         0.08 -5.493491e+07 5.654900e+02
## AltmanX3                        0.05         0.12 -7.654705e+06 6.185000e+01
## AltmanX4                        0.00         0.00 -1.000000e+02 0.000000e+00
## OhlsonX1                        0.03         0.00 -1.000000e-02 3.000000e-02
## OhlsonX2                        0.45         0.35 -8.917000e+01 5.270888e+06
## OhlsonX3                        0.16         0.18 -5.270887e+06 1.111200e+02
## OhlsonX4                        0.56         0.36 -6.426000e+02 5.270888e+06
## OhlsonX5                        0.01         0.00  0.000000e+00 1.000000e+00
## OhlsonX6                        0.06         0.09 -5.270888e+06 8.479000e+01
## OhlsonX7                        0.09         0.27 -1.414575e+06 5.819757e+04
## OhlsonX8                        0.40         0.00  0.000000e+00 1.000000e+00
## OhlsonX9                        0.03         0.33 -1.000000e+00 1.000000e+00
##                                range    skew kurtosis         se
## NewIDX                  3.038700e+04    0.00    -1.20      50.32
## IDX                     4.712900e+04    0.01    -1.20      77.62
## Hospital*               3.042000e+03    0.00    -1.20       5.04
## State                   7.700000e+01    0.11    -0.87       0.10
## GEOID                   7.702900e+04   -0.08    -1.20      91.26
## Years_2_Bankrupt        1.070000e+02  -14.16   198.98       0.04
## Bankrupt                1.000000e+00   14.13   197.58       0.00
## Year                    9.000000e+00    0.00    -1.22       0.02
## CurLiab                 1.254714e+10   13.43   377.00 1293256.15
## TotalLiab               2.027999e+10    9.27   148.46 2942447.29
## TotLiabFundBalance      2.653615e+10   12.22   213.08 5771122.96
## FundBalance             1.884921e+10   11.67   205.22 3504136.33
## EquityProxy             2.217624e+10    9.79  1341.40 1186505.76
## BedUtil                 1.000000e+00   -0.15    -0.68       0.00
## AdjPxDays               2.551465e+06    3.45    25.93     599.49
## CurrentRatio            3.913237e+05  100.66 10140.35      21.56
## Debt2Equity             1.785146e+04  -42.06  7229.94       0.58
## LiabFundBalRatio        4.710726e+08  174.30 30381.00   15501.49
## Overhead                4.622357e+09    5.78    62.83 1095776.39
## LaborCompRatio          3.635000e+01   -9.55  2649.93       0.00
## QuickRatio              3.880236e+05  100.66 10140.76      21.39
## BadDebt                 1.066772e+09    7.84   122.76  170553.61
## BadDebtARRatio          2.492515e+05  173.45 30186.28       7.92
## BadDebtNPRRatio         9.610000e+00    4.86   297.86       0.00
## NetPxRatio              8.527720e+09    4.69    36.45 2237151.64
## NetOpProfitMargin       8.710000e+01   32.72  5073.76       0.00
## OutpatientRev           1.942423e+10    6.41    82.95 3953271.89
## InpatientRev            1.517090e+10    4.98    45.20 4918024.35
## NetMedicaidRev          9.262182e+09   50.99  4474.04  583165.15
## NetMedicareRev          1.142510e+09    4.07    27.52  417328.68
## TotalRevenue            1.105686e+10    5.14    44.28 2570153.77
## PctPatientDiscounts     7.080000e+00    1.95   141.33       0.00
## Discharges              1.686740e+05    2.80    15.77      60.07
## StaffedBeds             2.840000e+04   40.87  3303.82       1.70
## AvgDailyCensus          3.780200e+04   78.60  8830.90       1.75
## ALOS                    6.931580e+03   70.95  5064.25       0.51
## MCI                     9.800000e-01    1.02    -0.20       0.00
## OpExpenses              7.242295e+09    5.09    42.81 2359912.69
## OpIncome                5.215232e+09   -1.18   177.04  564935.74
## OtherIncome             7.787303e+09   11.35   426.77  574334.33
## NetIncome               5.875846e+09    7.01   357.22  446029.17
## NetDelta                2.000000e+00   -0.07     0.01       0.00
## IncomeMargin            4.649800e+02  107.95 20203.87       0.01
## EBITDA                  5.250580e+09    0.67   187.80  543640.04
## CashOnHand              8.463358e+09   10.65   373.97  767732.89
## DaysCashOnHand          5.505050e+03    8.31   132.67       0.78
## AccountsReceivable      5.310889e+09    7.70   112.01  983366.93
## DaysSalesOutstanding    6.019800e+03   19.27   546.36       0.65
## CurrentAssets           1.324265e+10    7.87   128.74 1654712.31
## TotalAssets             2.448007e+10   12.18   211.68 5781155.57
## MedicareDays            1.638070e+05    2.85    13.40      87.86
## MedicaidDays            1.165540e+05    4.88    34.39      50.76
## OtherDays               5.645940e+05    3.56    22.62     234.83
## CMI                     5.080000e+00    1.48     6.86       0.00
## MedCMI                  1.790000e+00   -0.23     1.79       0.00
## SurgCMI                 1.854000e+01    2.73    60.50       0.00
## CC_MCC_Rate             9.800000e-01   10.22   172.01       0.00
## CharityCareCost         1.814455e+09   28.87  1446.16  156697.77
## TotalFreeCare           3.833108e+09   27.70  1537.06  290347.31
## DSHPaymentMedicare      1.048547e+08    7.08   103.06   18685.53
## MedicareAllowDSHPercent 1.370000e+00    2.41     7.31       0.00
## MedicarePerPatient      3.167700e+04    0.59     3.38      17.58
## TPS                     8.667000e+01    0.87     1.57       0.06
## SeriousComplRate        1.700000e+00    1.50     5.52       0.00
## HCAHPSStar              4.000000e+00   -0.04     0.35       0.00
## HospCompare             4.000000e+00   -0.04    -0.57       0.01
## ForProfit               1.000000e+00    1.23    -0.47       0.00
## Govt                    1.000000e+00    2.04     2.17       0.00
## Urban_No                1.000000e+00    2.57     4.59       0.00
## AltmanX1                1.514656e+11 -174.30 30381.00 4984389.12
## AltmanX2                5.493547e+07 -170.39 29397.19    1822.84
## AltmanX3                7.654767e+06 -154.79 25046.69     265.11
## AltmanX4                1.000000e+02 -174.30 30381.00       0.00
## OhlsonX1                4.000000e-02  -17.04  1642.73       0.00
## OhlsonX2                5.270977e+06  125.37 15885.51     222.60
## OhlsonX3                5.270998e+06 -125.37 15885.51     222.60
## OhlsonX4                5.271531e+06  125.37 15885.51     222.60
## OhlsonX5                1.000000e+00    2.47     4.12       0.00
## OhlsonX6                5.270973e+06 -125.37 15885.51     222.60
## OhlsonX7                1.472773e+06 -173.27 30145.91      46.64
## OhlsonX8                1.000000e+00    0.32    -1.90       0.00
## OhlsonX9                2.000000e+00   -0.07     0.01       0.00

Bankruptcies by State

myshape=shapefile("cb_2018_us_state_500k.shp") 
myshape$M=as.numeric(myshape$STATEFP)
myf=function(x) sum(x)/10
formap=as.data.frame(aggregate(bankrupt$Bankrupt,by=list(bankrupt$State), FUN=myf))
colnames(formap)=c('M','Bankrupt')
formap=sp::merge(myshape,formap, by="M", all.x=F)
temp=formap
formap=NULL
qpal<-colorBin(c("green", "orange", "red"), 0:10)


leaf=leaflet(temp) %>%
  addTiles(group = "OSM (default)") %>%
  addMapPane("borders", zIndex = 410) %>%
  
  #Base Diagrams
  addPolylines(data = temp,color = "black",
               opacity = 1, weight = 1, group="Borders", options = pathOptions(pane="borders"))%>%
  fitBounds(-124.8, -66.9, 24.4,49.4) %>% setView(-98.6, 39.83, zoom = 4)%>%
  
  addPolygons(stroke = FALSE,fillOpacity = 1, smoothFactor = 0.2, 
              color=~qpal(temp@data$Bankrupt), 
              popup = paste("County: ", temp@data$NAME, "<br>", 
                    "Bankruptices: ", temp@data$Bankrupt, "<br>"))%>%
  
  addLegend(data=temp, 
            "bottomright", opacity=1, pal = qpal, 
            values = ~temp@data$Bankrupt,
            title = "Number Bankruptcies")



leaf

Correlations

Correlations Among Ratios

ratios=bankrupt[, c(16:18, 20:21, 23:25)]
corfunction(ratios)

## Correlations Among Liability Variables

corfunction(bankrupt[, c(9:11 )])

## Correlation Among Revenue, Expense, and Profit Variables

rev=bankrupt[, c(17, 23:27, 35:41)]
corfunction(rev)

## Correlation among Cash-On-Hand Variables & Assets

coh=bankrupt[, c(37:42)]
corfunction(coh)

Correlation Among Treatment Variables

tx=bankrupt[, c(12:13, 26:30, 43:54)]
newtx=tx[,-c(2,8,9,15,6,10)]
corfunction(tx)

## Correlation among Quality Variables

qual=bankrupt[, c(49:52)]
corfunction(qual)

Some Remaining Correlations

corfunction(bankrupt[,-c(1:6)])

Column Names

colnames(bankrupt)
##  [1] "NewIDX"                  "IDX"                    
##  [3] "Hospital"                "State"                  
##  [5] "GEOID"                   "Years_2_Bankrupt"       
##  [7] "Bankrupt"                "Year"                   
##  [9] "CurLiab"                 "TotalLiab"              
## [11] "TotLiabFundBalance"      "FundBalance"            
## [13] "EquityProxy"             "BedUtil"                
## [15] "AdjPxDays"               "CurrentRatio"           
## [17] "Debt2Equity"             "LiabFundBalRatio"       
## [19] "Overhead"                "LaborCompRatio"         
## [21] "QuickRatio"              "BadDebt"                
## [23] "BadDebtARRatio"          "BadDebtNPRRatio"        
## [25] "NetPxRatio"              "NetOpProfitMargin"      
## [27] "OutpatientRev"           "InpatientRev"           
## [29] "NetMedicaidRev"          "NetMedicareRev"         
## [31] "TotalRevenue"            "PctPatientDiscounts"    
## [33] "Discharges"              "StaffedBeds"            
## [35] "AvgDailyCensus"          "ALOS"                   
## [37] "MCI"                     "OpExpenses"             
## [39] "OpIncome"                "OtherIncome"            
## [41] "NetIncome"               "NetDelta"               
## [43] "IncomeMargin"            "EBITDA"                 
## [45] "CashOnHand"              "DaysCashOnHand"         
## [47] "AccountsReceivable"      "DaysSalesOutstanding"   
## [49] "CurrentAssets"           "TotalAssets"            
## [51] "MedicareDays"            "MedicaidDays"           
## [53] "OtherDays"               "CMI"                    
## [55] "MedCMI"                  "SurgCMI"                
## [57] "CC_MCC_Rate"             "CharityCareCost"        
## [59] "TotalFreeCare"           "DSHPaymentMedicare"     
## [61] "MedicareAllowDSHPercent" "MedicarePerPatient"     
## [63] "TPS"                     "SeriousComplRate"       
## [65] "HCAHPSStar"              "HospCompare"            
## [67] "ForProfit"               "Govt"                   
## [69] "Urban_No"                "AltmanX1"               
## [71] "AltmanX2"                "AltmanX3"               
## [73] "AltmanX4"                "OhlsonX1"               
## [75] "OhlsonX2"                "OhlsonX3"               
## [77] "OhlsonX4"                "OhlsonX5"               
## [79] "OhlsonX6"                "OhlsonX7"               
## [81] "OhlsonX8"                "OhlsonX9"

Filter Out Bankrupt Year

We are going to classify bankruptcies without information that we would not have. We eliminate observations that are associated with the year a facility goes bankrupt and the subsequent years. We would not have that data.

newbankrupt=bankrupt[, -c(1:5,7)]
newbankrupt$Years_2_Bankrupt[newbankrupt$Years_2_Bankrupt<0]=-1
newbankrupt$Years_2_Bankrupt[newbankrupt$Years_2_Bankrupt>=0 & newbankrupt$Years_2_Bankrupt<99]=1
newbankrupt$Years_2_Bankrupt[newbankrupt$Years_2_Bankrupt==99]=0
newbankrupt=newbankrupt[newbankrupt$Years_2_Bankrupt!=1,]
newbankrupt$Years_2_Bankrupt=abs(as.numeric(newbankrupt$Years_2_Bankrupt))

Train Test Split

set.seed(1234)
mys=sample(seq(1,nrow(newbankrupt)),.7*nrow(newbankrupt))
mytrain=newbankrupt[mys,]
mytest=newbankrupt[-mys,]

Scale

Some methods are not scale invariant.

for (i in 2:ncol(mytrain)){
  ma=max(mytrain[,i])
  mi=min(mytrain[,i])
  mytrain[,i]=(mytrain[,i]-mi)/(ma-mi)
  mytest[,i]=(mytest[,i]-mi)/(ma-mi)
}

describe(mytrain)
##                         vars     n mean   sd median trimmed  mad min max range
## Years_2_Bankrupt           1 21222 0.00 0.05   0.00    0.00 0.00   0   1     1
## Year                       2 21222 0.50 0.32   0.56    0.50 0.33   0   1     1
## CurLiab                    3 21222 0.19 0.02   0.19    0.19 0.00   0   1     1
## TotalLiab                  4 21222 0.26 0.04   0.25    0.25 0.01   0   1     1
## TotLiabFundBalance         5 21222 0.14 0.04   0.13    0.14 0.01   0   1     1
## FundBalance                6 21222 0.20 0.03   0.19    0.19 0.01   0   1     1
## EquityProxy                7 21222 0.55 0.01   0.55    0.55 0.00   0   1     1
## BedUtil                    8 21222 0.50 0.19   0.51    0.50 0.22   0   1     1
## AdjPxDays                  9 21222 0.04 0.04   0.02    0.03 0.02   0   1     1
## CurrentRatio              10 21222 0.00 0.01   0.00    0.00 0.00   0   1     1
## Debt2Equity               11 21222 0.44 0.01   0.44    0.44 0.00   0   1     1
## LiabFundBalRatio          12 21222 0.00 0.01   0.00    0.00 0.00   0   1     1
## Overhead                  13 21222 0.04 0.04   0.03    0.03 0.01   0   1     1
## LaborCompRatio            14 21222 0.48 0.01   0.48    0.48 0.00   0   1     1
## QuickRatio                15 21222 0.00 0.01   0.00    0.00 0.00   0   1     1
## BadDebt                   16 21222 0.06 0.03   0.05    0.05 0.01   0   1     1
## BadDebtARRatio            17 21222 0.94 0.01   0.94    0.94 0.00   0   1     1
## BadDebtNPRRatio           18 21222 0.41 0.01   0.40    0.40 0.01   0   1     1
## NetPxRatio                19 21222 0.20 0.05   0.19    0.19 0.02   0   1     1
## NetOpProfitMargin         20 21222 0.46 0.01   0.46    0.46 0.00   0   1     1
## OutpatientRev             21 21222 0.03 0.04   0.02    0.02 0.02   0   1     1
## InpatientRev              22 21222 0.04 0.06   0.02    0.02 0.02   0   1     1
## NetMedicaidRev            23 21222 0.00 0.01   0.00    0.00 0.00   0   1     1
## NetMedicareRev            24 21222 0.05 0.06   0.03    0.03 0.03   0   1     1
## TotalRevenue              25 21222 0.16 0.04   0.14    0.15 0.02   0   1     1
## PctPatientDiscounts       26 21222 0.37 0.07   0.38    0.38 0.06   0   1     1
## Discharges                27 21222 0.06 0.06   0.04    0.05 0.04   0   1     1
## StaffedBeds               28 21222 0.01 0.01   0.01    0.01 0.01   0   1     1
## AvgDailyCensus            29 21222 0.01 0.02   0.01    0.01 0.01   0   1     1
## ALOS                      30 21222 0.00 0.01   0.00    0.00 0.00   0   1     1
## MCI                       31 21222 0.32 0.32   0.21    0.27 0.26   0   1     1
## OpExpenses                32 21222 0.04 0.06   0.02    0.03 0.02   0   1     1
## OpIncome                  33 21222 0.41 0.02   0.41    0.41 0.00   0   1     1
## OtherIncome               34 21222 0.29 0.01   0.28    0.29 0.00   0   1     1
## NetIncome                 35 21222 0.34 0.01   0.34    0.34 0.00   0   1     1
## NetDelta                  36 21222 0.51 0.26   0.50    0.51 0.16   0   1     1
## IncomeMargin              37 21222 0.54 0.01   0.54    0.54 0.00   0   1     1
## EBITDA                    38 21222 0.40 0.02   0.40    0.40 0.00   0   1     1
## CashOnHand                39 21222 0.41 0.02   0.40    0.41 0.00   0   1     1
## DaysCashOnHand            40 21222 0.30 0.03   0.29    0.29 0.00   0   1     1
## AccountsReceivable        41 21222 0.07 0.03   0.06    0.06 0.01   0   1     1
## DaysSalesOutstanding      42 21222 0.29 0.02   0.29    0.29 0.00   0   1     1
## CurrentAssets             43 21222 0.22 0.04   0.21    0.22 0.01   0   1     1
## TotalAssets               44 21222 0.07 0.04   0.06    0.06 0.01   0   1     1
## MedicareDays              45 21222 0.08 0.09   0.05    0.06 0.05   0   1     1
## MedicaidDays              46 21222 0.04 0.08   0.01    0.02 0.02   0   1     1
## OtherDays                 47 21222 0.06 0.07   0.03    0.04 0.04   0   1     1
## CMI                       48 21222 0.19 0.07   0.18    0.18 0.06   0   1     1
## MedCMI                    49 21222 0.46 0.08   0.46    0.46 0.07   0   1     1
## SurgCMI                   50 21222 0.13 0.03   0.13    0.13 0.02   0   1     1
## CC_MCC_Rate               51 21222 0.02 0.04   0.01    0.02 0.01   0   1     1
## CharityCareCost           52 21222 0.01 0.02   0.01    0.01 0.00   0   1     1
## TotalFreeCare             53 21222 0.01 0.01   0.00    0.00 0.00   0   1     1
## DSHPaymentMedicare        54 21222 0.02 0.03   0.01    0.01 0.01   0   1     1
## MedicareAllowDSHPercent   55 21222 0.19 0.11   0.16    0.17 0.05   0   1     1
## MedicarePerPatient        56 21222 0.35 0.10   0.35    0.35 0.07   0   1     1
## TPS                       57 21222 0.31 0.12   0.30    0.31 0.10   0   1     1
## SeriousComplRate          58 21222 0.26 0.10   0.25    0.25 0.08   0   1     1
## HCAHPSStar                59 21222 0.50 0.20   0.50    0.51 0.00   0   1     1
## HospCompare               60 21222 0.54 0.27   0.50    0.54 0.37   0   1     1
## ForProfit                 61 21222 0.24 0.42   0.00    0.17 0.00   0   1     1
## Govt                      62 21222 0.14 0.35   0.00    0.05 0.00   0   1     1
## Urban_No                  63 21222 0.11 0.31   0.00    0.01 0.00   0   1     1
## AltmanX1                  64 21222 1.00 0.01   1.00    1.00 0.00   0   1     1
## AltmanX2                  65 21222 1.00 0.01   1.00    1.00 0.00   0   1     1
## AltmanX3                  66 21222 1.00 0.01   1.00    1.00 0.00   0   1     1
## AltmanX4                  67 21222 0.33 0.01   0.33    0.33 0.00   0   1     1
## OhlsonX1                  68 21222 0.91 0.01   0.90    0.90 0.00   0   1     1
## OhlsonX2                  69 21222 0.00 0.01   0.00    0.00 0.00   0   1     1
## OhlsonX3                  70 21222 1.00 0.01   1.00    1.00 0.00   0   1     1
## OhlsonX4                  71 21222 0.00 0.01   0.00    0.00 0.00   0   1     1
## OhlsonX5                  72 21222 0.11 0.31   0.00    0.01 0.00   0   1     1
## OhlsonX6                  73 21222 1.00 0.01   1.00    1.00 0.00   0   1     1
## OhlsonX7                  74 21222 0.96 0.01   0.96    0.96 0.00   0   1     1
## OhlsonX8                  75 21222 0.42 0.49   0.00    0.40 0.00   0   1     1
## OhlsonX9                  76 21222 0.51 0.26   0.50    0.51 0.16   0   1     1
##                            skew kurtosis se
## Years_2_Bankrupt          20.13   403.08  0
## Year                      -0.01    -1.22  0
## CurLiab                   11.94   278.44  0
## TotalLiab                  8.20   107.55  0
## TotLiabFundBalance        12.03   208.52  0
## FundBalance               11.58   201.39  0
## EquityProxy                1.35  1449.76  0
## BedUtil                   -0.15    -0.68  0
## AdjPxDays                  3.69    31.13  0
## CurrentRatio              84.12  7080.36  0
## Debt2Equity               23.69  2894.37  0
## LiabFundBalRatio         145.66 21215.00  0
## Overhead                   5.72    60.64  0
## LaborCompRatio             3.06  2739.15  0
## QuickRatio                84.12  7080.59  0
## BadDebt                    8.60   144.56  0
## BadDebtARRatio           -79.90  6721.59  0
## BadDebtNPRRatio            7.32   370.99  0
## NetPxRatio                 4.70    37.13  0
## NetOpProfitMargin         15.65  5178.01  0
## OutpatientRev              6.28    81.00  0
## InpatientRev               4.93    45.73  0
## NetMedicaidRev            52.03  4116.19  0
## NetMedicareRev             4.08    28.10  0
## TotalRevenue               5.19    46.11  0
## PctPatientDiscounts       -1.21     3.11  0
## Discharges                 2.88    17.44  0
## StaffedBeds               22.08  1334.45  0
## AvgDailyCensus            14.75   769.97  0
## ALOS                      83.94  7108.66  0
## MCI                        1.03    -0.17  0
## OpExpenses                 5.04    42.29  0
## OpIncome                  -1.37   166.35  0
## OtherIncome               12.56   504.56  0
## NetIncome                  7.98   363.41  0
## NetDelta                  -0.07     0.01  0
## IncomeMargin             -12.63  1760.42  0
## EBITDA                     0.46   170.67  0
## CashOnHand                 8.23   257.33  0
## DaysCashOnHand             8.79   144.00  0
## AccountsReceivable         8.07   123.92  0
## DaysSalesOutstanding      18.19   504.86  0
## CurrentAssets              6.45    61.81  0
## TotalAssets               12.01   207.72  0
## MedicareDays               2.87    13.86  0
## MedicaidDays               4.96    35.79  0
## OtherDays                  3.65    24.62  0
## CMI                        1.52     7.48  0
## MedCMI                    -0.25     1.73  0
## SurgCMI                    3.40    79.87  0
## CC_MCC_Rate               10.50   178.91  0
## CharityCareCost           29.33  1427.34  0
## TotalFreeCare             28.82  1503.36  0
## DSHPaymentMedicare         7.38   110.50  0
## MedicareAllowDSHPercent    2.38     6.83  0
## MedicarePerPatient         0.55     3.22  0
## TPS                        0.89     1.69  0
## SeriousComplRate           1.49     5.47  0
## HCAHPSStar                -0.05     0.38  0
## HospCompare               -0.04    -0.57  0
## ForProfit                  1.24    -0.46  0
## Govt                       2.06     2.24  0
## Urban_No                   2.56     4.55  0
## AltmanX1                -145.66 21215.00  0
## AltmanX2                -142.38 20527.97  0
## AltmanX3                -129.35 17489.84  0
## AltmanX4                  37.91  4365.13  0
## OhlsonX1                 -21.83  1915.01  0
## OhlsonX2                 104.77 11092.11  0
## OhlsonX3                -104.77 11092.11  0
## OhlsonX4                 104.77 11092.11  0
## OhlsonX5                   2.47     4.10  0
## OhlsonX6                -104.77 11092.11  0
## OhlsonX7                -144.80 21052.52  0
## OhlsonX8                   0.32    -1.89  0
## OhlsonX9                  -0.07     0.01  0

Oversample

We have highly imbalanced data. To improve classification we oversample the positive cases of bankruptcy using majority weighted oversampline.

mytrain2=mytrain
tmp=mwmote(mytrain2, numInstances = 4000, classAttr="Years_2_Bankrupt")
tmp$Years_2_Bankrupt=round(tmp$Years_2_Bankrupt,0)
mytrain2=rbind(mytrain2,tmp)
table(mytrain2$Years_2_Bankrupt)
## 
##     0     1 
## 21170  4052

Prepare for Models

We build two new dataframes with the training and test sets to prevent re-running of code.

train=mytrain2
test=mytest

train$Years_2_Bankrupt=as.factor(train$Years_2_Bankrupt)
test$Years_2_Bankrupt=as.factor(test$Years_2_Bankrupt)

Confusion Matrix Function

This function is useful for some of the models. Others are done manually.

mycm=function(model){
  tmp=round(predict(model,test, type='response'),0)
  tmp[tmp>1]=1
  return(confusionMatrix(as.factor(tmp), as.factor(test$Years_2_Bankrupt), positive='1'))}

Models

Log. Reg.

Logistic regression model

m1=glm(Years_2_Bankrupt~Year+
         BedUtil+AdjPxDays+
         StaffedBeds+MedicareDays+
         CMI+TotalFreeCare+
         ForProfit+Govt+Urban_No+
         OhlsonX1+OhlsonX2+OhlsonX3+OhlsonX4+OhlsonX5+OhlsonX6+OhlsonX7+OhlsonX8+OhlsonX9, data=train, family='binomial')
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
(summary(m1))
## 
## Call:
## glm(formula = Years_2_Bankrupt ~ Year + BedUtil + AdjPxDays + 
##     StaffedBeds + MedicareDays + CMI + TotalFreeCare + ForProfit + 
##     Govt + Urban_No + OhlsonX1 + OhlsonX2 + OhlsonX3 + OhlsonX4 + 
##     OhlsonX5 + OhlsonX6 + OhlsonX7 + OhlsonX8 + OhlsonX9, family = "binomial", 
##     data = train)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -8.4904  -0.4023  -0.1882  -0.0630   2.9424  
## 
## Coefficients:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   -3.590e+04  1.100e+05  -0.326   0.7442    
## Year          -2.620e+00  8.985e-02 -29.157  < 2e-16 ***
## BedUtil        1.229e-01  1.942e-01   0.633   0.5268    
## AdjPxDays     -1.007e+01  3.917e+00  -2.570   0.0102 *  
## StaffedBeds    9.148e+01  8.981e+00  10.187  < 2e-16 ***
## MedicareDays  -1.451e+01  1.170e+00 -12.407  < 2e-16 ***
## CMI           -6.743e+00  5.026e-01 -13.416  < 2e-16 ***
## TotalFreeCare -6.369e+01  9.880e+00  -6.446 1.15e-10 ***
## ForProfit      1.343e+00  5.676e-02  23.657  < 2e-16 ***
## Govt           7.971e-01  6.464e-02  12.330  < 2e-16 ***
## Urban_No       6.342e-01  6.384e-02   9.935  < 2e-16 ***
## OhlsonX1      -5.412e+00  2.801e+00  -1.932   0.0534 .  
## OhlsonX2      -2.833e+05  1.214e+05  -2.333   0.0196 *  
## OhlsonX3       9.775e+04  8.900e+04   1.098   0.2721    
## OhlsonX4      -1.919e+04  1.476e+04  -1.300   0.1937    
## OhlsonX5       1.969e+00  6.200e-02  31.760  < 2e-16 ***
## OhlsonX6      -6.184e+04  1.171e+05  -0.528   0.5974    
## OhlsonX7       1.909e+00  9.635e+00   0.198   0.8429    
## OhlsonX8       9.796e-01  5.733e-02  17.087  < 2e-16 ***
## OhlsonX9      -2.706e-01  9.503e-02  -2.848   0.0044 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 22233  on 25221  degrees of freedom
## Residual deviance: 12850  on 25202  degrees of freedom
## AIC: 12890
## 
## Number of Fisher Scoring iterations: 25
mycm(m1)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction    0    1
##          0 8714   19
##          1  354    9
##                                          
##                Accuracy : 0.959          
##                  95% CI : (0.9547, 0.963)
##     No Information Rate : 0.9969         
##     P-Value [Acc > NIR] : 1              
##                                          
##                   Kappa : 0.0406         
##                                          
##  Mcnemar's Test P-Value : <2e-16         
##                                          
##             Sensitivity : 0.3214286      
##             Specificity : 0.9609616      
##          Pos Pred Value : 0.0247934      
##          Neg Pred Value : 0.9978243      
##              Prevalence : 0.0030783      
##          Detection Rate : 0.0009894      
##    Detection Prevalence : 0.0399077      
##       Balanced Accuracy : 0.6411951      
##                                          
##        'Positive' Class : 1              
## 

Random Forest

library(randomForest)
## randomForest 4.7-1.1
## Type rfNews() to see new features/changes/bug fixes.
## 
## Attaching package: 'randomForest'
## The following object is masked from 'package:psych':
## 
##     outlier
## The following object is masked from 'package:gridExtra':
## 
##     combine
## The following object is masked from 'package:ggplot2':
## 
##     margin
## The following object is masked from 'package:dplyr':
## 
##     combine
library(caret)
newtest=test
newtrain=train
myrf=randomForest(Years_2_Bankrupt~.,data=newtrain, xtest=newtest[,-1], ytest=test$Years_2_Bankrupt, importance=T, ntree=100)

myrf
## 
## Call:
##  randomForest(formula = Years_2_Bankrupt ~ ., data = newtrain,      xtest = newtest[, -1], ytest = test$Years_2_Bankrupt, importance = T,      ntree = 100) 
##                Type of random forest: classification
##                      Number of trees: 100
## No. of variables tried at each split: 8
## 
##         OOB estimate of  error rate: 0.07%
## Confusion matrix:
##       0    1  class.error
## 0 21169    1 4.723666e-05
## 1    17 4035 4.195459e-03
##                 Test set error rate: 0.13%
## Confusion matrix:
##      0  1 class.error
## 0 9068  0   0.0000000
## 1   12 16   0.4285714
cl=myrf$test$votes[,2]
cl[cl<.5]=0
cl=round(cl,0)
confusionMatrix(table(cl,test$Years_2_Bankrupt), positive='1')
## Confusion Matrix and Statistics
## 
##    
## cl     0    1
##   0 9068   12
##   1    0   16
##                                           
##                Accuracy : 0.9987          
##                  95% CI : (0.9977, 0.9993)
##     No Information Rate : 0.9969          
##     P-Value [Acc > NIR] : 0.0005562       
##                                           
##                   Kappa : 0.7267          
##                                           
##  Mcnemar's Test P-Value : 0.0014962       
##                                           
##             Sensitivity : 0.571429        
##             Specificity : 1.000000        
##          Pos Pred Value : 1.000000        
##          Neg Pred Value : 0.998678        
##              Prevalence : 0.003078        
##          Detection Rate : 0.001759        
##    Detection Prevalence : 0.001759        
##       Balanced Accuracy : 0.785714        
##                                           
##        'Positive' Class : 1               
## 
varImpPlot(myrf, n.var=15)

SVM

mysvm=svm(Years_2_Bankrupt~., data=train)
confusionMatrix(table(predict(mysvm, test),test$Years_2_Bankrupt), positive='1')
## Confusion Matrix and Statistics
## 
##    
##        0    1
##   0 9033    6
##   1   35   22
##                                           
##                Accuracy : 0.9955          
##                  95% CI : (0.9939, 0.9968)
##     No Information Rate : 0.9969          
##     P-Value [Acc > NIR] : 0.9921          
##                                           
##                   Kappa : 0.5156          
##                                           
##  Mcnemar's Test P-Value : 1.226e-05       
##                                           
##             Sensitivity : 0.785714        
##             Specificity : 0.996140        
##          Pos Pred Value : 0.385965        
##          Neg Pred Value : 0.999336        
##              Prevalence : 0.003078        
##          Detection Rate : 0.002419        
##    Detection Prevalence : 0.006266        
##       Balanced Accuracy : 0.890927        
##                                           
##        'Positive' Class : 1               
## 
print(summary(mysvm))
## 
## Call:
## svm(formula = Years_2_Bankrupt ~ ., data = train)
## 
## 
## Parameters:
##    SVM-Type:  C-classification 
##  SVM-Kernel:  radial 
##        cost:  1 
## 
## Number of Support Vectors:  1761
## 
##  ( 889 872 )
## 
## 
## Number of Classes:  2 
## 
## Levels: 
##  0 1
w = as.data.frame(round(t(mysvm$SV) %*% mysvm$coefs,3))
w$ABS=abs(w[,1])
colnames(w)=c('Coeff', 'Abs')
w[order(w$Abs, decreasing=T),]
##                           Coeff    Abs
## CMI                      46.268 46.268
## MedicareDays             37.290 37.290
## OtherDays                37.156 37.156
## BedUtil                  34.230 34.230
## Urban_No                -33.531 33.531
## DaysSalesOutstanding    -32.881 32.881
## Govt                    -31.419 31.419
## CharityCareCost          31.196 31.196
## BadDebtNPRRatio         -29.625 29.625
## MedCMI                   29.012 29.012
## OhlsonX5                -25.635 25.635
## Overhead                -25.592 25.592
## MedicaidDays            -24.123 24.123
## TPS                     -23.731 23.731
## EBITDA                   20.978 20.978
## OhlsonX8                -20.083 20.083
## NetIncome                19.127 19.127
## OutpatientRev           -18.608 18.608
## OhlsonX1                 18.453 18.453
## CC_MCC_Rate              18.430 18.430
## FundBalance              17.966 17.966
## TotalFreeCare            17.687 17.687
## SurgCMI                  16.467 16.467
## MCI                     -16.090 16.090
## NetOpProfitMargin        15.983 15.983
## MedicarePerPatient       11.963 11.963
## SeriousComplRate        -10.957 10.957
## BadDebtARRatio          -10.209 10.209
## DaysCashOnHand            9.598  9.598
## IncomeMargin              9.378  9.378
## OpIncome                  9.336  9.336
## TotalAssets               8.940  8.940
## AccountsReceivable        8.787  8.787
## TotLiabFundBalance        8.783  8.783
## Discharges                7.735  7.735
## NetMedicareRev           -7.083  7.083
## Year                      6.721  6.721
## PctPatientDiscounts      -6.281  6.281
## EquityProxy              -5.934  5.934
## Debt2Equity              -5.495  5.495
## AltmanX4                  5.322  5.322
## AdjPxDays                 5.246  5.246
## OtherIncome               5.161  5.161
## MedicareAllowDSHPercent   4.988  4.988
## HCAHPSStar               -4.851  4.851
## NetDelta                  4.842  4.842
## OhlsonX9                  4.842  4.842
## TotalLiab                -4.403  4.403
## InpatientRev             -4.185  4.185
## AvgDailyCensus            4.151  4.151
## ALOS                      3.915  3.915
## TotalRevenue             -3.752  3.752
## NetPxRatio                3.577  3.577
## CashOnHand               -3.393  3.393
## CurrentAssets            -3.058  3.058
## ForProfit                -2.738  2.738
## LaborCompRatio            2.433  2.433
## DSHPaymentMedicare       -2.290  2.290
## StaffedBeds               1.690  1.690
## BadDebt                   1.622  1.622
## OpExpenses                1.230  1.230
## HospCompare               1.079  1.079
## CurLiab                   1.059  1.059
## NetMedicaidRev            0.624  0.624
## CurrentRatio              0.530  0.530
## QuickRatio                0.497  0.497
## OhlsonX7                  0.299  0.299
## OhlsonX3                 -0.005  0.005
## AltmanX3                  0.002  0.002
## OhlsonX4                  0.002  0.002
## OhlsonX2                  0.001  0.001
## LiabFundBalRatio          0.000  0.000
## AltmanX1                  0.000  0.000
## AltmanX2                  0.000  0.000
## OhlsonX6                  0.000  0.000
(b = -mysvm$rho)
## [1] 7.870877

XG Boost

library(xgboost) #for fitting the xgboost model
## 
## Attaching package: 'xgboost'
## The following object is masked from 'package:dplyr':
## 
##     slice
xgbtrain_x=data.matrix(train[,-1])
xgbtrain_y=train[,1]

xgbtest_x=data.matrix(test[,-1])
xgbtest_y=test[,1]

xgbtrain=xgb.DMatrix(xgbtrain_x,label=xgbtrain_y)

xgbtest=xgb.DMatrix(xgbtest_x,label=xgbtest_y)

watchlist = list(train=xgbtrain, test=xgbtest)
model = xgb.train(data = xgbtrain, max.depth = 3, watchlist=watchlist, nrounds = 70)
## [1]  train-rmse:0.554022 test-rmse:0.340997 
## [2]  train-rmse:0.417924 test-rmse:0.231472 
## [3]  train-rmse:0.329416 test-rmse:0.163728 
## [4]  train-rmse:0.266311 test-rmse:0.127328 
## [5]  train-rmse:0.224305 test-rmse:0.110318 
## [6]  train-rmse:0.198990 test-rmse:0.105100 
## [7]  train-rmse:0.179303 test-rmse:0.107324 
## [8]  train-rmse:0.169704 test-rmse:0.109560 
## [9]  train-rmse:0.162227 test-rmse:0.108780 
## [10] train-rmse:0.155565 test-rmse:0.108380 
## [11] train-rmse:0.150970 test-rmse:0.109760 
## [12] train-rmse:0.146668 test-rmse:0.109199 
## [13] train-rmse:0.142199 test-rmse:0.108745 
## [14] train-rmse:0.138660 test-rmse:0.108098 
## [15] train-rmse:0.135169 test-rmse:0.106447 
## [16] train-rmse:0.131492 test-rmse:0.105273 
## [17] train-rmse:0.129061 test-rmse:0.104247 
## [18] train-rmse:0.125140 test-rmse:0.102804 
## [19] train-rmse:0.122900 test-rmse:0.102075 
## [20] train-rmse:0.121960 test-rmse:0.101718 
## [21] train-rmse:0.119632 test-rmse:0.100507 
## [22] train-rmse:0.116431 test-rmse:0.098942 
## [23] train-rmse:0.115020 test-rmse:0.098302 
## [24] train-rmse:0.112946 test-rmse:0.097289 
## [25] train-rmse:0.111200 test-rmse:0.096010 
## [26] train-rmse:0.109530 test-rmse:0.095384 
## [27] train-rmse:0.108236 test-rmse:0.094426 
## [28] train-rmse:0.106599 test-rmse:0.093314 
## [29] train-rmse:0.105730 test-rmse:0.092695 
## [30] train-rmse:0.104157 test-rmse:0.092313 
## [31] train-rmse:0.102912 test-rmse:0.091938 
## [32] train-rmse:0.100852 test-rmse:0.091318 
## [33] train-rmse:0.097922 test-rmse:0.090256 
## [34] train-rmse:0.096908 test-rmse:0.089575 
## [35] train-rmse:0.095489 test-rmse:0.088997 
## [36] train-rmse:0.094204 test-rmse:0.088302 
## [37] train-rmse:0.093343 test-rmse:0.087603 
## [38] train-rmse:0.092800 test-rmse:0.087363 
## [39] train-rmse:0.091879 test-rmse:0.086934 
## [40] train-rmse:0.091629 test-rmse:0.086767 
## [41] train-rmse:0.091113 test-rmse:0.086762 
## [42] train-rmse:0.090330 test-rmse:0.086566 
## [43] train-rmse:0.089610 test-rmse:0.086120 
## [44] train-rmse:0.088904 test-rmse:0.085698 
## [45] train-rmse:0.088087 test-rmse:0.085251 
## [46] train-rmse:0.087467 test-rmse:0.084859 
## [47] train-rmse:0.086797 test-rmse:0.084669 
## [48] train-rmse:0.086243 test-rmse:0.084503 
## [49] train-rmse:0.085303 test-rmse:0.084161 
## [50] train-rmse:0.085040 test-rmse:0.084086 
## [51] train-rmse:0.084340 test-rmse:0.083813 
## [52] train-rmse:0.083697 test-rmse:0.082975 
## [53] train-rmse:0.082834 test-rmse:0.082717 
## [54] train-rmse:0.082069 test-rmse:0.082091 
## [55] train-rmse:0.081639 test-rmse:0.081697 
## [56] train-rmse:0.081217 test-rmse:0.081555 
## [57] train-rmse:0.080986 test-rmse:0.081461 
## [58] train-rmse:0.080569 test-rmse:0.081068 
## [59] train-rmse:0.079873 test-rmse:0.080258 
## [60] train-rmse:0.079240 test-rmse:0.080331 
## [61] train-rmse:0.078969 test-rmse:0.080260 
## [62] train-rmse:0.078215 test-rmse:0.079809 
## [63] train-rmse:0.077779 test-rmse:0.079229 
## [64] train-rmse:0.077471 test-rmse:0.079016 
## [65] train-rmse:0.077318 test-rmse:0.078802 
## [66] train-rmse:0.076845 test-rmse:0.078793 
## [67] train-rmse:0.076351 test-rmse:0.078381 
## [68] train-rmse:0.076091 test-rmse:0.078116 
## [69] train-rmse:0.075898 test-rmse:0.077985 
## [70] train-rmse:0.075561 test-rmse:0.077694
importance_matrix <- xgb.importance(colnames(train[,-1]), model =model)

mypred4=as.factor(round(predict(model,xgbtest),0)-1)
confusionMatrix(table(mypred4,test$Years_2_Bankrupt), positive='1')
## Confusion Matrix and Statistics
## 
##        
## mypred4    0    1
##       0 9059    7
##       1    9   21
##                                          
##                Accuracy : 0.9982         
##                  95% CI : (0.9971, 0.999)
##     No Information Rate : 0.9969         
##     P-Value [Acc > NIR] : 0.01006        
##                                          
##                   Kappa : 0.7233         
##                                          
##  Mcnemar's Test P-Value : 0.80259        
##                                          
##             Sensitivity : 0.750000       
##             Specificity : 0.999007       
##          Pos Pred Value : 0.700000       
##          Neg Pred Value : 0.999228       
##              Prevalence : 0.003078       
##          Detection Rate : 0.002309       
##    Detection Prevalence : 0.003298       
##       Balanced Accuracy : 0.874504       
##                                          
##        'Positive' Class : 1              
## 
xgb.ggplot.importance(importance_matrix, top_n=15)