Learn R Programming

R2sample (version 5.1.0)

twosample_test: Tests for the univariate two-sample problem

Description

This function runs a number of two sample tests using Rcpp and parallel computing.

Usage

twosample_test(
  x,
  y,
  vals = NA,
  TS,
  TSextra,
  wx = rep(1, length(x)),
  wy = rep(1, length(y)),
  B = 5000,
  seed = NULL,
  nbins = c(50, 10),
  minexpcount = 5,
  maxProcessor,
  UseLargeSample,
  samplingmethod = "Binomial",
  rnull,
  SuppressMessages = FALSE,
  doMethods = "all"
)

Value

A list of two numeric vectors, the test statistics and the p values.

Arguments

x

a vector of numbers if data is continuous or of counts if data is discrete or a list with the data

y

a vector of numbers if data is continuous or of counts if data is discrete.

vals

=NA, a vector of numbers, the values of a discrete random variable. NA if data is continuous data.

TS

routine to calculate test statistics for non-chi-square tests

TSextra

additional info passed to TS, if necessary

wx

A numeric vector of weights of x.

wy

A numeric vector of weights of y.

B

=5000, number of simulation runs for permutation test

seed

=NULL, optional seed for reproducibility

nbins

=c(50,10), number of bins for chi square tests.

minexpcount

=5, minimum required expected counts for chi-square tests.

maxProcessor

maximum number of cores to use. If missing (the default) no parallel processing is used.

UseLargeSample

should p values be found via large sample theory if n,m>10000?

samplingmethod

="Binomial" or "independence" for discrete data

rnull

a function that generates data from a model, possibly with parameter estimation.

SuppressMessages

= FALSE print informative messages?

doMethods

="all" a vector of codes for the methods to include. If "all", all methods are used. For continuous data without weights and for discrete data this includes the HHG test (Heller, Heller, Kaufman, Brill and Gorfine 2016), see the vignette.

Details

For details consult vignette("R2sample","R2sample")

Examples

Run this code
 R2sample::twosample_test(rnorm(1000), rt(1000, 4), B=1000)
 myTS=function(x,y) {z=c(mean(x)-mean(y),sd(x)-sd(y));names(z)=c("M","S");z}
 R2sample::twosample_test(rnorm(1000), rt(1000, 4), TS=myTS, B=1000)
 vals=1:5
 x=table(sample(vals, size=100, replace=TRUE))
 y=table(sample(vals, size=100, replace=TRUE, prob=c(1,1,3,1,1)))
 R2sample::twosample_test(x, y, vals)

Run the code above in your browser using DataLab