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)}
######################
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
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)
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
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)
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
for(i in 1:ncol(bankrupt)){
if(is.numeric(bankrupt[,i])){
bankrupt[is.na(bankrupt[,i]), i] <- median(bankrupt[,i], na.rm = TRUE)
}
}
missmap(bankrupt)
#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
bankrupt$Loss2Years=NULL
bankrupt$ROWMISS=NULL
bankrupt$Impute=NULL
write.csv(bankrupt, 'c:/users/lfult/documents/bankruptcy study/cleaned data.csv', row.names=F )
bankrupt=read.csv('c:/users/lfult/documents/bankruptcy study/cleaned data.csv', stringsAsFactors = T)
bankrupt$Year=as.numeric(bankrupt$Year)
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
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