Exercise 4.2 (a) Taking support for abortion as the outcome variable, produce fourfold displays showing the association with sex, stratified by status. (b) Do the same for the association of support for abortion with status, stratified bysex.
library("vcdExtra")
## Loading required package: vcd
## Warning: package 'vcd' was built under R version 3.4.3
## Loading required package: grid
## Loading required package: gnm
## Warning: package 'gnm' was built under R version 3.4.4
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"
fourfold(Abortion,c(3,1,2))

fourfold(aperm(Abortion,c(3,1,2)))

Exercise 4.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 = F)
## odds ratios for Sex and Status by Support_Abortion
##
## Yes No
## 1.3614130 0.6338682
oddsratio(aperm(Abortion,log = F))
## log odds ratios for Support_Abortion and Status by Sex
##
## Female Male
## 0.5634609 -0.2009764
Exercise 4.2 (d) Write a brief summary of how support for abortion depends on sex and status.
Ans: - From the fourfold plot above and by analyzing the data separetely using odds ratio, it can be cseen that generally males support abortion when the status is high and women support abortion when the status is low.
Exercise 4.4 (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
Exercise 4.4 (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
Exercise 4.4 (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)

Exercise 4.4(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)
library(vcdExtra)
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
Ans:- p-value is less than 0.05, so we can conclude that the relation holds true.
Exercise 4.6 The two-way table Mammograms in vcdExtra gives ratings on the severity of diagnosis of 110 mammograms by two raters. (a)Assess the strength of agreement between the raters using Cohen’s κ, both unweighted and weighted. (b)Use agreementplot () for a graphical display of agreement here.
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
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
Exercise 4.6 (c)Compare the Kappa measures with the results from assocstats (). What is a reasonable interpretation of each of these measures
Ans: - By default, Kappa() computes the 2-norm condition number of a matrix and R matrix computes the Pearson chi-Squared test, the Likelihood Ratio chi-Squared test, the phi coefficient, the contingency coefficient and Cramer’s V for possibly stratified contingency tables.
Exercise 4.7 (a) Assess the strength of agreement between the raters using Cohen’s κ, both unweighted and weighted.
ratings = matrix(c(24,8,13,8,13,11,10,9,64),ncol=3,byrow=TRUE)
rownames(ratings) = c("Con","Mixed","Pro")
colnames(ratings) = c("Con","Mixed","Pro")
addmargins(ratings)
## 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(ratings)
## 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
Exercise 4.7 (b) Use agreementplot () for a graphical display of agreement here.
agreementplot(ratings, main="Unweighted")

agreementplot(ratings, main="Weighted")
