3. In larger contingency tables (at least one categorical variable
has more than two categories), up to 20% of the expected frequencies can
be between 1 and 5, but this will reduce the power of the test. (doesnt
apply for 2x2 contigency tables - also my case)
results <- chisq.test(mydata2$SexFactor, mydata2$ConditionFactor,
correct = TRUE)
results
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mydata2$SexFactor and mydata2$ConditionFactor
## X-squared = 21.852, df = 1, p-value = 2.946e-06
BSD we reject null hypothesis (p<0.001) and conclude that there
is association between categorical variables sex and condition.
addmargins(results$observed) #empirical frequencies
## mydata2$ConditionFactor
## mydata2$SexFactor No_Disease Disease Sum
## Female 71 25 96
## Male 89 112 201
## Sum 160 137 297
round(results$expected, 2) #expected frequencies
## mydata2$ConditionFactor
## mydata2$SexFactor No_Disease Disease
## Female 51.72 44.28
## Male 108.28 92.72
Here we have to check that all expected frequencies are greater than
5. Since all are greater than 5,we can confirm our assumption is
met.
round(results$res, 2)
## mydata2$ConditionFactor
## mydata2$SexFactor No_Disease Disease
## Female 2.68 -2.90
## Male -1.85 2.00
There is more than expected number of patients in category female
and no disease (a= 0.01)
There is less than expected number of patients in category female
and disease (a = 0.01).
There is more than expected number of patients in category male and
disease (a = 0.05)
Difference for category male and no disease is statistically not
significant.
addmargins(round(prop.table(results$observed), 3))
## mydata2$ConditionFactor
## mydata2$SexFactor No_Disease Disease Sum
## Female 0.239 0.084 0.323
## Male 0.300 0.377 0.677
## Sum 0.539 0.461 1.000
Interpretation:
Out of 297 patients, there is 23.9% of them female and without
disease. There is 30% of them male and without disease. There is 8,4%
female with disease and 37.7% male with disease. There is 53.9% of all
patients without disease and 46.1% of all patients with disease.
addmargins(round(prop.table(results$observed, 1), 3), 2)
## mydata2$ConditionFactor
## mydata2$SexFactor No_Disease Disease Sum
## Female 0.740 0.260 1.000
## Male 0.443 0.557 1.000
Interpretation:
26% of all female have disease and 74% of female do not have
disease. 55.7% of all men have disease and 44.3% of men do not have
disese.
addmargins(round(prop.table(results$observed, 2), 3), 1)
## mydata2$ConditionFactor
## mydata2$SexFactor No_Disease Disease
## Female 0.444 0.182
## Male 0.556 0.818
## Sum 1.000 1.000
Interpretation:
out of all patients that have disease, only 18.2% are female and
81.8% are male. Out of all people without disease 44.4% are female and
55.6% are male.
library(effectsize)
##
## Attaching package: 'effectsize'
## The following object is masked from 'package:psych':
##
## phi
effectsize::cramers_v(mydata2$SexFactor, mydata2$ConditionFactor)
## Cramer's V (adj.) | 95% CI
## --------------------------------
## 0.27 | [0.17, 1.00]
##
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.27)
## [1] "medium"
## (Rules: funder2019)
BSD we can conclude that there is association between categorical
variables gender and condition and the effect is medium.