Exploring length of stay in the ICU


In [48]:
# install.packages("RPostgreSQL")
require("RPostgreSQL")
require("ggplot2")

In [4]:
# load the PostgreSQL driver
drv <- dbDriver("PostgreSQL")

In [19]:
# create a connection to the postgres database
# set the search path to the mimiciii schema
con <- dbConnect(drv, dbname = "mimic",
                 host = "localhost", port = 5432,
                 user = "mimic")
dbSendQuery(con, 'set search_path to mimiciii')

In [34]:
# show a list of tables
dbListTables(con)


Out[34]:
  1. 'admissions'
  2. 'callout'
  3. 'caregivers'
  4. 'chartevents'
  5. 'chartevents_1'
  6. 'chartevents_2'
  7. 'chartevents_3'
  8. 'chartevents_4'
  9. 'chartevents_5'
  10. 'chartevents_6'
  11. 'chartevents_7'
  12. 'chartevents_8'
  13. 'chartevents_9'
  14. 'chartevents_10'
  15. 'chartevents_11'
  16. 'chartevents_12'
  17. 'chartevents_13'
  18. 'chartevents_14'
  19. 'cptevents'
  20. 'datetimeevents'
  21. 'diagnoses_icd'
  22. 'drgcodes'
  23. 'd_cpt'
  24. 'd_icd_diagnoses'
  25. 'd_icd_procedures'
  26. 'd_items'
  27. 'd_labitems'
  28. 'icustays'
  29. 'inputevents_cv'
  30. 'inputevents_mv'
  31. 'labevents'
  32. 'microbiologyevents'
  33. 'noteevents'
  34. 'outputevents'
  35. 'prescriptions'
  36. 'procedureevents_mv'
  37. 'procedures_icd'
  38. 'services'
  39. 'transfers'
  40. 'noteevents_deid'
  41. 'patients'

In [90]:
# assign ICU length of stay to variable
iculos = dbGetQuery(con, "select los from icustays where los >= 0 and los <=20")

In [93]:
# plot histogram of length of stay in the ICU
qplot(iculos$los, geom="histogram", binwidth = 1, main = "Length of stay in the ICU", 
      xlab = "Length of stay, days", fill=I("#9ebcda"), col=I("#FFFFFF"))



In [ ]:
# close the connection
dbDisconnect(con)
dbUnloadDriver(drv)