Find the total number of cases contained in this table
data("UCBAdmissions")
summary(UCBAdmissions)
## Number of cases in table: 4526
## Number of factors: 3
## Test for independence of all factors:
## Chisq = 2000.3, df = 16, p-value = 0
sum(UCBAdmissions)
## [1] 4526
For each department, find the total number of applicants
ftable(UCBAdmissions, row.vars = 3:3)
## Admit Admitted Rejected
## Gender Male Female Male Female
## Dept
## A 512 89 313 19
## B 353 17 207 8
## C 120 202 205 391
## D 138 131 279 244
## E 53 94 138 299
## F 22 24 351 317
For each department, find the overall proportion of applicants who were admitted
prop.table(ftable(UCBAdmissions, row.vars = 3:3))
## Admit Admitted Rejected
## Gender Male Female Male Female
## Dept
## A 0.113124171 0.019664163 0.069155988 0.004197967
## B 0.077993814 0.003756076 0.045735749 0.001767565
## C 0.026513478 0.044631021 0.045293858 0.086389748
## D 0.030490499 0.028943880 0.061643836 0.053910738
## E 0.011710119 0.020768891 0.030490499 0.066062749
## F 0.004860804 0.005302696 0.077551922 0.070039770
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
aperm(UCBAdmissions, 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
aperm(UCBAdmissions, 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
aperm(apply(UCBAdmissions,c(1,3),sum))
## Admit
## Dept Admitted Rejected
## A 601 332
## B 370 215
## C 322 596
## D 269 523
## E 147 437
## F 46 668
library(vcd)
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
Verify that the total number of games represented in this table is 380
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
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
Express each of the marginal totals as proportions
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