Contrast patterns are a generalization of association rules that allow for the specification of a condition under which there is a significant difference in some statistical feature between two numeric variables.
theta(xvar) >> theta(yvar) | C
The feature theta
of the first variable xvar
is significantly higher
than the feature theta
of the second variable yvar
under the
condition C
.
mean(daily_ice_cream_income) >> mean(daily_tea_income) | sunny
The mean of daily ice-cream income is significantly higher than
the mean of daily tea income under the condition of sunny weather.
The contrast is computed using
a statistical test, which is specified by the method
argument. The
function computes the contrast between all pairs of variables, where the
first variable is specified by the xvars
argument and the second variable
is specified by the yvars
argument. The contrast is computed in sub-data
corresponding to conditions generated from the condition
columns. The
dig_contrasts()
function supports crisp conditions only, i.e., the
condition columns must be logical.
dig_contrasts(
x,
condition = where(is.logical),
xvars = where(is.numeric),
yvars = where(is.numeric),
method = "t",
alternative = "two.sided",
min_length = 0L,
max_length = Inf,
min_support = 0,
max_p_value = 0.05,
threads = 1,
...
)
A tibble with found patterns in rows. The following columns are always present:
the condition of the pattern as a character string
in the form {p1 & p2 & ... & pn}
where p1
, p2
, ..., pn
are
x
's column names.
the support of the condition, i.e., the relative
frequency of the condition in the dataset x
.
the name of the first variable in the contrast.
the name of the second variable in the contrast.
the p-value of the underlying test.
the number of rows in the sub-data corresponding to the condition.
a character string indicating the alternative hypothesis.
a character string indicating the method used for the test.
For the "t"
method, the following additional columns are also
present (see also t.test()
):
the estimated mean of variable xvar
.
the estimated mean of variable yvar
.
the t-statistic of the t test.
the degrees of freedom of the t test.
the lower bound of the confidence interval.
the upper bound of the confidence interval.
the standard error of the mean difference.
For the "wilcox"
method, the following additional columns are also
present (see also wilcox.test()
):
the estimate of the location parameter.
the Wilcoxon rank sum statistic.
the lower bound of the confidence interval.
the upper bound of the confidence interval.
For the "var"
method, the following additional columns are also
present (see also var.test()
):
the ratio of the sample variances of variables
xvar
and yvar
.
the value of the F test statistic.
the numerator degrees of freedom.
the denominator degrees of freedom.
the lower bound of the confidence interval for the ratio of the population variances.
the upper bound of the confidence interval for the ratio of the population variances.
a matrix or data frame with data to search in.
a tidyselect expression (see tidyselect syntax) specifying the columns to use as condition predicates
a tidyselect expression (see tidyselect syntax) specifying the columns to use for computation of contrasts
a tidyselect expression (see tidyselect syntax) specifying the columns to use for computation of contrasts
a character string indicating which contrast to compute.
One of "t"
, "wilcox"
, or "var"
. "t"
(resp. "wilcos"
) compute
a parametric (resp. non-parametric) test on equality in position, and
"var"
performs the F-test on equality of variance.
indicates the alternative hypothesis and must be one of
"two.sided"
, "greater"
or "less"
. "greater"
corresponds to
positive association, "less"
to negative association.
the minimum size (the minimum number of predicates) of the condition to be generated (must be greater or equal to 0). If 0, the empty condition is generated in the first place.
The maximum size (the maximum number of predicates) of the condition to be generated. If equal to Inf, the maximum length of conditions is limited only by the number of available predicates.
the minimum support of a condition to trigger the callback
function for it. The support of the condition is the relative frequency
of the condition in the dataset x
. For logical data, it equals to the
relative frequency of rows such that all condition predicates are TRUE on it.
For numerical (double) input, the support is computed as the mean (over all
rows) of multiplications of predicate values.
the maximum p-value of a test for the pattern to be considered
significant. If the p-value of the test is greater than max_p_value
, the
pattern is not included in the result.
the number of threads to use for parallel computation.
Further arguments passed to the underlying test function
(t.test()
, wilcox.test()
, or var.test()
accordingly to the
selected method).
Michal Burda
dig()
, dig_grid()
, stats::t.test()
, stats::wilcox.test()
, stats::var.test()
crispCO2 <- partition(CO2, Plant:Treatment)
dig_contrasts(crispCO2,
condition = where(is.logical),
xvars = conc,
yvars = uptake,
method = "t",
min_support = 0.1)
Run the code above in your browser using DataLab