TDA's segr: a dissimilarity D-Index, a variance ratio and a Gini
coefficient between two groups, across one or more
categorical class variables. The D-Index is
\(\frac{1}{2}\sum_i |p_{1i} - p_{0i}|\), the share of one group that
would have to change class for the two groups' distributions across
classes to match exactly.
Arguments
- data
a data frame.
- group
the grouping variable, as a name or a vector: coded 0 and 1 (or
FALSE/TRUE).- variables
one or more categorical class variables from
data(by name) to compute the measures for, one row of output each. Defaults to every other column indatawhengroupis itself given as a column name (nothing to default to ifgroupwas a raw vector instead, sincedatathen has no column of its own to exclude).- options
a named list of further TDA options, passed through.
- dir
working directory.
Value
An object carrying a table: one row per variable in
variables, with the number of classes, cases in each group,
and the three measures.
See also
Other descriptive statistics:
tda_brr(),
tda_cov(),
tda_dstat(),
tda_freq(),
tda_independence(),
tda_ineq(),
tda_loglin(),
tda_quant(),
tda_rcorr(),
tda_subm()
Examples
set.seed(1)
n <- 100
d <- data.frame(group = rbinom(n, 1, 0.5),
class1 = sample(1:3, n, replace = TRUE),
class2 = sample(1:2, n, replace = TRUE))
tda_segr(d, group = "group", variables = c("class1", "class2"))
#> Call: tda_segr(data = d, group = "group", variables = c("class1", "class2"))
#>
#> Cases:
#>
#> variable classes cases group0 group1 d_index v_ratio gini
#> class1 3 100 52 48 0.11057692 0.0145697807 0.12980769
#> class2 2 100 52 48 0.02083333 0.0004335067 0.02083333