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("UCBAdmissions", package = "datasets")
sum(UCBAdmissions)
## [1] 4526
  1. For each department, find the total number of applicants.
margin.table(UCBAdmissions,3)
## Dept
##   A   B   C   D   E   F 
## 933 585 918 792 584 714
  1. For each department, find the overall proportion of applicants who were admitted.
mytable <- margin.table(UCBAdmissions, c(1,3))
prop.table(mytable,2)
##           Dept
## Admit               A          B          C          D          E
##   Admitted 0.64415863 0.63247863 0.35076253 0.33964646 0.25171233
##   Rejected 0.35584137 0.36752137 0.64923747 0.66035354 0.74828767
##           Dept
## Admit               F
##   Admitted 0.06442577
##   Rejected 0.93557423
  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.
admit <- UCBAdmissions[1,,]
reject <- UCBAdmissions[2,,]
admit/(admit+reject)
##         Dept
## Gender            A          B          C          D          E          F
##   Male   0.62060606 0.63035714 0.36923077 0.33093525 0.27748691 0.05898123
##   Female 0.82407407 0.68000000 0.34064081 0.34933333 0.23918575 0.07038123

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.

  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
sum(UKSoccer)
## [1] 380
  1. Find the marginal total of the number of goals scored by each of the home and away teams.
homedata <- margin.table(UKSoccer,1)
homedata
## Home
##   0   1   2   3   4 
##  76 142  90  45  27
awaydata <- margin.table(UKSoccer,2)
awaydata
## Away
##   0   1   2   3   4 
## 140 136  55  38  11
  1. Express each of the marginal totals as proportions.
prop.table(homedata)
## Home
##          0          1          2          3          4 
## 0.20000000 0.37368421 0.23684211 0.11842105 0.07105263
prop.table(awaydata)
## Away
##          0          1          2          3          4 
## 0.36842105 0.35789474 0.14473684 0.10000000 0.02894737
  1. Comment on the distribution of the numbers of home-team and away-team goals. Is there any evidence that home teams score more goals on average?

Home teams have a better chance of scoring (1,2,3,4), and away teams have a higher chance of not scoring (0).