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 designs.

Usage

p_2r(
  n,
  r.ab1,
  r.ab2,
  r.ac1,
  r.ac2,
  r.bc1,
  r.bc2,
  r.ad1,
  r.ad2,
  r.bd1,
  r.bd2,
  r.cd1,
  r.cd2,
  n2_n1 = 1,
  two.tailed = TRUE,
  type = c("independent", "overlap", "nonoverlap"),
  test = "fisher1925",
  gen_fun = gen_2r,
  ...
)

gen_2r(n, R, ...)

Arguments

n

sample size

r.ab1

correlation between variable A and B in sample 1

r.ab2

correlation between variable A and B in sample 2

r.ac1

same pattern as r.ab1

r.ac2

same pattern as r.ab2

r.bc1

...

r.bc2

...

r.ad1

...

r.ad2

...

r.bd1

...

r.bd2

...

r.cd1

...

r.cd2

...

n2_n1

sample size ratio

two.tailed

logical; use two-tailed test?

type

type of correlation design

test

hypothesis method to use. Defaults to 'fisher1925'

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 ...

...

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

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.ab1=.5, r.ab2=.6)



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

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



# overlap (same y, different xs)
p_2r(100, r.ab1=.5, r.ab2=.7,
          r.ac1=.3, r.ac2=.3,
          r.bc1=.2, r.bc2=.2, type = 'overlap')

# nonoverlap (different ys, different xs)
p_2r(100, r.ab1=.5, r.ab2=.6,
          r.ac1=.3, r.ac2=.3,
          r.bc1=.2, r.bc2=.2,
          r.ad1=.2, r.ad2=.2,
          r.bd1=.4, r.bd2=.4,
          r.cd1=.2, r.cd2=.2,
          type = 'nonoverlap')



Spower documentation built on April 4, 2025, 5:11 a.m.