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
margin.table(data1, 3)
## Dept
## A B C D E F
## 933 585 918 792 584 714
data2 = data1[,1,] + data1[,2,]
prop.table(data2[,1])
## Admitted Rejected
## 0.6441586 0.3558414
prop.table(data2[,2])
## Admitted Rejected
## 0.6324786 0.3675214
prop.table(data2[,3])
## Admitted Rejected
## 0.3507625 0.6492375
prop.table(data2[,4])
## Admitted Rejected
## 0.3396465 0.6603535
prop.table(data2[,5])
## Admitted Rejected
## 0.2517123 0.7482877
prop.table(data2[,6])
## Admitted Rejected
## 0.06442577 0.93557423
data3 = aperm(data1, c(3,2,1))
prop.table(data3)
## , , 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. (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
data6 = addmargins(UKSoccer)
data6
## 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(data6)
## 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