library(vcdExtra)
## Warning: package 'vcdExtra' was built under R version 3.3.3
## Loading required package: vcd
## Warning: package 'vcd' was built under R version 3.3.3
## Loading required package: grid
## Loading required package: gnm
## Warning: package 'gnm' was built under R version 3.3.3
Exercise 4.2.
data("Abortion")
str(Abortion)
## table [1:2, 1:2, 1:2] 171 152 138 167 79 148 112 133
## - attr(*, "dimnames")=List of 3
## ..$ Sex : chr [1:2] "Female" "Male"
## ..$ Status : chr [1:2] "Lo" "Hi"
## ..$ Support_Abortion: chr [1:2] "Yes" "No"
ftable(Abortion, Sex~Support)
## Support_Abortion Yes No
## Sex Status
## Female Lo 171 79
## Hi 138 112
## Male Lo 152 148
## Hi 167 133
(a) Taking support for abortion as the outcome (response) variable, produce fourfold displays showing the association with sex, stratified by status.
Abortion2 <-aperm(Abortion, c(1,3,2))
fourfold(Abortion2)

(b) Do the same for the association of support for abortion with status, stratified by sex
Abortion3<-aperm(Abortion, c(2,3,1))
fourfold(Abortion3)

(c) For each of the problems above, use oddsratio() to calculate the numerical values of the odds ratio, as stratified in the question.
loddsratio(Abortion2, log = FALSE)
## odds ratios for Sex and Support_Abortion by Status
##
## Lo Hi
## 2.1075949 0.9812874
loddsratio(Abortion3, log = FALSE)
## odds ratios for Status and Support_Abortion by Sex
##
## Female Male
## 1.7567419 0.8179317
(d) Write a brief summary of how support for abortion depends on sex
and status.
We note that in (a) above, where support for abortion and sex are stratified by status, the odds ratio indicates that Support for Abortion is greater for Low Status. However, there is an association between Support for Abortion and Status. It seems people of low status support abortion.
We note that in (b) above, where support for abortion and status are stratified by sex, it seems Females of Low Status support abortion more so than that of Females of High Status. Also, the Males show independence with respect to the association of support for abortion with status, stratified by sex.
Exercise 4.7.
Below we have reproduced the Agresti and Winner table of the Siskel and Ebert ratings:
##> data
## X X.1 Ebert X.2 X.3 X.4
##1 Con Mixed Pro Total:
##2 Con 24 8 13 45
##3 Siskel Mixed 8 13 11 32
##4 Pro 10 9 64 83
##5 Total: 42 30 88 160
(a) Assess the strength of agreement between the raters using Cohen’s K, both unweighted and weighted.
library(vcd)
Below, we convert our data into a standard matrix only of numbers:
SE <- matrix(c(24,8,10,8,13,9,13,11,64), ncol = 3, byrow = TRUE)
SE
## [,1] [,2] [,3]
## [1,] 24 8 10
## [2,] 8 13 9
## [3,] 13 11 64
Let’s equate our variables for the above matrix:
Observations: [1,] = Con, [2,] = Mixed, [3,] = Pro
variables: [,1] = Con, [,2] = Mixed, [,3] = Pro
Kappa(SE)
## value ASE z Pr(>|z|)
## Unweighted 0.3888 0.05979 6.503 7.870e-11
## Weighted 0.4269 0.06350 6.723 1.781e-11
(b) Use the agreementplot() function for a graphical display of agreement here.
agreementplot(SE, main = "Siskel and Ebert", xlab = "Ebert", ylab = "Siskel")

In the agreement (weighted) chart above, going from left to right, we have the following categories:
first rectangle: the Con x Con rectangle (Con)
second rectangle: the Mixed x Mixed rectangle (Con)
third rectangle: the Pro x Pro rectangle (Pro)
We see that Siskel and Ebert more often agree in the extreme categories of “Con” and “Pro.”
The black squares show observed agreement. Although we do not have perfect agreement in the three cases, we see there is more agreement (larger black areas), as we mentioned earlier, in the extreme categories of “Con” and “Pro.”
confint(Kappa(SE))
##
## Kappa lwr upr
## Unweighted 0.2716461 0.5060309
## Weighted 0.3024256 0.5513224
summary(Kappa(SE))
## value ASE z Pr(>|z|)
## Unweighted 0.3888 0.05979 6.503 7.870e-11
## Weighted 0.4269 0.06350 6.723 1.781e-11
##
## Weights:
## [,1] [,2] [,3]
## [1,] 1.0 0.5 0.0
## [2,] 0.5 1.0 0.5
## [3,] 0.0 0.5 1.0