p_r: p-value from correlation simulation

View source: R/p_r.R

p_rR Documentation

p-value from correlation simulation

Description

Generates correlated X-Y data and returns a p-value to assess the null of no correlation in the population. The X-Y data are generated assuming a bivariate normal distribution.

Usage

p_r(n, r, rho = 0, method = "pearson", two.tailed = TRUE, gen_fun = gen_r, ...)

gen_r(n, r, ...)

Arguments

n

sample size

r

correlation

rho

population coefficient to test against. Uses the Fisher's z-transformation approximation when non-zero

method

method to use to compute the correlation (see cor.test). Only used when rho = 0

two.tailed

logical; should a two-tailed or one-tailed test be used?

gen_fun

function used to generate the required dependent bivariate data. Object returned must be a matrix with two columns and n rows. Default uses gen_r to generate conditionally dependent data from a bivariate normal distribution. 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

Value

a single p-value

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

See Also

gen_r

Examples


# 50 observations, .5 correlation
p_r(50, r=.5)
p_r(50, r=.5, method = 'spearman')

# test against constant other than rho = .6
p_r(50, .5, rho=.60)



    # compare simulated results to pwr package

    pwr::pwr.r.test(r=0.3, n=50)
    p_r(n=50, r=0.3) |> Spower()

    pwr::pwr.r.test(r=0.3, power=0.80)
    p_r(n=NA, r=0.3) |> Spower(power=.80, interval=c(10, 200))

    pwr::pwr.r.test(r=0.1, power=0.80)
    p_r(n=NA, r=0.1) |> Spower(power=.80, interval=c(200, 1000))




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