## use example data from ?pyrifos
example(pyrifos)
## Demonstrate the maximum number of permutations for the pyrifos data
## under a series of permutation schemes
## no restrictions - lots of perms
(check1 <- permCheck(pyrifos, control = permControl(type = "free")))
summary(check1)
## no strata but data are series with no mirroring, so 132 permutations
permCheck(pyrifos, control = permControl(type = "series",
mirror = FALSE))
## no strata but data are series with mirroring, so 264 permutations
permCheck(pyrifos, control = permControl(type = "series",
mirror = TRUE))
## unrestricted within strata
permCheck(pyrifos, control = permControl(strata = ditch,
type = "free"))
## time series within strata, no mirroring
permCheck(pyrifos, control = permControl(strata = ditch,
type = "series", mirror = FALSE))
## time series within strata, with mirroring
permCheck(pyrifos, control = permControl(strata = ditch,
type = "series", mirror = TRUE))
## time series within strata, no mirroring, same permutation within strata
permCheck(pyrifos, control = permControl(strata = ditch,
type = "series", constant = TRUE))
## time series within strata, with mirroring, same permutation within strata
permCheck(pyrifos, control = permControl(strata = ditch,
type = "series", mirror = TRUE, constant = TRUE))
## permute strata
permCheck(pyrifos, permControl(strata = ditch, type = "free",
permute.strata = TRUE))
## this should also also for arbitrary vectors
vec1 <- permCheck(1:100)
vec2 <- permCheck(1:100, permControl())
all.equal(vec1, vec2)
vec3 <- permCheck(1:100, permControl(type = "series"))
all.equal(100, vec3$n)
vec4 <- permCheck(1:100, permControl(type = "series", mirror = TRUE))
all.equal(vec4$n, 200)
## enumerate all possible permutations
fac <- gl(2,6)
ctrl <- permControl(type = "grid", mirror = FALSE, strata = fac,
constant = TRUE, nrow = 3, ncol = 2)
numPerms(1:12, control = ctrl)
(tmp <- allPerms(12, control = ctrl, observed = TRUE))
(tmp2 <- allPerms(12, control = ctrl))
## turn on mirroring
ctrl$mirror <- TRUE
numPerms(1:12, control = ctrl)
(tmp3 <- allPerms(12, control = ctrl, observed = TRUE))
(tmp4 <- allPerms(12, control = ctrl))
## prints out details of the permutation scheme as
## well as the matrix of permutations
summary(tmp)
summary(tmp2)
## different numbers of observations per level of strata
fac <- factor(rep(1:3, times = c(3,2,2)))
## free permutations in levels of strata
numPerms(7, permControl(type = "free", strata = fac))
allPerms(7, permControl(type = "free", strata = fac))
## series permutations in levels of strata
numPerms(7, permControl(type = "series", strata = fac))
allPerms(7, permControl(type = "series", strata = fac))
## allPerms can work with a vector
vec <- c(3,4,5)
allPerms(vec)
## Tests for permuplot
n <- 25
## standard permutation designs
permuplot(n, permControl(type = "free"))
permuplot(n, permControl(type = "series"))
permuplot(n, permControl(type = "grid", nrow = 5, ncol = 5))
## restricted perms with mirroring
permuplot(n, permControl(type = "series", mirror = TRUE))
permuplot(n, permControl(type = "grid", nrow = 5, ncol = 5,
mirror = TRUE))
## perms within strata
fac <- gl(6, 20)
control <- permControl(type = "free", strata = fac)
permuplot(120, control = control, cex = 0.8)
control <- permControl(type = "series", strata = fac)
permuplot(120, control = control, cex = 0.8)
fac <- gl(6, 25)
control <- permControl(type = "grid", strata = fac,
nrow = 5, ncol = 5)
permuplot(150, control = control, cex = 0.8)
## perms within strata with mirroring
fac <- gl(6, 20)
control <- permControl(type = "series", strata = fac,
mirror = TRUE)
permuplot(120, control = control, cex = 0.8)
fac <- gl(6, 25)
control <- permControl(type = "grid", strata = fac,
nrow = 5, ncol = 5, mirror = TRUE)
permuplot(150, control = control, cex = 0.8)
## same perms within strata
fac <- gl(6, 20)
control <- permControl(type = "free", strata = fac,
constant = TRUE)
permuplot(120, control = control, cex = 0.8)
control <- permControl(type = "series", strata = fac,
constant = TRUE)
permuplot(120, control = control, cex = 0.8)
fac <- gl(6, 25)
control <- permControl(type = "grid", strata = fac,
nrow = 5, ncol = 5, constant = TRUE)
permuplot(150, control = control, cex = 0.8)
## same perms within strata with mirroring
fac <- gl(6, 20)
control <- permControl(type = "series", strata = fac,
mirror = TRUE, constant = TRUE)
permuplot(120, control = control, cex = 0.8)
fac <- gl(6, 25)
control <- permControl(type = "grid", strata = fac,
nrow = 5, ncol = 5, mirror = TRUE,
constant = TRUE)
permuplot(150, control = control, cex = 0.8)
Run the code above in your browser using DataLab