R voor SAS-gebruikers
Melinda Higgins, PhD
Research Professor/Senior Biostatistician Emory University
# Gebruik table() binnen with() voor bmicat
daviskeep %>% with(table(bmicat))
bmicat
1. underwt/norm 2. overwt 3. obese
161 35 3
Gecodeerde variabele bmigt25 toevoegen
# Voeg één categorische variabele toe: bmigt25
daviskeep <- daviskeep %>%
mutate(bmigt25 = ifelse(bmi > 25,
"2. overwt/obese",
"1. underwt/norm"))
# Bekijk frequenties voor bmigt25-categorieën
daviskeep %>% with(table(bmigt25))
bmigt25
1. underwt/norm 2. overwt/obese
161 38


# Sla tabeluitvoer van bmigt25 per sex op
tablebmisex <- daviskeep %>%
with(table(bmigt25, sex))
tablebmisex
# Gebruik de tabel voor chisq.test
chisq.test(tablebmisex)
sex
bmigt25 F M
1. underwt/norm 107 54
2. overwt/obese 4 34
Pearson chi-kwadraattoets met Yates'
continuïteitscorrectie
data: tablebmisex
X-squared = 36.759, df = 1, p-waarde = 1.336e-09
# Laad gmodels-package
library(gmodels)
# Voer gmodels::CrossTabs uit, toon kolom-% en verwachte waarden
daviskeep %>%
with(gmodels::CrossTable(bmigt25, sex,
chisq = TRUE,
prop.r = FALSE,
prop.t = FALSE,
prop.chisq = FALSE,
expected = TRUE))
Celinhoud
|-------------------------|
| N |
| Verwachte N |
| N / Kolomtotaal |
|-------------------------|
Totaal waarnemingen in tabel: 199
| sex
bmigt25 | F | M | Rijtotaal |
----------------|-----------|-----------|-----------|
1. underwt/norm | 107 | 54 | 161 |
| 89.804 | 71.196 | |
| 0.964 | 0.614 | |
----------------|-----------|-----------|-----------|
2. overwt/obese | 4 | 34 | 38 |
| 21.196 | 16.804 | |
| 0.036 | 0.386 | |
----------------|-----------|-----------|-----------|
Kolomtotaal | 111 | 88 | 199 |
| 0.558 | 0.442 | |
----------------|-----------|-----------|-----------|
gmodels::CrossTable()-uitvoer - vervolg...
Statistieken voor alle tabelvariabelen
Pearson chi-kwadraattoets
------------------------------------------------------------
Chi^2 = 38.99402 v.f. = 1 p = 4.251066e-10
Pearson chi-kwadraat met Yates-continuïteitscorrectie
------------------------------------------------------------
Chi^2 = 36.75936 v.f. = 1 p = 1.336475e-09

# Maak mozaïekplot van bmigt25 per sex
mosaicplot(bmigt25 ~ sex,
data = daviskeep,
color = c("light blue",
"dark grey"),
main =
"BMI-categorieën per geslacht")

R voor SAS-gebruikers