Chapter 3, Displaying and Describing Catagorical Data

Homework 3.3 Problem 32

Obesity <- matrix(c(23.8,26,35.6,27.8,28.7,28.1,31.6,31.1,27.2,16.8,14.2,9.1),ncol=3,byrow=TRUE)
colnames(Obesity) <- c("Normal %","Overweight %","Obese %")

rownames(Obesity) <- c("Inactive","Irregularly active","Regular not intense","Regular intense")
Obesity <- as.table(Obesity)
Obesity
##                     Normal % Overweight % Obese %
## Inactive                23.8         26.0    35.6
## Irregularly active      27.8         28.7    28.1
## Regular not intense     31.6         31.1    27.2
## Regular intense         16.8         14.2     9.1

CrossTable from the gmodels package does all these at once.

library(gmodels)
as.data.frame.matrix(Obesity)
##                     Normal % Overweight % Obese %
## Inactive                23.8         26.0    35.6
## Irregularly active      27.8         28.7    28.1
## Regular not intense     31.6         31.1    27.2
## Regular intense         16.8         14.2     9.1
CrossTable(Obesity, 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:  300 
## 
##  
##                     |  
##                     |     Normal % | Overweight % |      Obese % |    Row Total | 
## --------------------|--------------|--------------|--------------|--------------|
##            Inactive |           23 |           26 |           35 |           85 | 
##                     |        0.765 |        0.214 |        1.788 |              | 
##                     |        0.279 |        0.304 |        0.417 |        0.285 | 
##                     |        0.238 |        0.260 |        0.356 |              | 
##                     |        0.079 |        0.087 |        0.119 |              | 
## --------------------|--------------|--------------|--------------|--------------|
##  Irregularly active |           27 |           28 |           28 |           84 | 
##                     |        0.006 |        0.009 |        0.000 |              | 
##                     |        0.329 |        0.339 |        0.332 |        0.282 | 
##                     |        0.278 |        0.287 |        0.281 |              | 
##                     |        0.093 |        0.096 |        0.094 |              | 
## --------------------|--------------|--------------|--------------|--------------|
## Regular not intense |           31 |           31 |           27 |           89 | 
##                     |        0.089 |        0.043 |        0.255 |              | 
##                     |        0.352 |        0.346 |        0.303 |        0.300 | 
##                     |        0.316 |        0.311 |        0.272 |              | 
##                     |        0.105 |        0.104 |        0.091 |              | 
## --------------------|--------------|--------------|--------------|--------------|
##     Regular intense |           16 |           14 |            9 |           40 | 
##                     |        0.882 |        0.052 |        1.362 |              | 
##                     |        0.419 |        0.354 |        0.227 |        0.134 | 
##                     |        0.168 |        0.142 |        0.091 |              | 
##                     |        0.056 |        0.047 |        0.030 |              | 
## --------------------|--------------|--------------|--------------|--------------|
##        Column Total |          100 |          100 |          100 |          300 | 
##                     |        0.333 |        0.333 |        0.333 |              | 
## --------------------|--------------|--------------|--------------|--------------|
## 
## 
  1. Column percentages
  2. below
  3. Yes, these studies show a clear correlation that the less you exersise, the more likely you are to be obese.

Some graphs…

Y axis is physical activity in the order from bottom to top since i couldn’t figure out how to add y axis labels!! A. Inactive B. Irregularly active C. Regular, not intense D. Regular, intense

barplot(Obesity, main = "Body mass index", xlab = "Physical activity", col=c("blue","green","yellow","magenta"))