Exercise 4.2
options(repos="https://cran.rstudio.com")
install.packages("vcd")
##
## The downloaded binary packages are in
## /var/folders/xj/tl6pm98x5qb3b_94_pxtg29h0000gn/T//Rtmp2LPoas/downloaded_packages
library(vcd)
## Loading required package: grid
install.packages('vcdExtra')
##
## The downloaded binary packages are in
## /var/folders/xj/tl6pm98x5qb3b_94_pxtg29h0000gn/T//Rtmp2LPoas/downloaded_packages
library(vcdExtra)
## Loading required package: gnm
data("Abortion",package ="vcdExtra")
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"
fourfold(aperm(Abortion, c(3, 1, 2)))
(b) Do the same for the association of support for abortion with status, stratified by sex.
fourfold(aperm(Abortion, c(3, 2, 1 )))
(c) For each of the problems above, use oddsratio () to calculate the numerical values of the odds ratio, as stratified in the question.
oddsratio(aperm(Abortion, c(3, 1,2 )))
## log odds ratios for Support_Abortion and Sex by Status
##
## Lo Hi
## 0.74554746 -0.01888987
oddsratio(aperm(Abortion, c(3, 2, 1 )))
## log odds ratios for Support_Abortion and Status by Sex
##
## Female Male
## 0.5634609 -0.2009764
In low status, women tend to suport abortion more than men. While in high status, men tend to support abortion more than women.
Exercise 4.7
movies = matrix(c(24,8,13,8,13,11,10,9,64),ncol=3,byrow=TRUE)
colnames(movies) = c("Con","Mixed","Pro")
rownames(movies) = c("Con","Mixed","Pro")
movies = as.table(movies)
addmargins(movies)
## Con Mixed Pro Sum
## Con 24 8 13 45
## Mixed 8 13 11 32
## Pro 10 9 64 83
## Sum 42 30 88 160
Kappa(movies)
## 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
agreementplot(movies, main="Unweighted")
agreementplot(movies, main="Weighted")