---
title: "Profiling hospitals based on psychiatric readmission rates"
author: "Kenneth Nieser"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Profiling hospitals based on psychiatric readmission rates}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 8,
  fig.height = 6
)
```

This vignette includes an example of hospital profiling based on a measure of thirty-day all-cause unplanned readmission following psychiatric hospitalization in an inpatient psychiatric facility (IPF Readmission). This claims-based measure is reported by hospitals to CMS as part of the Inpatient Psychiatric Facility Quality Reporting Program.


```{r setup}
library(QualityMeasure)
```


-------------------------------------------------------------

First, we'll load the dataset included with the `QualityMeasure` package.

```{r}
df <- psychreadmission
knitr::kable(head(df), 'simple')
```

Next, we will plot the risk-standardized readmission rates (RSRR) with corresponding confidence intervals and a dashed, red line to indicate the national average rate.

```{r}
marg.p = sum(df$n * df$rate) / (sum(df$n)) / 100

df$rank = rank(df$rate, ties.method = 'random')

profile.fig <- ggplot(data = df, aes(x = rank, y = rate)) +
  geom_point(color = 'black') +
  geom_errorbar(aes(ymin = rate.lwr, ymax = rate.upr), width = 0.1) +
  geom_hline(yintercept = marg.p * 100, col = 'red', lty = 'dashed', linewidth = 1.2, alpha = 0.7) +
  xlab('Hospital Rank') +
  ylab('Readmission Rate (%)') +
  theme_classic() +
  theme(
    axis.text = element_text(size = 16),
    axis.ticks.length = unit(.25, 'cm'),
    axis.title = element_text(size = 18, face = 'bold')
  )
profile.fig
```
<br>

We can also examine the number of hospitals with rates that are below average, above average, and no different from average.

```{r}
knitr::kable(table(df$category), 'simple', col.names = c('Category', 'Count'))
```



