Exercise 4.2 The data set Abortion in vcdExtra gives a 2 × 2 × 2 table of opinions regarding abortion in relation to sex and status of the respondent.
library(vcd)
## Warning: package 'vcd' was built under R version 3.4.4
## Loading required package: grid
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"
(a) Taking support for abortion as the outcome variable, produce fourfold displays showing the association with sex, stratified by status.
fourfold(Abortion, c(3,1,2))

(b) Do the same for the association of support for abortion with status, stratified bysex.
fourfold(aperm(Abortion, c(3,1,2)))

(c) For each of the problems above, use oddsratio () to calculate the numerical values of the odds ratio, as stratified in the question.
oddsratio(Abortion, log=FALSE)
## odds ratios for Sex and Status by Support_Abortion
##
## Yes No
## 1.3614130 0.6338682
confint(oddsratio(Abortion, log=FALSE))
## 2.5 % 97.5 %
## Yes 0.9945685 1.8635675
## No 0.4373246 0.9187431
(d) Write a brief summary of how support for abortion depends on sex and status.
fourfold(Abortion, 3:1)

fourfold(aperm(Abortion, 3:1))

Exercise 4.4 The Hospital data in vcd gives a 3 × 3 table relating the length of stay (in years) of 132 long-term schizophrenic patients in two London mental hospitals with the frequency of visits by family and friends.
(a)Carry out a ??2 test for association between the two variables.
chisq.test(Hospital)
##
## Pearson's Chi-squared test
##
## data: Hospital
## X-squared = 35.171, df = 4, p-value = 4.284e-07
(b)Use assocstats () to compute association statistics. How would you describe the strength of association here?
assocstats(Hospital)
## X^2 df P(> X^2)
## Likelihood Ratio 38.353 4 9.4755e-08
## Pearson 35.171 4 4.2842e-07
##
## Phi-Coefficient : NA
## Contingency Coeff.: 0.459
## Cramer's V : 0.365
(c)Produce an association plot for these data, with visit frequency as the vertical variable. Describe the pattern of the relation you see here.
a <- t(Hospital)
assocplot(a)

(d)Both variables can be considered ordinal, so CMHtest () may be useful here. Carry out that analysis. Do any of the tests lead to different conclusions?
library(grid)
library(gnm)
## Warning: package 'gnm' was built under R version 3.4.4
library(vcdExtra)
## Warning: package 'vcdExtra' was built under R version 3.4.4
library(vcd)
CMHtest(Hospital)
## Cochran-Mantel-Haenszel Statistics for Visit frequency by Length of stay
##
## AltHypothesis Chisq Df Prob
## cor Nonzero correlation 29.138 1 6.7393e-08
## rmeans Row mean scores differ 34.391 2 3.4044e-08
## cmeans Col mean scores differ 29.607 2 3.7233e-07
## general General association 34.905 4 4.8596e-07
The p-value is inferior than 0.05, so the significance is important.
(a)Assess the strength of agreement between the raters using Cohen’s ??, both unweighted and weighted.
data(Mammograms)
Kappa(Mammograms)
## value ASE z Pr(>|z|)
## Unweighted 0.3713 0.06033 6.154 7.560e-10
## Weighted 0.5964 0.04923 12.114 8.901e-34
(b)Use agreementplot () for a graphical display of agreement here.
agreementplot(Mammograms,main= "agreementplot")

kappa(Mammograms)
## [1] 45.29604
assocstats(Mammograms)
## X^2 df P(> X^2)
## Likelihood Ratio 92.619 9 4.4409e-16
## Pearson 83.516 9 3.2307e-14
##
## Phi-Coefficient : NA
## Contingency Coeff.: 0.657
## Cramer's V : 0.503
(c)Compare the Kappa measures with the results from assocstats (). What is a reasonable interpretation of each of these measures
The unweighted Kappa value suggests a minimal agreement between rater1 and rater2.
The weighted Kappa value suggests a stronger agreement between rater1 and rater2, but the agreement is still weak.
The Likelihood ratio and Pearson Chi Square test suggests the two raters has different opinions on rating.
Exercise 4.7 Agresti and Winner (1997) gave the data in below on the ratings of 160 movies by the reviewers Gene Siskel and Roger Ebert for the period from April 1995 through September 1996. The rating categories were Con (“thumbs down”), Mixed, and Pro (“thumbs up”).
(a) Assess the strength of agreement between the raters using Cohen’s ??, both unweighted and weighted.
data <- matrix(c(24,8,13,8,13,11,10,9,64), nrow=3, ncol = 3, byrow = TRUE)
rownames(data) <- c("Con", "Mixed", "Pro")
colnames(data) <- c("Con", "Mixed", "Pro")
data
## Con Mixed Pro
## Con 24 8 13
## Mixed 8 13 11
## Pro 10 9 64
Kappa(data)
## 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 agreementplot () for a graphical display of agreement here.
agreementplot(data, main = "Unweighted", weights = 1)

agreementplot(data, main = "Weighted")
