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

data("UCBAdmissions",package="datasets")
View(UCBAdmissions)

To view the dataset first.

  1. Find the total number of cases contained in this table.
sum(UCBAdmissions)
## [1] 4526

Total number of cases is 4526.

  1. For each department, find the total number of applicants.
margin.table(UCBAdmissions,margin=3)
## Dept
##   A   B   C   D   E   F 
## 933 585 918 792 584 714

Total number of applicants is 933, 585, 918, 792, 584 and 714 for department A, B, C, D, E and F respectively.

  1. For each department, find the overall proportion of applicants who were admitted.
prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept"))
##          Dept          A          B          C          D          E          F
## Admit                                                                          
## Admitted      0.13278833 0.08174989 0.07114450 0.05943438 0.03247901 0.01016350
## Rejected      0.07335395 0.04750331 0.13168361 0.11555457 0.09655325 0.14759169
prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,1])
## [1] 0.6441586 0.3558414
prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,2])
## [1] 0.6324786 0.3675214
prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,3])
## [1] 0.3507625 0.6492375
prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,4])
## [1] 0.3396465 0.6603535
prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,5])
## [1] 0.2517123 0.7482877
prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,6])
## [1] 0.06442577 0.93557423

64%, 63%, 35%, 34%, 25% and 6% of the applicants were admitted for department A, B, C, D, E and F respectively.

  1. 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.
table1 <- aperm(UCBAdmissions,c(3,2,1))
table1
## , , Admit = Admitted
## 
##     Gender
## Dept Male Female
##    A  512     89
##    B  353     17
##    C  120    202
##    D  138    131
##    E   53     94
##    F   22     24
## 
## , , Admit = Rejected
## 
##     Gender
## Dept Male Female
##    A  313     19
##    B  207      8
##    C  205    391
##    D  279    244
##    E  138    299
##    F  351    317
tablea <- table1[,,"Admitted"]
tabler <- table1[,,"Rejected"]
table2 <- tablea/(tablea+tabler)
table2
##     Gender
## Dept       Male     Female
##    A 0.62060606 0.82407407
##    B 0.63035714 0.68000000
##    C 0.36923077 0.34064081
##    D 0.33093525 0.34933333
##    E 0.27748691 0.23918575
##    F 0.05898123 0.07038123

The proportion of male applicants who were admitted is 62%, 63%, 37%, 33%, 28% and 6% for department A, B, C, D, E and F. The proportion of female applicants who were admitted is 82%, 68%, 34%, 35%, 24% and 7% for department A, B, C, D, E and F.

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.

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

To view the dataset first.

  1. Verify that the total number of games represented in this table is 380.
sum(UKSoccer)
## [1] 380
  1. Find the marginal total of the number of goals scored by each of the home and away teams.
addmargins(UKSoccer)
##      Away
## Home    0   1   2   3   4 Sum
##   0    27  29  10   8   2  76
##   1    59  53  14  12   4 142
##   2    28  32  14  12   4  90
##   3    19  14   7   4   1  45
##   4     7   8  10   2   0  27
##   Sum 140 136  55  38  11 380

The marginal total is 76, 142, 90, 45 and 27 for Home 0, 1, 2, 3 and 4+ respectively, and 140, 136, 55, 38 and 11 for Away 0, 1, 2, 3 and 4+ respectively.

  1. Express each of the marginal totals as proportions.
prop.table(addmargins(UKSoccer))
##      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