library(vcdExtra)
data(Abortion, package="vcdExtra")
structable(Abortion)
## Status Lo Hi
## Sex Support_Abortion
## Female Yes 171 138
## No 79 112
## Male Yes 152 167
## No 148 133
Permuting the table dimensions gives different views
Abortion2<-aperm(Abortion, c(1,3,2))
fourfold(Abortion2)
Abortion3<-aperm(Abortion, c(2,3,1))
fourfold(Abortion3)
Sex by support for abortion, stratified by status
summary(oddsratio(Abortion2))
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## Lo 0.74555 0.17844 4.1781 2.94e-05 ***
## Hi -0.01889 0.17228 -0.1096 0.9127
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Status by support for abortion, stratified by sex
summary(oddsratio(Abortion3))
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## Female 0.56346 0.18623 3.0256 0.002481 **
## Male -0.20098 0.16384 -1.2267 0.219941
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Support for abortion differs by sex and status. Among low status individuals, there is a strong tendency for women to support it compared to men. There is no association between sex and support among men.
\(\chi^2\) test and association
str(Hospital)
## 'table' num [1:3, 1:3] 43 6 9 16 11 18 3 10 16
## - attr(*, "dimnames")=List of 2
## ..$ Visit frequency: chr [1:3] "Regular" "Less than monthly" "Never"
## ..$ Length of stay : chr [1:3] "2-9" "10-19" "20+"
chisq.test(Hospital)
##
## Pearson's Chi-squared test
##
## data: Hospital
## X-squared = 35.171, df = 4, p-value = 4.284e-07
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
There is a strong association between visit frequency and length of stay
The association plot shows that regular visits lead to shorter length of stay, never visiting to longer length of stay
assoc(Hospital, shade=TRUE)
All CMH tests are significant, but the test for non-zero correlation has the largest \(\chi^2 /df\) and the smallest p-value.
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
plot(Hospital, shade=TRUE)
tile(Hospital, shade=TRUE)
mosaic(Hospital, shade=TRUE)
spineplot(Hospital)
str(Mammograms)
## num [1:4, 1:4] 34 6 2 0 10 8 5 1 2 8 ...
## - attr(*, "dimnames")=List of 2
## ..$ Reader2: chr [1:4] "Absent" "Minimal" "Moderate" "Severe"
## ..$ Reader1: chr [1:4] "Absent" "Minimal" "Moderate" "Severe"
Mammograms
## Reader1
## Reader2 Absent Minimal Moderate Severe
## Absent 34 10 2 0
## Minimal 6 8 8 2
## Moderate 2 5 4 12
## Severe 0 1 2 14
The unweighted \(\kappa = 0.37\) is moderately strong, but the weighted versions, particularly using Fleiss-Cohen weights show very strong agreement, allowing for small steps of disagreement.
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
Kappa(Mammograms, weights= "Fleiss-Cohen")
## value ASE z Pr(>|z|)
## Unweighted 0.3713 0.06033 6.154 7.560e-10
## Weighted 0.7641 0.03996 19.122 1.667e-81
confint(Kappa(Mammograms))
##
## Kappa lwr upr
## Unweighted 0.2530339 0.4895358
## Weighted 0.4998809 0.6928576
The agreement plots illustrate the strength of agreement. There is no
tendency for the boxes to deviate systematically from the diagonal line,
indicating that the two readers use the diagnostic categories more or
less the same, except for the Severe
category.
agreementplot(Mammograms, main="Unweighted", weights=1)
agreementplot(Mammograms, main="Weighted")