Computes a dependence measure and its asymptotic independence test for two numeric vectors.
Usage
indep_test(
x,
y,
method = "pearson",
weights = NULL,
remove_missing = TRUE,
alternative = "two-sided",
seeds = NULL,
y_continuous = TRUE
)Arguments
- x, y
numeric vectors of data values.
xandymust have the same length.- method
the dependence measure; see Details for possible values.
- weights
an optional vector of weights for the observations.
- remove_missing
if
TRUE, all pairwise incomplete observations are removed; ifFALSE, the function throws an error if there are incomplete observations.- alternative
indicates the alternative hypothesis and must be one of
"two-sided","greater"or"less". You can specify just the initial letter."greater"corresponds to positive association,"less"to negative association.- seeds
an optional integer vector used to break predictor ties for Chatterjee's xi. The default uses a fixed, reproducible ordering.
- y_continuous
whether the response distribution is known to be continuous for Chatterjee inference. Set this to
FALSEfor a discrete response even if the sample contains no observed response ties.
Value
A one-row data frame containing the estimate, transformed test statistic, p-value, effective sample size, method, and alternative.
Details
Available methods:
"pearson": Pearson correlation"spearman": Spearman's \(\rho\)"kendall": Kendall's \(\tau\)"blomqvist": Blomqvist's \(\beta\)"hoeffding": Hoeffding's \(D\)"chatterjee": Chatterjee's \(\xi\)
Partial matching of method names is enabled.
This implementation of Hoeffding's \(D\) does not support tied
observations; test results are invalid when ties are present. It supports
only the two-sided alternative. The natural one-sided alternative for
Chatterjee's \(\xi\) is "greater".
Chatterjee's \(\xi\) measures the dependence of y on x. Analytic
inference with unequal weights requires a continuous response and assumes
that weights are fixed or depend only on x. It is unavailable when the
response is discrete or tied and weights are unequal.
Examples
x <- rnorm(100)
y <- rpois(100, 1)
w <- runif(100)
indep_test(x, y, method = "kendall") # unweighted
#> estimate statistic p_value n_eff method alternative
#> 1 -0.01762804 -0.2317181 0.8167569 100 kendall two-sided
indep_test(x, y, method = "kendall", weights = w) # weighted
#> estimate statistic p_value n_eff method alternative
#> 1 0.01242062 0.1395713 0.8889987 74.08639 kendall two-sided