[Vegan-commits] r2700 - in pkg/permute: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Nov 12 21:17:26 CET 2013
Author: gsimpson
Date: 2013-11-12 21:17:26 +0100 (Tue, 12 Nov 2013)
New Revision: 2700
Modified:
pkg/permute/R/shuffleSet2.R
pkg/permute/inst/ChangeLog
pkg/permute/man/shuffleSet.Rd
Log:
a better way of handling small permutation sets; generate all of them, and then sample nset of them.
Modified: pkg/permute/R/shuffleSet2.R
===================================================================
--- pkg/permute/R/shuffleSet2.R 2013-11-11 18:30:52 UTC (rev 2699)
+++ pkg/permute/R/shuffleSet2.R 2013-11-12 20:17:26 UTC (rev 2700)
@@ -7,6 +7,8 @@
nset <- 1
else
nset <- np
+ } else {
+ control <- update(control, nperm = nset)
}
sn <- seq_len(n) ## sequence of samples in order of input
@@ -50,6 +52,16 @@
## Use that instead of a ranodm set
out <- control$all.perms
}
+
+ ## Because all.perms might have been generated, we have the
+ ## possibility that nrow(out) != nset. In that case, also no random
+ ## numbers have been generated. Hence we can sample nset rows from
+ ## out and return that. This has the nice side-effect of not
+ ## generating any non-unique permutations. Suggested by Jari.
+ if ((nr <- nrow(out)) > nset) {
+ out <- out[sample.int(nr, nset), ]
+ }
+
out
}
Modified: pkg/permute/inst/ChangeLog
===================================================================
--- pkg/permute/inst/ChangeLog 2013-11-11 18:30:52 UTC (rev 2699)
+++ pkg/permute/inst/ChangeLog 2013-11-12 20:17:26 UTC (rev 2700)
@@ -2,6 +2,21 @@
permute ChangeLog
+Version 0.7-7
+
+ * shuffleSet: Implemented an idea of Jari's to allow `check()` and
+ `allPerms()` to do their thing and possibly generate the set of all
+ permutations, rather than turn off checking. If that now results in
+ more than `nset` permutations, `shuffleSet` randomly takes `nset` of
+ these. This is a nice suggestion as it avoids the problem that with
+ small numbers of possible permutations, you can randomly draw the
+ same permutation more than once.
+
+ As I have added this feature, I reverted some earlier changes to the
+ documentation that used the `check = FALSE` in their call to
+ `shuffleSet()`. The `check` argument is retained though, as a way for
+ function writers to skip that part of the permute workflow if desired.
+
Version 0.7-6
* summary.allPerms: Was printing two slightly different subtitles.
Modified: pkg/permute/man/shuffleSet.Rd
===================================================================
--- pkg/permute/man/shuffleSet.Rd 2013-11-11 18:30:52 UTC (rev 2699)
+++ pkg/permute/man/shuffleSet.Rd 2013-11-12 20:17:26 UTC (rev 2700)
@@ -126,7 +126,7 @@
## as above, but with same permutation for each Plot-level stratum
CTRL <- how(plots = plotStrata,
within = Within(type = "series", constant = TRUE))
-shuffleSet(20, 10, CTRL, check = FALSE)
+shuffleSet(20, 10, CTRL)
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
More information about the Vegan-commits
mailing list