test_r: Test the significance, analyze the power, and plan the sample...

View source: R/test_r.R

test_rR Documentation

Test the significance, analyze the power, and plan the sample size for r.

Description

Test the significance, analyze the power, and plan the sample size for r.

Usage

test_r(r = NULL, n = NULL, sig_level = 0.05, power = 0.8)

Arguments

r

Pearson's correlation. Cohen(1988) suggested >=0.1, >=0.3, and >=0.5 as cut-off values of Pearson's correlation r for small, medium, and large effect sizes, respectively.

n

Sample size of r. Non-integer n would be converted to be a integer using as.integer(). n should be at least 3.

sig_level

Expected significance level.

power

Expected statistical power.

Details

To test the significance of the r using the one-sample t-test, the SE of r is determined by the following formula: SE = sqrt((1 - r^2)/(n - 2)). Another way is transforming r to Fisher's z using the following formula: fz = atanh(r) with the SE of fz being sqrt(n - 3). Fisher's z is commonly used to compare two Pearson's correlations from independent samples. Fisher's transformation is presented here only to satisfy the curiosity of users who are interested in the difference between t-test and Fisher's transformation.

The post-hoc power of r's t-test is computed through the way of Aberson (2019). Other software and R packages like SPSS and pwr give different power estimates due to underlying different formulas. Keng adopts Aberson's approach because this approach guarantees the equivalence of r and PRE.

Value

A list with the following results: ⁠[[1]]⁠ r, the given r; ⁠[[2]]⁠ d, Cohen's d derived from r; Cohen (1988) suggested >=0.2, >=0.5, and >=0.8 as cut-off values of d for small, medium, and large effect sizes, respectively. ⁠[[3]]⁠ Integer n; ⁠[[4]]⁠ t-test of r (incl., r, df of r, SE_r, t, p_r), 95% CI of r based on t -test (LLCI_r_t, ULCI_r_t), and post-hoc power of r (incl., delta_post, power_post); ⁠[[5]]⁠ Fisher's z transformation (incl., fz of r, z-test of fz [SE_fz, z, p_fz], and 95% CI of r derived from fz.

Note that the returned CI of r may be out of r's valid range [-1, 1]. This "error" is deliberately left to users, who should correct the CI manually in reports.

References

Aberson, C. L. (2019). Applied power analysis for the behavioral sciences. Routledge.

Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Routledge.

Examples

test_r(0.2, 193)

# compare the p-values of t-test and Fisher's transformation
for (i in seq(30, 200, 10)) {
cat(c("n = ", i, ", difference between ps = ",
       format(
        abs(test_r(0.2, i)[["t_test"]]["p_r"] - test_r(0.2, i)[["Fisher_z"]]["p_fz"]),
        nsmall = 12,
        scientific = FALSE)),
      sep = "",
      fill = TRUE)
}

Keng documentation built on April 4, 2025, 1:37 a.m.