Learn R Programming

PoweR (version 1.0.7)

powcomp.fast: Computation of power and level tables for hypothesis tests.

Description

Functions for the computation of power and level tables for hypothesis tests, with possible use of a cluster.

Usage

powcomp.fast(law.indices,stat.indices,vectn = c(20,50,100),M = 10^3,levels = c(0.05,0.1),
         critval = NULL,alter = create.alter(stat.indices),parlaws = NULL, 
         parstats = NULL,nbclus = 1,model = NULL,null.law.index = 2,null.law.pars = NULL,
         Rlaws=NULL, Rstats = NULL, center=FALSE, scale=FALSE)

Arguments

law.indices

vector of law indices as given by function getindex.

stat.indices

vector of statistic indices as given by function getindex (some components can be 0 if you want to use your own function for some test statistics; see 'Rstats' argument).

vectn

vector of sample sizes (\(n\)) values.

M

number of Monte Carlo repetitions.

levels

vector of significance levels for the test.

critval

if not NULL, a named-list of critical values for each test statistic. The names of the list should be stat\(j\), \(j\) taken in stat.indices. Note that if a single value of critval$stat\(j\) is povided, then it is the right critical value. If two values are provided, then these are the left and right critical values, in that order. If NULL, critval is computed using the function many.crit; in that case, be sure to provide the correct value for null.law.index.

alter

named-list of integer values (0: two.sided=bilateral, 1: less=unilateral, 2: greater=unilateral, 3: bilateral test that rejects H0 only for large values of the test statistic, 4: bilateral test that rejects H0 only for small values of the test statistic). The names of the list should be stat\(j\), \(j\) taken in stat.indices.

parlaws

named-list of parameter values for each law to simulate. The names of the list should be law\(j\), \(j\) taken in law.indices. The length of vector law\(j\) should not be greater than 4 (we supposed than no common distribution has more than 4 parameters!).

parstats

named-list of parameter values for each statistic to simulate. The names of the list should be stat\(j\), \(j\) taken in stat.indices (in the same order). If NULL, the default parameter values for these statistics will be used.

nbclus

number of slaves to use for the computation on a cluster. This needs parallel or Rmpi package to be installed and functionnal on the system. Also the mpd daemon sould be started.

model

NOT YET IMPLEMENTED. If NULL, no model is used. If an integer \(i>0\), the model coded in the C function modele\(i\) is used. Else this shoud be an R function that takes three arguments: eps (vector of \(\epsilon\) values), thetavec (vector of \(\theta\) values) and xvec (vector or matrix of \(x\) values). This function should take a vector of errors, generate observations from a model (with parameters thetavec and values xvec) based on these errors, then compute and return the residuals from the model. See function modele1.R in directory inst/doc/ for an example in multiple linear regression.

null.law.index

index of the law under the null. Only used, by many.crit function, if critval is NULL.

null.law.pars

vector of parameters corresponding to null.law.index.

Rlaws

When some law indices in 'law.indices' are equal to 0, this means that you will be using some R random generators. In that case, you should provide the names of the random generation functions in the corresponding components of 'Rlaws' list, the other components should be set to NULL.

Rstats

A list. If in a given row of the 'params' matrix, the value of 'stat' is set to 0, the corresponding component of the list 'Rstats' should be an R function that outputs a list with components 'statistic' (value of the test statistic), 'pvalue' (pvalue of the test; if not computable should be set to 0), 'decision' (1 if we reject the null, 0 otherwise), 'alter' (see above), 'stat.pars' (see above), 'pvalcomp' (1L if the pvalue can be computed, 0L otherwise), 'nbparstat' (length of stat.pars). If the value of 'stat' is not 0, then the corresponding component of 'Rstats' should be set to 'NULL'.

center

Logical. Should we center the data generated

scale

Logical. Should we center the data generated

Value

A list of class power whose components are described below:

M

number of Monte Carlo repetitions.

law.indices

vector of law indices as given by function getindex.

vectn

vector of sample sizes.

stat.indices

vector of test statistic indices as given by function getindex.

decision

a vector of counts (between 0 and M) of the decisions taken for each one of the levels.len * laws.len * vectn.len * stats.len combinations of (level,law,sample size,test statistic), to be understood in the following sense. The decision for the \(l\)-th level (in levels), \(d\)-th law (in law.indices), \(n\)-th sample size (in vectn) and \(s\)-th test statistic (in stat.indices) is given by: decision[\(s\) + stats.len*(\(n\)-1) + stats.len*vectn.len*(\(d\)-1) + stats.len*vectn.len*laws.len*(\(l\)-1)]

where stats.len, vectn.len, laws.len and levels.len are respectively the lengths of the vectors stat.indices, vectn, law.indices and levels.

levels

vector of levels for the test.

cL

left critical values used.

cR

right critical values used.

usecrit

a vector of 1s and 0s depending if a critical value has been used or not.

alter

type of each one of the tests in stat.indices used (0: two.sided=bilateral, 1: less=unilateral, 2: greater=unilateral, 3: bilateral test that rejects H0 only for large values of the test statistic, 4: bilateral test that rejects H0 only for small values of the test statistic).

nbparlaws

default number of parameters used for each law in law.indices.

parlaws

default values of the parameters for each law.

nbparstats

default number of parameters for each test statistic in stat.indices.

parstats

default values of the parameters for each test statistic.

nbclus

number of CPUs used for the simulations.

Details

This version is faster (but maybe less easy to use in the process of investigating the power of test statistics under different alternatives) than the powcomp.easy version.

References

Pierre Lafaye de Micheaux, Viet Anh Tran (2016). PoweR: A Reproducible Research Tool to Ease Monte Carlo Power Simulation Studies for Studies for Goodness-of-fit Tests in R. Journal of Statistical Software, 69(3), 1--42. doi:10.18637/jss.v069.i03

Examples

Run this code
# NOT RUN {
## Regenerate Table 6 from Puig (2000) (page 424)

law.index <- 1
# Take M = 50000 for accurate results 
M <- 10
vectn <- c(10,15,20,35,50,75,100)
level <- c(0.05)
stat.indices <- c(43,44,42,45,46)
law.indices <- c(2,3,4)
alter <- list(stat43 = 3,stat44 = 3,stat42 = 3,stat45 = 3,stat46 = 3)
critval <- many.crit(law.index,stat.indices,M,vectn,level,alter,
                     law.pars = NULL,parstats = NULL)
table6 <- powcomp.fast(law.indices,stat.indices,vectn,M,level,critval = critval,alter,
                       parlaws = NULL,parstats = NULL,nbclus = 1)
table6
# }

Run the code above in your browser using DataLab