Learn R Programming

R2sample (version 4.1.0)

run.studies: Power Comparisons

Description

This function runs the case studies included in the package and compares the power of a new test to those included.

Usage

run.studies(
  TS,
  study,
  TSextra,
  With.p.value = FALSE,
  BasicComparison = TRUE,
  nsample = 500,
  alpha = 0.05,
  param_alt,
  maxProcessor,
  SuppressMessages = FALSE,
  B = 1000
)

Value

A (list of ) matrices of power values.

Arguments

TS

routine to calculate test statistics.

study

either the name of the study, or its number. If missing all the studies are run.

TSextra

list passed to TS.

With.p.value

=FALSE does user supplied routine return p values?

BasicComparison

=TRUE if true compares tests on one default value of parameter of the alternative distribution.

nsample

= 500, desired sample size.

alpha

=0.05 type I error

param_alt

(list of) values of parameter under the alternative hypothesis. If missing included values are used.

maxProcessor

number of cores to use for parallel programming

SuppressMessages

= FALSE print informative messages?

B

= 1000

Details

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

Examples

Run this code
#The new test is a simple chisquare test:
chitest = function(x, y, TSextra) {
   nbins=TSextra$nbins
   nx=length(x);ny=length(y);n=nx+ny
   xy=c(x,y)
   bins=quantile(xy, (0:nbins)/nbins)
   Ox=hist(x, bins, plot=FALSE)$counts
   Oy=hist(y, bins, plot=FALSE)$counts
   tmp=sqrt(sum(Ox)/sum(Oy))
   chi = sum((Ox/tmp-Oy*tmp)^2/(Ox+Oy))
   pval=1-pchisq(chi, nbins-1)
   out=ifelse(TSextra$statistic,chi,pval)
   names(out)="ChiSquare"
   out
}
TSextra=list(nbins=5,statistic=FALSE) # Use 5 bins and calculate p values
run.studies(chitest,TSextra=TSextra, With.p.value=TRUE, B=100)

Run the code above in your browser using DataLab