Skip to content

Is Bayesian Kendall's tau working as expected? #224

Open
@jmgirard

Description

@jmgirard

Based on my reading of the below code, if you set bayesian = TRUE and method = "kendall" then you get routed to .cor_test_bayes(method = "kendall") from L256 of cor_test() and then method = "pearson" on L24 of cor_test_bayes() without ever rank-transforming the data. Unless I am missing something, this is just calculating Pearson correlations on the untransformed data and calling them Kendall's tau correlations.

correlation/R/cor_test.R

Lines 233 to 268 in 73471db

# Bayesian
} else {
if (method %in% c("tetra", "tetrachoric")) {
stop("Tetrachoric Bayesian correlations are not supported yet. Get in touch if you want to contribute.")
} else if (method %in% c("poly", "polychoric")) {
stop("Polychoric Bayesian correlations are not supported yet. Get in touch if you want to contribute.")
} else if (method %in% c("biserial", "pointbiserial", "point-biserial")) {
stop("Biserial Bayesian correlations are not supported yet. Get in touch if you want to contribute.")
} else if (method %in% c("biweight")) {
stop("Biweight Bayesian correlations are not supported yet. Get in touch if you want to contribute.")
} else if (method %in% c("distance")) {
stop("Bayesian distance correlations are not supported yet. Get in touch if you want to contribute.")
} else if (method %in% c("percentage", "percentage_bend", "percentagebend", "pb")) {
stop("Bayesian Percentage Bend correlations are not supported yet. Get in touch if you want to contribute.")
} else if (method %in% c("blomqvist", "median", "medial")) {
stop("Bayesian Blomqvist correlations are not supported yet. Check-out the BBcor package (https://github.com/donaldRwilliams/BBcor).")
} else if (method %in% c("hoeffding")) {
stop("Bayesian Hoeffding's correlations are not supported yet. Check-out the BBcor package (https://github.com/donaldRwilliams/BBcor).")
} else if (method %in% c("gamma")) {
stop("Bayesian gamma correlations are not supported yet. Get in touch if you want to contribute.")
} else if (method %in% c("shepherd", "sheperd", "shepherdspi", "pi")) {
out <- .cor_test_shepherd(data, x, y, ci = ci, bayesian = TRUE, ...)
} else {
out <- .cor_test_bayes(
data,
x,
y,
ci = ci,
method = method,
bayesian_prior = bayesian_prior,
bayesian_ci_method = bayesian_ci_method,
bayesian_test = bayesian_test,
...
)
}
}

if (tolower(method) %in% c("spearman", "spear", "s")) {
var_x <- datawizard::ranktransform(var_x, sign = TRUE, method = "average")
var_y <- datawizard::ranktransform(var_y, sign = TRUE, method = "average")
method <- "Bayesian Spearman"
} else if (tolower(method) %in% c("gaussian")) {
var_x <- stats::qnorm(rank(var_x) / (length(var_x) + 1))
var_y <- stats::qnorm(rank(var_y) / (length(var_y) + 1))
method <- "Bayesian Gaussian rank"
} else {
method <- "Bayesian Pearson"
}

Example:

correlation::correlation(mtcars[, 1:3], bayesian = TRUE, method = "kendall")
#> # Correlation Matrix (kendall-method)
#> 
#> Parameter1 | Parameter2 |   rho |         95% CI |      pd | % in ROPE |        BF |         Prior
#> --------------------------------------------------------------------------------------------------
#> mpg        |        cyl | -0.80 | [-0.90, -0.64] | 100%*** |        0% | > 1000*** | Beta (3 +- 3)
#> mpg        |       disp | -0.79 | [-0.90, -0.65] | 100%*** |        0% | > 1000*** | Beta (3 +- 3)
#> cyl        |       disp |  0.86 | [ 0.74,  0.93] | 100%*** |        0% | > 1000*** | Beta (3 +- 3)
#> 
#> Observations: 32

Created on 2021-12-20 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions