Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document r_rbs SEs #341

Merged
merged 7 commits into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions R/rank_effectsizes.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#' Effect size for non-parametric (rank sum) tests
#'
#' Compute the rank-biserial correlation \eqn{(r_{rb})}{}, Cliff's *delta*
#' \eqn{(\delta)}{}, rank epsilon squared \eqn{(\varepsilon^2)}{}, and Kendall's
#' *W* effect sizes for non-parametric (rank sum) tests.
#' Compute the rank-biserial correlation (\eqn{r_{rb}}{r_rb}),
#' Cliff's *delta* (\eqn{\delta}{\delta}),
#' rank epsilon squared (\eqn{\varepsilon^2}{\epsilon^2}), and
#' Kendall's \eqn{W}{W} effect sizes for non-parametric (rank sum) tests.
#'
#' @inheritParams cohens_d
#' @param x Can be one of:
Expand Down Expand Up @@ -200,14 +201,30 @@ rank_biserial <- function(x,
rf <- atanh(r_rbs)
if (paired) {
nd <- sum((x - mu) != 0)
maxw <- (nd * (nd + 1)) / 2

rfSE <- sqrt(((nd * (nd + 1) * (2 * nd + 1)) / 6) * (1 / maxw ^ 2))
maxw <- (nd^2 + nd) / 2

# From: https://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test#Historical_T_statistic
# wSE <- sqrt((n * (n + 1) * (2 * n + 1)) / 24)
# Delta method for f(x) = w * 2 / (maxw) - 1
# r_rbsSE <- wSE * sqrt(4 / (maxw)^2)
# Delta method for z: z_rbsSE <- r_rbsSE / (1 - r_rbs^2)
# But simulations suggest that z_rbsSE is positively biased
# more than r_rbsSE is negatively biased, especially when r_rbs is large,
# so we use r_rbsSE instead
rfSE <- sqrt((2 * nd^3 + 3 * nd^2 + nd) / 6) / maxw
} else {
n1 <- length(x)
n2 <- length(y)

rfSE <- sqrt(4 * 1 / (n1 * n2) ^ 2 * ((n1 * n2 * (n1 + n2 + 1)) / 12))
# From: https://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test#Normal_approximation_and_tie_correction
# wSE <- sqrt((n1 * n2 * (n1 + n2 + 1)) / 12)
# Delta method for f(x) = 1 - 2 * w / (n1 * n2) * sign(diff)
# r_rbsSE <- wSE * sqrt(4 / (n1 * n2)^2)
# Delta method for z: z_rbsSE <- r_rbsSE / (1 - r_rbs^2)
# But simulations suggest that z_rbsSE is positively biased
# more than r_rbsSE is negatively biased, especially when r_rbs is large,
# so we use r_rbsSE instead
rfSE <- sqrt((n1 + n2 + 1) / (3 * n1 * n2))
}

confint <- tanh(rf + c(-1, 1) * qnorm(1 - alpha / 2) * rfSE)
Expand Down
7 changes: 4 additions & 3 deletions man/rank_biserial.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.