UCBAdmissions
## , , Dept = A
##
## Gender
## Admit Male Female
## Admitted 512 89
## Rejected 313 19
##
## , , Dept = B
##
## Gender
## Admit Male Female
## Admitted 353 17
## Rejected 207 8
##
## , , Dept = C
##
## Gender
## Admit Male Female
## Admitted 120 202
## Rejected 205 391
##
## , , Dept = D
##
## Gender
## Admit Male Female
## Admitted 138 131
## Rejected 279 244
##
## , , Dept = E
##
## Gender
## Admit Male Female
## Admitted 53 94
## Rejected 138 299
##
## , , Dept = F
##
## Gender
## Admit Male Female
## Admitted 22 24
## Rejected 351 317
Exercise 2.3 (a) Find the total number of cases contained in this table.
data= UCBAdmissions
summary(data)
## 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(UCBAdmissions, row.vars="Dept", col.vars = c( "Admit"))
## Admit Admitted Rejected
## Dept
## A 601 332
## B 370 215
## C 322 596
## D 269 523
## E 147 437
## F 46 668
prop.table(margin.table(UCBAdmissions,c(1,3)), 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
propt=prop.table(UCBAdmissions, c(2,3))
ftable(round(propt, 2), row.vars="Dept", col.vars = c("Gender", "Admit"))
## Gender Male Female
## Admit Admitted Rejected Admitted Rejected
## Dept
## A 0.62 0.38 0.82 0.18
## B 0.63 0.37 0.68 0.32
## C 0.37 0.63 0.34 0.66
## D 0.33 0.67 0.35 0.65
## E 0.28 0.72 0.24 0.76
## F 0.06 0.94 0.07 0.93
Exercise 2.5 (a) Verify that the total number of games represented in this table is 380.
install.packages("vcd",repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/xj/tl6pm98x5qb3b_94_pxtg29h0000gn/T//RtmpfmFCjV/downloaded_packages
library(vcd)
## Loading required package: grid
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(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