library(vcd)
library(vcdExtra)

1 Exercise 4.3

1.1 Part A.

Make the Jobsat table.

data(JobSat)
JobSat
##         satisfaction
## income   VeryD LittleD ModerateS VeryS
##   < 15k      1       3        10     6
##   15-25k     2       3        10     7
##   25-40k     1       6        14    12
##   > 40k      0       1         9    11

1.2 Part B.

Carry out a standard X2 test for association between income and job satisfaction. Is there any indication that this test might not be appropriate? Repeat this test using a Monte Carlo test that does not depend on large sample size. Does this change your conclusion?

chisq.test(JobSat)
## Warning in chisq.test(JobSat): Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  JobSat
## X-squared = 5.9655, df = 9, p-value = 0.7434

The p value is more than 0.05 indicating that there is no association. However, we get a warning which indicates that the Chi-squared test might not be appropriate. This because the Pearson’s Chi-Squared test is valid only when most expected frequencies are greater than or equal to 5.

chisq.test(JobSat, simulate=TRUE)
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  JobSat
## X-squared = 5.9655, df = NA, p-value = 0.7446

The conclusion does not change as the p-value is still more than 0.05, indicating that there is no association.

1.3 Part C.

Both variables are ordinal, so CMH tests may be more powerful here. Carry out that analysis. What do you conclude?

CMHtest(JobSat)
## Cochran-Mantel-Haenszel Statistics for income by satisfaction 
## 
##                  AltHypothesis  Chisq Df     Prob
## cor        Nonzero correlation 2.9830  1 0.084144
## rmeans  Row mean scores differ 4.4774  3 0.214318
## cmeans  Col mean scores differ 3.1036  3 0.375931
## general    General association 5.9034  9 0.749549

The p-value of each of these tests is more than 0.05, indicating that there is no association.

2 Exercise 4.6

The two-way table Mammograms in vcdExtra gives ratings on the severity of diagnosis of 110 mammograms by two raters.

data("Mammograms")

2.1 Part A.

Assess the strength of agreement between the raters using Cohen’s ??, both unweighted and weighted.

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

2.2 Part B.

Use agreementplot() for a graphical display of agreement here.

agreementplot(Mammograms,main= "Unweighted", weights = 1)

agreementplot(Mammograms,main= "Weighted")

2.3 Part C.

Compare the Kappa measures with the results from assocstats(). What is a reasonable interpretation of each of these measures?

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

Kappa, by default, computes the 2-norm condition number of a matrix and assocstats 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. The unweighted Kappa value suggests a minimal agreement between rater 1 and rater 2, and the weighted Kappa value suggests a little stronger, but still weak agreement. The Likelihood ratio and the Pearson Chi-Square test also suggest the two raters have different opinions on rating.