Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cran-comments.md
Rplots.pdf
references/working/
.claude/
.claude/settings.local.json
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ importFrom(stats,qlogis)
importFrom(stats,qnorm)
importFrom(stats,qt)
importFrom(stats,quantile)
importFrom(stats,runif)
importFrom(stats,sd)
importFrom(stats,setNames)
importFrom(stats,t.test)
Expand Down
1 change: 1 addition & 0 deletions R/boot_ses_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
#' bootstrap confidence intervals, [brunner_munzel()] with
#' `test_method = "perm"` for robust TOST on the probability scale.
#' @name boot_ses_test
#' @importFrom stats runif
#' @export boot_ses_test

boot_ses_test <- function(x, ...,
Expand Down
24 changes: 15 additions & 9 deletions R/compare_cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@
#' * For minimal effect testing ("minimal.effect"), it determines whether the difference falls
#' outside the specified bounds.
#'
#' **Note on Fisher's z transformation of bounds:** When `method = "fisher"`, the `null` values
#' (equivalence bounds) are specified on the **correlation scale** and are internally converted to
#' the Fisher z scale via `atanh()`. For example, `null = 0.4` is treated as r = 0.4, which maps
#' to z = 0.4236. If you want bounds expressed directly in Fisher-z units, you should back-transform
#' them to the correlation scale first using `tanh()` before passing them to this function.
#'
#' When performing equivalence or minimal effect testing:
#' * If a single value is provided for `null`, symmetric bounds ±value will be used
#' * If two values are provided for `null`, they will be used as the lower and upper bounds
#'
#' @return A list with class "htest" containing the following components:
#'
#' * **statistic**: z-score with name "z"
#' * **statistic**: standardized z-score (i.e., the test statistic divided by its standard error) with name "z"
#' * **p.value**: numeric scalar containing the p-value for the test under the null hypothesis
#' * **estimate**: difference in correlation coefficients between studies
#' * **null.value**: the specified hypothesized value(s) for the null hypothesis
Expand Down Expand Up @@ -138,10 +144,10 @@ compare_cor = function(r1,
phi = p_from_z(zhi/z_se, alternative = 'less')
if(phi >= plo){
pval = phi
z = zhi
z = zhi / z_se
} else {
pval = plo
z = zlo
z = zlo / z_se
}
}
if(alternative == "minimal.effect"){
Expand All @@ -151,10 +157,10 @@ compare_cor = function(r1,
phi = p_from_z(zhi/z_se, alternative = 'greater')
if(phi <= plo){
pval = phi
z = zhi
z = zhi / z_se
} else {
pval = plo
z = zlo
z = zlo / z_se
}
}
} else {
Expand All @@ -178,10 +184,10 @@ compare_cor = function(r1,
phi = p_from_z(zhi/se, alternative = 'less')
if(phi >= plo){
pval = phi
z = zhi
z = zhi / se
} else {
pval = plo
z = zlo
z = zlo / se
}
}
if(alternative == "minimal.effect"){
Expand All @@ -191,10 +197,10 @@ compare_cor = function(r1,
phi = p_from_z(zhi/se, alternative = 'greater')
if(phi <= plo){
pval = phi
z = zhi
z = zhi / se
} else {
pval = plo
z = zlo
z = zlo / se
}
}
} else{
Expand Down
8 changes: 7 additions & 1 deletion man/compare_cor.Rd

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

23 changes: 23 additions & 0 deletions tests/testthat/test-corr.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,29 @@ test_that("Run examples for boot_cor_test", {

})

test_that("compare_cor: z-statistic is standardized (issue #115)", {
result <- compare_cor(
r1 = 0.6, df1 = 18,
r2 = 0.8, df2 = 23,
null = 0.4,
method = "fisher",
alternative = "equivalence"
)

# Manually compute the expected standardized z
z1 <- atanh(0.6)
z2 <- atanh(0.8)
diff <- z1 - z2
SE <- sqrt(1/17 + 1/22)
bound_z <- atanh(0.4)

expected_z <- (diff - (-bound_z)) / SE
expected_p <- 1 - pnorm(expected_z)

expect_equal(unname(result$statistic), expected_z, tolerance = 1e-6)
expect_equal(result$p.value, expected_p, tolerance = 1e-6)
})

test_that("Run examples for boot_compare_cor", {
skip_on_cran()

Expand Down
Loading