Description Usage Arguments Details Value Note Author(s) See Also Examples
Enumerate or sample permutations of treatment assignments in a one-way design.
1 2 3 4 5 | permuteTrt(trt, B = 100, idxOnly = FALSE)
nparts(n)
nperms.permutedTrt(permutedTrt)
ntrt.permutedTrt(permutedTrt)
trt.permutedTrt(permutedTrt)
|
trt |
A vector of treatment labels |
B |
A positive integer of the number of permutations requested. |
idxOnly |
A logical scalar, indicating whether only factoradic indices are computed. This has no effect when |
n |
The sample size in each treatment group. |
permutedTrt |
A |
The nparts
functions computes the total number of partitions, with sizes being specified by n
.
Denote the totality by N
, i.e., length(trt)
or sum(n)
. When B
is no smaller than nparts(table(trt))
, all partitions are returned by permuteTrt
and B
is set to nparts(table(trt))
.
Otherwise, a sample B
random permutations will be selection from a total of N!
possible permutations (without replacement).
For permuteTrt
, it returns S3 object of class 'permutedTrt'
, which is a list ANS
of length(unique(trt))
treatment assignment matrices. When idxOnly
is FALSE
, each matrix has B
columns, where B
may be smaller than requested, such that ANS[[i]][,b]
contains sorted individual indices that are allocated to treatment i
under the b
th random permutation. Note that, here b
should not be interpreted as the factoradic number. That is, the column locations of the matrices have no special meaning. However, an exception is that the first column (i.e., the first permutation) is always equivalent to the original treatment assignment. In other words, it is guaranteed that setequal( split(seq(length(trt)),trt), lapply(ANS, '[', , 1L))
should always be TRUE
. In addition, the 'idx'
attribute of the result is set to NA_character_
.
When idxOnly
is TRUE
, each matrix has only one column, corresponding to the original treatment assignment. The permutations being sampled represented by the correspoding decimal factoradic numbers (stored as character) returned in the 'idx'
attribute. In this case, the length of the 'idx'
attribute is B
and the first element is always "0"
, corresponding to no permutations.
nparts
returns the total number of non-equivalent treatment assignments.
nperms.permutedTrt
returns the total number of permutations.
ntrt.permutedTrt
returns a named vector of sample sizes.
trt.permutedTrt
recovers the trt
vector passed to permuteTrt
.
When B
is less than nparts(table(trt))
, ideally one could randomly sample B
partitions from a total of nparts(table(trt))
without replacement, subject to the first partition being equivalent to the original treatment assignment. For the sake of simplicity, this is not implemented here. The random sample of size B
is generated from a total of N!
permutations without replacement. Therefore, it is possible for some of the permutations sampled corresponding to equivalent partitions. However, for the purpose of permutation tests, the type I error rate is still under control.
Long Qu
combn
, urand.bigz
, HSEL.bigz
, sample1
, dec2permvec
1 2 3 4 5 6 7 8 9 | set.seed(2340)
trt=gl(2,10)
nparts(table(trt)) ## 92378 partitions = choose(20,10)/2
urand.bigz(0,seed=1032940L) # init seed
pmat=permuteTrt(trt, 1e3L) ## use 1000 random permutations
## Not run:
pmat=permuteTrt(trt, 1e6L) ## use all partitions, as 1e6L >= 92378
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.