Excercise 2.2 “UCB Admissions”

  1. Find total number of cases contained in this table:
UCBAdmissions_2 = as.data.frame(UCBAdmissions)
sum(UCBAdmissions_2$Freq)
## [1] 4526
  1. Find the total number o f applicants
margin.table(UCBAdmissions,3)
## Dept
##   A   B   C   D   E   F 
## 933 585 918 792 584 714

Matrix above shows the total number of applicants per department

  1. For each department, find the proportion of aplicants that were admitted
Admitted = xtabs(Freq~Dept+Admit,data = UCBAdmissions)
prop.table(Admitted)
##     Admit
## Dept   Admitted   Rejected
##    A 0.13278833 0.07335395
##    B 0.08174989 0.04750331
##    C 0.07114450 0.13168361
##    D 0.05943438 0.11555457
##    E 0.03247901 0.09655325
##    F 0.01016350 0.14759169

First column shows the proportion of admitted applicants

  1. Construct a table showing the proportion of applicants that were admitted (in each cell)
Admitted_Gender=xtabs(Freq~Dept+Gender+Admit,data = UCBAdmissions)
prop.table(Admitted_Gender)
## , , 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

The first matrix shows the proportion of aplicants that were admitted by Gender

Excercise 2.5 “UKSoccer”

  1. Verify the total number of games represented in this table
data("UKSoccer", package = "vcd")
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

the total number of games is equal to 380

  1. 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

The “Sum” colum and row of the above matrix shows the total number of goals at home and away separately

  1. Express each of the marginal totals as proportions
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

The matrix above shows the proportion of the marginal totals for home and away teams