sim_wilcoxon: Simulate the Power of a Wilcoxon Rank Sum Test

Description Usage Arguments Details Value Author(s) Examples

View source: R/sim_wilcoxon.R

Description

Generates random samples from any two specified distributions and compares the samples by a Wilcoxon rank sum test. Power is calculated as the proportion of tests that correctly reject the null hypothesis.

Usage

1
2
sim_wilcoxon(n, ..., weights = list(c(1, 1)), alpha = 0.05, nsim = 10000,
  seed = NULL, ncores = 1)

Arguments

n

Total sample size

...

two distribution functions should be entered. See 'Details'.

weights

a list of vectors giving the proposed weights for the two groups. Each vector will be normalized.

alpha

Significance level for the test.

nsim

Number of simulations to run per set of conditions

seed

The value of the random number generator seed (for reproducibility)

ncores

The number of cores to use in parallel processing.

Details

Distribution functions should be entered as a valid random variable generating function, but excluding the first argument. For example, to sample from a Poisson distribution with a mean of 3, one would enter rpois(lambda=3). Multiple values may be given to an argument to generate power under multiple conditions, such as rpois(lambda=c(3, 5, 7)).

Value

Returns a data frame with the following fields:

  1. n_total Total sample size

  2. n1 Group 1 sample size

  3. n2 Group 2 sample size

  4. k The proportion of the total sample size allotted to Group 1

  5. alpha Significance level

  6. power Estimate of simulated power

  7. nsim Number of simulations performed

  8. pop1_param Parameters for the random sampling of group 1

  9. pop2_param Parameters for the random sampling of group 2

  10. pop1_dist Random sampling function for group 1

  11. pop2_dist Random sampling function for group 2

Author(s)

Benjamin Nutter

Examples

1
2
3
4
5
sim_wilcoxon(n=30,
             weights=list(c(1, 1), c(1, 3)),
             rpois(lambda=c(2.1, 3.1, 4.1)),
             rpois(lambda=3.53),
             nsim=100)

nutterb/StudyPlanning documentation built on May 24, 2019, 10:51 a.m.