Produce a contingency table from the values of two or more WALS features.
contingency_table(ids, names = TRUE, absolute = TRUE, data = WALS)
ids | Vector of feature IDs |
---|---|
names | Boolean; should the output use prose value descriptions? If |
absolute | Boolean; should the output be in the form of absolute frequencies? If |
data | Optionally a data frame, e.g. a subset of |
An n-by-n contingency table, where n is the length of ids
This function calls intersect_features
internally to establish the database intersection based on which a contingency table may be created.
# 2x2 contingency table (absolute frequencies) of the first two features: tab <- contingency_table(c("1A", "2A")) # Run a chi-square test on the above: chisq.test(tab)#> #> Pearson's Chi-squared test #> #> data: tab #> X-squared = 959.41, df = 8, p-value < 2.2e-16 #># 3x3 contingency table of the first three features, showing relative # frequencies and value IDs instead of value descriptions: contingency_table(c("1A", "2A", "3A"), names=FALSE, absolute=FALSE)#> , , 3A 20 = 1 #> #> 2A 187 #> 1A 19 1 2 3 #> 1 0.103571429 0.000000000 0.000000000 #> 2 0.000000000 0.000000000 0.000000000 #> 3 0.000000000 0.000000000 0.000000000 #> 4 0.000000000 0.000000000 0.000000000 #> 5 0.000000000 0.000000000 0.000000000 #> #> , , 3A 20 = 2 #> #> 2A 187 #> 1A 19 1 2 3 #> 1 0.055357143 0.000000000 0.000000000 #> 2 0.003571429 0.119642857 0.000000000 #> 3 0.000000000 0.000000000 0.000000000 #> 4 0.000000000 0.000000000 0.000000000 #> 5 0.000000000 0.000000000 0.000000000 #> #> , , 3A 20 = 3 #> #> 2A 187 #> 1A 19 1 2 3 #> 1 0.000000000 0.000000000 0.000000000 #> 2 0.000000000 0.094642857 0.000000000 #> 3 0.000000000 0.294642857 0.028571429 #> 4 0.000000000 0.000000000 0.000000000 #> 5 0.000000000 0.000000000 0.000000000 #> #> , , 3A 20 = 4 #> #> 2A 187 #> 1A 19 1 2 3 #> 1 0.000000000 0.000000000 0.000000000 #> 2 0.000000000 0.000000000 0.000000000 #> 3 0.000000000 0.000000000 0.033928571 #> 4 0.000000000 0.000000000 0.146428571 #> 5 0.000000000 0.000000000 0.000000000 #> #> , , 3A 20 = 5 #> #> 2A 187 #> 1A 19 1 2 3 #> 1 0.000000000 0.000000000 0.000000000 #> 2 0.000000000 0.000000000 0.000000000 #> 3 0.000000000 0.000000000 0.000000000 #> 4 0.000000000 0.000000000 0.019642857 #> 5 0.000000000 0.000000000 0.100000000 #>