p_wilcox.test: p-value from Wilcoxon (signed rank) test simulation

View source: R/p_wilcox.test.R

p_wilcox.testR Documentation

p-value from Wilcoxon (signed rank) test simulation

Description

Simulates data given one (Wilcoxon) or two (Mann-Whitney) parent distributions and returns a p-value. Can also be used for power analyses related to sign tests.

Usage

p_wilcox.test(
  n,
  d,
  n2_n1 = 1,
  mu = 0,
  type = c("two.sample", "one.sample", "paired"),
  exact = NULL,
  correct = TRUE,
  two.tailed = TRUE,
  alternative = NULL,
  parent1 = function(n, d) rnorm(n, d, 1),
  parent2 = function(n, d) rnorm(n, 0, 1),
  return_analysis = FALSE
)

Arguments

n

sample size per group. For paired samples this corresponds to the number of pairings (hence, half of the data points observed)

d

effect size passed to parent functions

n2_n1

sample size ratio

mu

parameter used to form the null hypothesis

type

type of analysis to use (two-sample, one-sample, or paired)

exact

a logical indicating whether an exact p-value should be computed

correct

a logical indicating whether to apply continuity correction in the normal approximation for the p-value

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

parent1

data generation function for first group. Ideally should have SDs = 1 so that d reflects a standardized difference

parent2

same as parent1, but for the second group

return_analysis

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

Value

a single p-value

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

Examples


# with normal distributions defaults d is standardized
p_wilcox.test(100, .5)
p_wilcox.test(100, .5, type = 'paired')  # n = number of pairs
p_wilcox.test(100, .5, type = 'one.sample')

# return analysis object
p_wilcox.test(100, .5, return_analysis = TRUE)

# using chi-squared distributions (standardizing to 0-1)
p_wilcox.test(100, .5, type = 'one.sample',
   parent1 = function(n, d) rchisq(n, df=10) - 10 + d)
p_wilcox.test(100, .5,
   parent1 = function(n, d) (rchisq(n, df=10) - 10)/sqrt(20) + d,
   parent2 = function(n, d) (rchisq(n, df=10) - 10)/sqrt(20))


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