install.packages(“vcd”) library(“vcd”)

Part I

Original data format

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
  1. Find the total number of cases contained in this table.
sum(UCBAdmissions)
## [1] 4526
  1. For each department, find the total number of applicants.
colSums(UCBAdmissions, dims = 2)
##   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.
round(prop.table(margin.table(UCBAdmissions,c(1,3)),2),4)
##           Dept
## Admit           A      B      C      D      E      F
##   Admitted 0.6442 0.6325 0.3508 0.3396 0.2517 0.0644
##   Rejected 0.3558 0.3675 0.6492 0.6604 0.7483 0.9356
  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.
ftable(round(prop.table(UCBAdmissions,c(2,3)),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

Part II

data(UKSoccer, package="vcd")
  1. Verify that the total number of games represented in this table is 380.
sum(UKSoccer)
## [1] 380
  1. Find the marginal total of the number of goals scored by each of the home and away teams.
UKSoccerNew<-addmargins(UKSoccer)
UKSoccerNew
##      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

Home Total Goals:

76*0+142*1+90*2+45*3+27*4
## [1] 565

Away Total Goals:

140*0+136*1+55*2+38*3+11*4
## [1] 404
  1. Express each of the marginal totals as proportions.

Overall goals total:

565+404
## [1] 969

Home Marginal Total Proportion:

round(565/(565+404),2)
## [1] 0.58

Away Marginal Total Proportion:

round(404/(565+404),2)
## [1] 0.42