Functions for the computation of power and level tables for hypothesis tests, with possible use of a cluster.
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)
vector of law indices as given by function getindex
.
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).
vector of sample sizes (\(n\)) values.
number of Monte Carlo repetitions.
vector of significance levels for the test.
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
.
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
.
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!).
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.
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.
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.
index of the law under the null. Only used, by
many.crit
function, if critval
is NULL
.
vector of parameters corresponding to
null.law.index
.
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.
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'.
Logical. Should we center the data generated
Logical. Should we center the data generated
A list of class power
whose components are described below:
number of Monte Carlo repetitions.
vector of law indices as given by function getindex
.
vector of sample sizes.
vector of test statistic indices as given by function getindex
.
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
.
vector of levels for the test.
left critical values used.
right critical values used.
a vector of 1s and 0s depending if a critical value has been used or not.
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).
default number of parameters used for each law in law.indices
.
default values of the parameters for each law.
default number of parameters for each test
statistic in stat.indices
.
default values of the parameters for each test statistic.
number of CPUs used for the simulations.
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.
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
# 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