Chi-square test examines whether rows and columns of a contingency table are statistically significantly associated.
Null hypothesis (H0): the row and the column variables of the contingency table are independent.
Alternative hypothesis (H1): row and column variables are dependent
#>
#> good poor
#> placebo 127 158
#> treatment 172 98
#>
#> good poor
#> placebo TRUE TRUE
#> treatment TRUE TRUE
#>
#> Pearson's Chi-squared test with Yates' continuity correction
#>
#> data: tab
#> X-squared = 19.682, df = 1, p-value = 9.148e-06
If the calculated Chi-square statistic is greater than the critical value, then we must conclude that the row and the column variables are not independent of each other. This implies that they are significantly associated.
The chi-squared statistic (x-squared) is significantly higher than that of the critical value (p). The expected value for all variables was tested to be greater than 5 which is displayed as TRUE. We can therefore reject the null hypothesis with confidence there is significance. This evidence indicates a high level of dependence of patient status on treatment.
Figure 1. Patients under the treatment category have a higher proportion of recorded good status than that of patients under the placebo category
A relative risk or odds ratio greater than one indicates an event to be harmful, while a value less than one indicates a protective effect.
#> $data
#>
#> good poor Total
#> placebo 127 158 285
#> treatment 172 98 270
#> Total 299 256 555
#>
#> $measure
#> risk ratio with 95% C.I.
#> estimate lower upper
#> placebo 1.0000000 NA NA
#> treatment 0.6547117 0.5418409 0.7910945
#>
#> $p.value
#> two-sided
#> midp.exact fisher.exact chi.square
#> placebo NA NA NA
#> treatment 6.178541e-06 6.334767e-06 6.138238e-06
#>
#> $correction
#> [1] FALSE
#>
#> attr(,"method")
#> [1] "Unconditional MLE & normal approximation (Wald) CI"
#> $data
#>
#> good poor Total
#> placebo 127 158 285
#> treatment 172 98 270
#> Total 299 256 555
#>
#> $measure
#> odds ratio with 95% C.I.
#> estimate lower upper
#> placebo 1.0000000 NA NA
#> treatment 0.4588706 0.3255106 0.6443252
#>
#> $p.value
#> two-sided
#> midp.exact fisher.exact chi.square
#> placebo NA NA NA
#> treatment 6.178541e-06 6.334767e-06 6.138238e-06
#>
#> $correction
#> [1] FALSE
#>
#> attr(,"method")
#> [1] "median-unbiased estimate & mid-p exact CI"
Both indicate a ratio greater than one for the placebo groups and reports a ratio less than one for treatment groups. This indicates that the treatment had a “protective” effect on the patients.
ggplot(respiratory, aes(y = subject, x = treatment, colour = factor(status))) + geom_boxplot() + theme_classic() +
xlab("Treatment") + ylab("subject") + labs(colour = "Status")