forked from MIT-LCP/mimic-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9c297c
commit cf4af9a
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: "Average length of ICU stay in MIMIC-III" | ||
author: "tom pollard" | ||
description: "Average length of ICU stay in MIMIC-III" | ||
output: pdf_document | ||
date: "10/10/2017" | ||
--- | ||
|
||
```{r setup, include = FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
library(ggplot2) | ||
library(RPostgreSQL) | ||
``` | ||
|
||
|
||
```{r dbconnect, include=FALSE} | ||
# Load configuration settings | ||
dbdriver <- 'PostgreSQL' | ||
host <- '127.0.0.1' | ||
port <- '5432' | ||
user <- 'postgres' | ||
password <- 'postgres' | ||
dbname <- 'mimic' | ||
schema <- 'mimiciii' | ||
# Connect to the database using the configuration settings | ||
con <- dbConnect(dbDriver(dbdriver), dbname = dbname, host = host, port = port, | ||
user = user, password = password) | ||
# Set the default schema | ||
dbExecute(con, paste("SET search_path TO ", schema, sep=" ")) | ||
``` | ||
|
||
|
||
```{r load_data, include=FALSE} | ||
sql_query <- "SELECT i.subject_id, i.hadm_id, i.los | ||
FROM icustays i;" | ||
data <- dbGetQuery(con, sql_query) | ||
``` | ||
|
||
This is an RMarkdown document that demonstrates a reproducible analysis using MIMIC-III (version 1.4). Let's calculate the mean length of stay in the ICU and then include this value in our document. | ||
|
||
```{r calculate_mean_los, include=FALSE} | ||
avg_los <- mean(data$los, na.rm=TRUE) | ||
rounded_avg_los <-round(avg_los, digits = 2) | ||
``` | ||
|
||
So the mean length of stay in the ICU is `r avg_los` days. Rounded to two days, this is `r rounded_avg_los` days. We can plot the distribution of length of stay using the qplot function: | ||
|
||
|
||
```{r plot_los, echo=FALSE, include=TRUE, warning = FALSE} | ||
qplot(data$los, geom="histogram",xlim=c(0,25), binwidth = 1, | ||
xlab = "Length of stay, days.",fill=I("#FF9999"), col=I("white")) | ||
``` |
Binary file not shown.