Exercise 2.3 The data set UCBAdmissions is a 3-way table of frequencies classified by Admit, Gender, and Dept. (a) Find the total number of cases contained in this table.
data1 = UCBAdmissions
summary(data1)
## Number of cases in table: 4526
## Number of factors: 3
## Test for independence of all factors:
## Chisq = 2000.3, df = 16, p-value = 0
ftable(data1)
## Dept A B C D E F
## Admit Gender
## Admitted Male 512 353 120 138 53 22
## Female 89 17 202 131 94 24
## Rejected Male 313 207 205 279 138 351
## Female 19 8 391 244 299 317
prop.table(data1)
## , , Dept = A
##
## Gender
## Admit Male Female
## Admitted 0.113124171 0.019664163
## Rejected 0.069155988 0.004197967
##
## , , Dept = B
##
## Gender
## Admit Male Female
## Admitted 0.077993814 0.003756076
## Rejected 0.045735749 0.001767565
##
## , , Dept = C
##
## Gender
## Admit Male Female
## Admitted 0.026513478 0.044631021
## Rejected 0.045293858 0.086389748
##
## , , Dept = D
##
## Gender
## Admit Male Female
## Admitted 0.030490499 0.028943880
## Rejected 0.061643836 0.053910738
##
## , , Dept = E
##
## Gender
## Admit Male Female
## Admitted 0.011710119 0.020768891
## Rejected 0.030490499 0.066062749
##
## , , Dept = F
##
## Gender
## Admit Male Female
## Admitted 0.004860804 0.005302696
## Rejected 0.077551922 0.070039770
aperm(data1, c(3,2,1))
## , , 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
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. (a) 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
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
prop.table(UKSoccer)
## Away
## Home 0 1 2 3 4
## 0 0.071052632 0.076315789 0.026315789 0.021052632 0.005263158
## 1 0.155263158 0.139473684 0.036842105 0.031578947 0.010526316
## 2 0.073684211 0.084210526 0.036842105 0.031578947 0.010526316
## 3 0.050000000 0.036842105 0.018421053 0.010526316 0.002631579
## 4 0.018421053 0.021052632 0.026315789 0.005263158 0.000000000