This function enhances combn
in two ways.
One is to deal with two-group situation, which is commonly seen in real designs;
the other is to choose only a random sample of size R
from all possible
combinations to avoid unnecessary computation.
When neither x2
nor m2
is missing and neither m=0
nor m2=0
,
the function works in two-group mode. In this situation,
(A) if sample.method="diff2"
, combn2R
will try to sample R
combinations from each
group separately. That is, first sample R
combinations from x
taken m
at a time,
and then sample R
combinations from x2
taken m2
at time. The results are then combined
to give R
combinations from the two groups. This sampling method will make the samples as different
from each other as possible. But when R
is larger than min(choose(n1,m1),choose(n2,m2))
,
it is not possible to get R
samples from each group separately. If this happens and try.rest=FALSE
,
then R
will be reset to min(choose(n,m),choose(n2,m2))
and the function works as before;
otherwise, if try.rest=TRUE
, then sample.method
will be reset to "all" and the function will
try to get R
samples from all choose(n1,m1)*choose(n2,m2)
combinations (see below).
(B) if sample.method="all"
, combn2R
will try to sample R
samples from all
choose(n1,m1)*choose(n2,m2)
combinations directly. This means two samples of size m+m2
may have the same sample of size m
(or m2
) which comes from x
(or x2
). For
example, if x=1:3
, m=1
, x2=4:6
, m=2
and R=2
, then it is possible
to get one sample to be 1
and 4,5
, but the other sample is 1
and 5,6
. That is,
the same sample from x
is used in both results. This will not happen when sample.method='diff2'
.
However, this will guarantee any two samples of size m+m2
will differ in at least one element.
(C) if sample.method='replace'
, combn2R
will not guarantee the uniqueness of the
R
combinations in any way. It is possible to have two exactly the same samples of size
m+m2
.
Because the number of possible combinations grows very fast, computational limitations may be reached. In
this case, if try.rest=TRUE
, then sample.method
will be reset to "replace", which uses the
least computational resources; otherwise, an error will be generated.
When either x2
or m2
is missing, or one of m
and m2
is zero,
the function works in one-group mode. In this situation, sample.method="diff2"
and
sample.method="all"
will be treated the same as sample.method="noReplace"
, and combn2R
will try to obtain R
different combinations from all possible combinations for the non-missing group.
Again, if this fails due to computational limitations, sample.method
will be reset to "replace" and
no guarantee will be made to ensure the R
combinations are different from each other.