Skip to content

Commit

Permalink
add rmd example
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Sep 21, 2017
1 parent e9c297c commit cf4af9a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions notebooks/rmd_mimic_los/mimic_los.Rmd
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 added notebooks/rmd_mimic_los/mimic_los.pdf
Binary file not shown.

0 comments on commit cf4af9a

Please sign in to comment.