Exercise 2.3 The data set UCBAdmissions is a 3-way table of frequencies classified by Admit, Gender, and Dept.

  1. Find the total number of cases contained in this table.
data.ucba=UCBAdmissions
summary(data.ucba)
## Number of cases in table: 4526 
## Number of factors: 3 
## Test for independence of all factors:
##  Chisq = 2000.3, df = 16, p-value = 0
  1. For each department, find the total number of applicants.
margin.table(data.ucba,3)
## Dept
##   A   B   C   D   E   F 
## 933 585 918 792 584 714

(c)For each department, find the overall proportion of applicants who were admitted.

data.c=data.ucba[,1,]+data.ucba[,2,]
prop.table(data.c[,1])
##  Admitted  Rejected 
## 0.6441586 0.3558414
prop.table(data.c[,2])
##  Admitted  Rejected 
## 0.6324786 0.3675214
prop.table(data.c[,3])
##  Admitted  Rejected 
## 0.3507625 0.6492375
prop.table(data.c[,4])
##  Admitted  Rejected 
## 0.3396465 0.6603535
prop.table(data.c[,5])
##  Admitted  Rejected 
## 0.2517123 0.7482877
prop.table(data.c[,6])
##   Admitted   Rejected 
## 0.06442577 0.93557423

(d)Construct a tabular display of department (rows) and gender (columns), showing the proportion of applicants in each cell who were admitted relative to the total applicants in that cell.

data.d=aperm(data.ucba,c(3,2,1))
prop.table(data.d)
## , , Admit = Admitted
## 
##     Gender
## Dept        Male      Female
##    A 0.113124171 0.019664163
##    B 0.077993814 0.003756076
##    C 0.026513478 0.044631021
##    D 0.030490499 0.028943880
##    E 0.011710119 0.020768891
##    F 0.004860804 0.005302696
## 
## , , Admit = Rejected
## 
##     Gender
## Dept        Male      Female
##    A 0.069155988 0.004197967
##    B 0.045735749 0.001767565
##    C 0.045293858 0.086389748
##    D 0.061643836 0.053910738
##    E 0.030490499 0.066062749
##    F 0.077551922 0.070039770

Exercise 2.5 The data set UKSoccer in vcd gives the distributions of number of goals scored by the 20 teams in the 1995/96 season of the Premier League of the UK Football Association. This two-way table classifies all 20 × 19 = 380 games by the joint outcome (Home, Away), the number of goals scored by the Home and Away teams. The value 4 in this table actually represents 4 or more goals.

  1. Verify that the total number of games represented in this table is 380.
data(UKSoccer,package="vcd")
ftable(UKSoccer)
##      Away  0  1  2  3  4
## Home                    
## 0         27 29 10  8  2
## 1         59 53 14 12  4
## 2         28 32 14 12  4
## 3         19 14  7  4  1
## 4          7  8 10  2  0
summary(UKSoccer)
## Number of cases in table: 380 
## Number of factors: 2 
## Test for independence of all factors:
##  Chisq = 18.699, df = 16, p-value = 0.2846
##  Chi-squared approximation may be incorrect

(b)Find the marginal total of the number of goals scored by each of the home and away teams.

data.uk=addmargins(UKSoccer)

(c)Express each of the marginal totals as proportions.

prop.table(data.uk)
##      Away
## Home             0            1            2            3            4
##   0   0.0177631579 0.0190789474 0.0065789474 0.0052631579 0.0013157895
##   1   0.0388157895 0.0348684211 0.0092105263 0.0078947368 0.0026315789
##   2   0.0184210526 0.0210526316 0.0092105263 0.0078947368 0.0026315789
##   3   0.0125000000 0.0092105263 0.0046052632 0.0026315789 0.0006578947
##   4   0.0046052632 0.0052631579 0.0065789474 0.0013157895 0.0000000000
##   Sum 0.0921052632 0.0894736842 0.0361842105 0.0250000000 0.0072368421
##      Away
## Home           Sum
##   0   0.0500000000
##   1   0.0934210526
##   2   0.0592105263
##   3   0.0296052632
##   4   0.0177631579
##   Sum 0.2500000000