p_2r: p-value from comparing two or more correlations simulation

View source: R/p_2r.R

p_2rR Documentation

p-value from comparing two or more correlations simulation

Description

Function utilizes cocor to perform correlation comparison for independent, overlapping, and non-overlapping correlation designs. Type type of correlation design is inferred based on which correlations are specified.

Usage

p_2r(
  n,
  r.ab,
  r.ab2 = NULL,
  r.ac,
  r.bc,
  r.ad,
  r.bd,
  r.cd,
  n2_n1 = 1,
  two.tailed = TRUE,
  alternative = NULL,
  test = NULL,
  gen_fun = gen_2r,
  return_analysis = FALSE,
  ...
)

gen_2r(n, R, ...)

Arguments

n

sample size

r.ab

correlation between variable A and B (for independent groups, this is for sample 1)

r.ab2

(for independent group test only) correlation between variable A and B in sample 2

r.ac

(for overlap/non-overlap) correlation between A and C. This is the correlation used in the overlapping hypothesis test, comparing this input to r.ab

r.bc

(for overlap/non-overlap only) correlation between B and C.

r.ad

(for non-overlap only) correlation between A and D

r.bd

(for non-overlap only) correlation between B and D

r.cd

(for non-overlap only) correlation between C and D. This is the correlation used in the non-overlapping hypothesis test, comparing this input to r.ab

n2_n1

sample size ratio. Only used for independent group test

two.tailed

logical; use two-tailed test? For one-tailed tests relevant alternative arguments are set to 'greater'

alternative

character vector passed to alternative analysis function (most commonly, 'two.tailed', 'greater', 'less'). When used, ignores the value of two.tailed

test

hypothesis testing method to use. Defaults to 'fisher1925' for the independent groups test and 'steiger1980' for overlap/non-overlap tests

gen_fun

function used to generate the required discrete data. Object returned must be a matrix with n rows. Default uses gen_2r. User defined version of this function must include the argument ...

return_analysis

logical; return the analysis object for further extraction and customization?

...

additional arguments to be passed to gen_fun. Not used unless a customized gen_fun is defined

R

a correlation matrix constructed from the inputs to p_2r

Details

For independent group tests, only r.ab and r.ab2 need to be specified, where the null hypothesis pertains to H_0: r_{ab}=r_{ab2}.

For overlapping correlation tests, r.ab, r.ac, and r.bc need to be specified, where the null hypothesis pertains to H_0: r_{ab}=r_{ac}.

For non-overlapping correlation tests, all correlations expect for r.ab2 must be specified, where the null hypothesis pertains to H_0: r_{ab}=r_{cd}.

Value

a single p-value

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

Examples


# independent (same x-y pairing across groups)
p_2r(100, r.ab=.5, r.ab2=.6)

# return cocor object for further analysis
p_2r(100, r.ab=.5, r.ab2=.6, return_analysis = TRUE)



   # estimate empirical power
   p_2r(n=100, r.ab=.5, r.ab2=.6) |> Spower()

   # estimate n required to reach 80% power
   p_2r(n=interval(100, 5000), r.ab=.5, r.ab2=.6) |> Spower(power=.80)



# overlap (same y, different xs)
# H0: r.ab = r.bc
p_2r(100, r.ab=.5, r.ac=.3, r.bc=.2)

# nonoverlap (different ys, different xs)
# H0: r.ab = r.cd
p_2r(100, r.ab=.5, r.ac=.3, r.bc=.2, r.ad=.2, r.bd=.4, r.cd=.2)



Spower documentation built on Oct. 16, 2026, 9:08 a.m.