Learn R Programming

bayesics (version 2.0.2)

cor_test_b: Test for Association/Correlation Between Paired Samples via Kendall's tau

Description

Test for Association/Correlation Between Paired Samples via Kendall's tau

Usage

cor_test_b(x, ...)

# S3 method for default cor_test_b( x, y, tau = 0, ROPE, prior = "centered", prior_shapes, CI_level = 0.95, plot = TRUE, ... )

# S3 method for formula cor_test_b( formula, data, tau = 0, ROPE, prior = "centered", prior_shapes, CI_level = 0.95, plot = TRUE, ... )

Value

(returned invisible) A list with the following:

  • posterior_mean: posterior mean of Kendall's tau

  • CI: Credible interval bounds

  • Pr_less_than_tau: Posterior probability that Kendall's tau is less than provided reference tau

  • Pr_in_ROPE: Posterior probability that Kendall's tau is in the ROPE

  • prob_plot: Posterior and prior plot

  • posterior_parameters: The posterior for Kendall's tau is a location shift and scaled beta distribution to fall over the range -1 to 1, i.e., \(0.5 * (\tau + 1.0)\) follows a beta with shape parameters given by posterior_parameters.

  • dfba_bivariate_concordance_object: The underlying object from the DFBA package

Arguments

x, y

numeric vectors of data values. x and y must have the same length.

...

optional arguments.

tau

If provided, cor_test_b will return the posterior probability that Kendall's tau is less than this value.

ROPE

If a single number, ROPE will be \(\tau\pm\) ROPE. If a vector of length 2, these will serve as the ROPE bounds. Defaults to \(\pm\)0.05.

prior

Beta prior used on \(phi\) (see details). Either "uniform' (Beta(1,1)), "centered' (Beta(2,2)), "positive" (Beta(3.9,2), putting 80% of the prior mass above 0.5), or "negative" (Beta(2,3.9), putting 80% of the prior mass below 0.5).

prior_shapes

Vector of length two, giving the shape parameters for the beta distribution that will act as the prior on \(\phi\) (see details).

CI_level

The posterior probability to be contained in the credible interval.

plot

logical. Should a plot be shown?

formula

ADD description!

data

ADD description!

Details

cor_test_b relies on the robust Kendall's tau, defined to be $$ \tau := \frac{(\# \text{concordant pairs}) - (\# \text{discordant pairs})}{(\# \text{concordant pairs}) - (\# \text{discordant pairs})}, $$ where a concordant pair is a pair of points such that if the rank of the x values is higher for the first (second) point of the pair, so too the rank of the y value is higher for the first (second) point of the pair.

The Bayesian approach of Chechile (2020) puts a Beta prior on \(phi\), the proportion of concordance, i.e., $$ \phi := \frac{(\# \text{concordant pairs})}{(\# \text{concordant pairs}) - (\# \text{discordant pairs})}. $$ The relationship between the two, then, is \(\tau = 2\phi - 1\), or equivalently \(\phi = (\tau + 1)/2\).

For more information, see dfba_bivariate_concordance and vignette("dfba_bivariate_concordance",package = "DFBA").

References

Chechile, R.A. (2020). Bayesian Statistics for Experimental Scientists: A General Introduction Using Distribution_Free Statistics. Cambridge: MIT Press.

Chechile, R.A., & Barch, D.H. (2021). A distribution-free, Bayesian goodness-of-fit method for assessing similar scientific prediction equations. Journal of Mathematical Psychology. https://doi.org/10.1016/j.jmp.2021.102638

Lindley, D. V., & Phillips, L. D. (1976). Inference for a Bernoulli process (a Bayesian view). The American Statistician, 30, 112-119.

Barch DH, Chechile RA (2023). DFBA: Distribution-Free Bayesian Analysis. doi:10.32614/CRAN.package.DFBA

Examples

Run this code
# \donttest{
# Generate data
set.seed(2025)
N = 50
x = rnorm(N)
y = x + 4 * rnorm(N)

# Test for non-zero correlation
cor_test_b(x,y)

# Input can be in the form of formula and data
cor_test_b(~ asdf + qwer,
           data = data.frame(asdf = x,
                             qwer = y))

# Other priors can be used, also.  See help for details.
cor_test_b(x,y,
           prior = "uniform")
cor_test_b(x,y,
           prior = "negative")
cor_test_b(x,y,
           prior = "positive")
cor_test_b(x,y,
           prior_shapes = c(10,10))
# }


Run the code above in your browser using DataLab