nurse

references:
- ISI, exploration 5.1, p.264

library(tidyverse)

data

nurse <- read.delim("Gilbert.txt", header = TRUE)
str(nurse)
## 'data.frame':    1641 obs. of  2 variables:
##  $ GilbertWorked.: Factor w/ 2 levels "No","Yes": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Patient       : Factor w/ 2 levels "Death","NoDeath": 1 1 1 1 1 1 1 1 1 1 ...
tbl <- nurse %>%
  group_by(GilbertWorked., Patient) %>%
  summarize(n = n())
tbl
## # A tibble: 4 x 3
## # Groups:   GilbertWorked. [?]
##   GilbertWorked. Patient     n
##           <fctr>  <fctr> <int>
## 1             No   Death    34
## 2             No NoDeath  1350
## 3            Yes   Death    40
## 4            Yes NoDeath   217

contingency table

tbl2 <- c(40, 257 - 40, 34, 1384 - 34)
dim(tbl2) <- c(2, 2)
dimnames(tbl2) <- list(patient.died = c("yes", "no"),
                       Gilbert.working = c("yes", "no"))
tbl2
##             Gilbert.working
## patient.died yes   no
##          yes  40   34
##          no  217 1350

mosaicplot

mosaicplot(t(tbl2), col = c("yellow", "green"), main = "Nurse")