Chapter 3, Displaying and Describing Catagorical Data

Homework 3.3 Problem 37

Hospitals <- matrix(c(120,680,10,40,10,190,20,230),ncol=4,byrow=TRUE)
colnames(Hospitals) <- c("LH delayed","LH discharged","SH delayed","SH discharged")

rownames(Hospitals) <- c("Major surgery","Minor sugery")
Hospitals <- as.table(Hospitals)
Hospitals
##               LH delayed LH discharged SH delayed SH discharged
## Major surgery        120           680         10            40
## Minor sugery          10           190         20           230
Hospitals2 <- matrix(c(120,680,10,190),ncol=2,byrow=TRUE)
colnames(Hospitals2) <- c("LH delayed","LH discharged")

rownames(Hospitals2) <- c("Major surgery","Minor sugery")
Hospitals2 <- as.table(Hospitals)
Hospitals2
##               LH delayed LH discharged SH delayed SH discharged
## Major surgery        120           680         10            40
## Minor sugery          10           190         20           230
Hospitals3 <- matrix(c(10,40,20,230),ncol=2,byrow=TRUE)
colnames(Hospitals3) <- c("SH delayed","SH discharged")

rownames(Hospitals3) <- c("Major surgery","Minor sugery")
Hospitals3 <- as.table(Hospitals)
Hospitals3
##               LH delayed LH discharged SH delayed SH discharged
## Major surgery        120           680         10            40
## Minor sugery          10           190         20           230

CrossTable from the gmodels package does all these at once.

library(gmodels)
as.data.frame.matrix(Hospitals2)
##               LH delayed LH discharged SH delayed SH discharged
## Major surgery        120           680         10            40
## Minor sugery          10           190         20           230
CrossTable(Hospitals2, prop.t=TRUE, prop.r=TRUE, prop.c=TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  1300 
## 
##  
##               |  
##               |    LH delayed | LH discharged |    SH delayed | SH discharged |     Row Total | 
## --------------|---------------|---------------|---------------|---------------|---------------|
## Major surgery |           120 |           680 |            10 |            40 |           850 | 
##               |        14.412 |        21.720 |         4.713 |       105.602 |               | 
##               |         0.141 |         0.800 |         0.012 |         0.047 |         0.654 | 
##               |         0.923 |         0.782 |         0.333 |         0.148 |               | 
##               |         0.092 |         0.523 |         0.008 |         0.031 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
##  Minor sugery |            10 |           190 |            20 |           230 |           450 | 
##               |        27.222 |        41.026 |         8.903 |       199.470 |               | 
##               |         0.022 |         0.422 |         0.044 |         0.511 |         0.346 | 
##               |         0.077 |         0.218 |         0.667 |         0.852 |               | 
##               |         0.008 |         0.146 |         0.015 |         0.177 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
##  Column Total |           130 |           870 |            30 |           270 |          1300 | 
##               |         0.100 |         0.669 |         0.023 |         0.208 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
## 
## 
library(gmodels)
as.data.frame.matrix(Hospitals2)
##               LH delayed LH discharged SH delayed SH discharged
## Major surgery        120           680         10            40
## Minor sugery          10           190         20           230
CrossTable(Hospitals2, prop.t=TRUE, prop.r=TRUE, prop.c=TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  1300 
## 
##  
##               |  
##               |    LH delayed | LH discharged |    SH delayed | SH discharged |     Row Total | 
## --------------|---------------|---------------|---------------|---------------|---------------|
## Major surgery |           120 |           680 |            10 |            40 |           850 | 
##               |        14.412 |        21.720 |         4.713 |       105.602 |               | 
##               |         0.141 |         0.800 |         0.012 |         0.047 |         0.654 | 
##               |         0.923 |         0.782 |         0.333 |         0.148 |               | 
##               |         0.092 |         0.523 |         0.008 |         0.031 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
##  Minor sugery |            10 |           190 |            20 |           230 |           450 | 
##               |        27.222 |        41.026 |         8.903 |       199.470 |               | 
##               |         0.022 |         0.422 |         0.044 |         0.511 |         0.346 | 
##               |         0.077 |         0.218 |         0.667 |         0.852 |               | 
##               |         0.008 |         0.146 |         0.015 |         0.177 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
##  Column Total |           130 |           870 |            30 |           270 |          1300 | 
##               |         0.100 |         0.669 |         0.023 |         0.208 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
## 
## 
library(gmodels)
as.data.frame.matrix(Hospitals3)
##               LH delayed LH discharged SH delayed SH discharged
## Major surgery        120           680         10            40
## Minor sugery          10           190         20           230
CrossTable(Hospitals3, prop.t=TRUE, prop.r=TRUE, prop.c=TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  1300 
## 
##  
##               |  
##               |    LH delayed | LH discharged |    SH delayed | SH discharged |     Row Total | 
## --------------|---------------|---------------|---------------|---------------|---------------|
## Major surgery |           120 |           680 |            10 |            40 |           850 | 
##               |        14.412 |        21.720 |         4.713 |       105.602 |               | 
##               |         0.141 |         0.800 |         0.012 |         0.047 |         0.654 | 
##               |         0.923 |         0.782 |         0.333 |         0.148 |               | 
##               |         0.092 |         0.523 |         0.008 |         0.031 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
##  Minor sugery |            10 |           190 |            20 |           230 |           450 | 
##               |        27.222 |        41.026 |         8.903 |       199.470 |               | 
##               |         0.022 |         0.422 |         0.044 |         0.511 |         0.346 | 
##               |         0.077 |         0.218 |         0.667 |         0.852 |               | 
##               |         0.008 |         0.146 |         0.015 |         0.177 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
##  Column Total |           130 |           870 |            30 |           270 |          1300 | 
##               |         0.100 |         0.669 |         0.023 |         0.208 |               | 
## --------------|---------------|---------------|---------------|---------------|---------------|
## 
## 
  1. 0.1+0.023=12.3% were discharged delayed
  2. Yes. Major surgery had a rate of 15.3% while minor surgery only had a rate of 6.7%
  3. Large was 13% while small was 10%
  4. Large hospitals delayed 15% when it was a major surgery and 5% when it was a minor surgery. Small hospitals delayed 20% when it was a major surgery and 8% when it was a minor surgery.
  5. No, with each surgery type smaller hospitals consistant delay discharges compared to large hospitals. Simpsons paradox is present.
  6. The small hospital primarily does minor surgeries, which consist of 83.3% of their surgeries, comapred to large hospitals, who primarily do large surgeries, which consist of 80% of their surgeries. Since minor surgeries do not delay as often, the small hospitals have the edge when it comes to releasing their patients on time.

Some graphs…

barplot(Hospitals, main = "Hospital discharges", col=c("darkblue","red"), beside = T)