Exercise 2.3 The dataset UCBAdmissions is a 3-way table of frequencies classified by Admit, Gender, and Department

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

Therefore, the 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

There are 933, 585,918,792,584 and 714 applicants for the departments A to F.

c.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

For department A, the admit percentage is 64.4% and rejection rate is 7.33%

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

For department C, the admit percentage is 35% and rejection rate is 64.9%

prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,4])
## [1] 0.3396465 0.6603535

For department D, the admit percentage is 39.9% and rejection rate is 66%

prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,5])
## [1] 0.2517123 0.7482877

For department E, the admit percentage is 25.17% and rejection rate is 74.8%

prop.table(ftable(UCBAdmissions,row.vars = "Admit",col.vars = "Dept")[,6])
## [1] 0.06442577 0.93557423

For department F, the admit percentage is 6.44% and rejection rate is 93.5%

  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.
tableA <- aperm(UCBAdmissions, c(3,2,1))
tableA
## , , 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
table1 <-tableA[,,"Admitted"]
table2 <-tableA[,,"Rejected"]
tableB <- table1/(table1+table2)
tableB
##     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 above table provide proportion of men who are admitted in each department. For department A, 62% male candidates and 82.4% female candidates. For department B, 63% male candidates and 68% female candidates For department C, 37% male candidates and 34% female candidates For department D, 33% male candidates and 35% female candidates For department E, 28% male candidates and 24% female candidates For department F, 5.8% male candidates and 7% female candidates

Exercise 2.5 The dataset 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

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
  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 for the home teams are 76,142,90,45, and 27 for 0,1,2,3,4+ respectively. Similarly, the marginal total for away teams are 140,136,55,38, and 11 for 0,1,2,3,4+ goals respectively.

  1. Express each of the margin 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

From this table, we can deduce that there is 30% chance that that home team makes 3 goals in its matches.