Homework 3.3 Problem 31 Blood Pressure
Blood <- matrix(c(27,37,31,48,91,93,23,51,73),ncol=3,byrow=TRUE)
colnames(Blood) <- c("Under 30","30-49","Over 50")
rownames(Blood) <- c("Low","Normal","High")
Blood <- as.table(Blood)
Blood
## Under 30 30-49 Over 50
## Low 27 37 31
## Normal 48 91 93
## High 23 51 73
CrossTable from the gmodels package does all these at once.
library(gmodels)
as.data.frame.matrix(Blood)
## Under 30 30-49 Over 50
## Low 27 37 31
## Normal 48 91 93
## High 23 51 73
CrossTable(Blood, 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: 474
##
##
## |
## | Under 30 | 30-49 | Over 50 | Row Total |
## -------------|-----------|-----------|-----------|-----------|
## Low | 27 | 37 | 31 | 95 |
## | 2.757 | 0.035 | 1.823 | |
## | 0.284 | 0.389 | 0.326 | 0.200 |
## | 0.276 | 0.207 | 0.157 | |
## | 0.057 | 0.078 | 0.065 | |
## -------------|-----------|-----------|-----------|-----------|
## Normal | 48 | 91 | 93 | 232 |
## | 0.000 | 0.131 | 0.121 | |
## | 0.207 | 0.392 | 0.401 | 0.489 |
## | 0.490 | 0.508 | 0.472 | |
## | 0.101 | 0.192 | 0.196 | |
## -------------|-----------|-----------|-----------|-----------|
## High | 23 | 51 | 73 | 147 |
## | 1.798 | 0.367 | 2.320 | |
## | 0.156 | 0.347 | 0.497 | 0.310 |
## | 0.235 | 0.285 | 0.371 | |
## | 0.049 | 0.108 | 0.154 | |
## -------------|-----------|-----------|-----------|-----------|
## Column Total | 98 | 179 | 197 | 474 |
## | 0.207 | 0.378 | 0.416 | |
## -------------|-----------|-----------|-----------|-----------|
##
##
barplot(prop.table(Blood,2), main = "Blood pressure by age group", xlab = "age group", col=c("green","blue", "magenta"))