-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson20-crosstabs-crosstable-gmodels.R
47 lines (27 loc) · 1.37 KB
/
lesson20-crosstabs-crosstable-gmodels.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
demo <- read.csv("demographics.csv")
View(demo)
##########
### how to create cross-tables
### with the CrossTable function (package gmodels)
##########
### we will build a cross table with the variables gender and carcat (car category)
### load the package
require(gmodels)
CrossTable(demo$gender, demo$carcat, prop.chisq = FALSE) ### we don't want the chi square contributions
### some other options of the CrossTable function
CrossTable(demo$gender, demo$carcat, digits=3, expected=TRUE, prop.r=TRUE, prop.c=TRUE,
prop.t=TRUE, prop.chisq=TRUE, chisq = FALSE, fisher=FALSE, mcnemar=FALSE,
missing.include=FALSE)
### digits: number of decimals
### expected: shows the expected frequencies
### prop.r: shows the row proportions
### prop.c: shows the column proportions
### prop.chisq: shows the chi square contributions
### chisq: computes the chi square test for association
### fisher: computes the Fisher exact test
### mcnemar: computes the McNemar test (for the 2x2 tables only)
### missing.include: if TRUE removes the unused factor levels
### this table will show the observed counts only
CrossTable(demo$gender, demo$carcat, digits=3, expected=FALSE, prop.r=FALSE, prop.c=FALSE,
prop.t=FALSE, prop.chisq=FALSE, chisq = FALSE, fisher=FALSE, mcnemar=FALSE,
missing.include=FALSE)