cont_table {descstat} | R Documentation |
Contingency table
Description
A contingency table returns the counts of all the combinations of
the modalities of two series in a table for which every modality of
the first series is a row and every modality of the second series
is a column. The joint
, marginal
and conditional
functions
compute these three distributions from the contingency table (by
indicating one series for the last two).
Usage
cont_table(
data,
x1,
x2,
weights = NULL,
freq = NULL,
total = FALSE,
xfirst1 = NULL,
xlast1 = NULL,
wlast1 = NULL,
xfirst2 = NULL,
xlast2 = NULL,
wlast2 = NULL
)
joint(data)
conditional(data, x = NULL)
marginal(data, x = NULL, f = "f", vals = NULL)
Arguments
data |
a tibble, |
x1 , x2 |
the two series used the construct the contingency table, the distinct values of the first and the second will respectively be the rows and the columns of the contingency table, |
weights |
a series containing the weights that should be used to mimic the population, |
freq |
the frequencies (in the case where data is already contingency table), |
total |
if |
xfirst1 , xfirst2 , xlast1 , xlast2 , wlast1 , wlast2 |
see |
x |
the series on which the operation should be computed, |
f |
see |
vals |
see |
Details
cont_table
actually returns a tibble in "long format", as the
dplyr::count
table does. As the returned object is of class
cont_table
, this is the format
and print
methods that turns
the tibble in a wide format before printing.
The conditional
and joint
functions return a cont_table
object, as the marginal
function returns a freq_table
object.
Value
a tibble
Author(s)
Yves Croissant
Examples
library("dplyr")
# get a contingency table containing education and sex
cont_table(employment, education, sex)
# instead of counts, sum the weights
cont_table(employment, education, sex, weights = weights)
# get the joint distribution and the conditional and marginal
# distribution of sex
cont_table(employment, education, sex) %>% joint
cont_table(employment, education, sex) %>% marginal(sex)
cont_table(employment, education, sex) %>% conditional(sex)