[Apologies - I replied with this only to Kay. Hopefully she won't mind
receiving it twice!]
thanks a lot for your elaborations.
of course, envfit(..,strata=rep.mes) does it.
then, at least, i consider it exercise for other cases, were you really
might need a handmade permutation
so, as to round this off, i actually can't analyse this very design in
such a way, with the right NULL concerned - but were to go from here?
You could hook up the code in 'permute'. It contains a new
permuted.index() function (and currently no NAMESPACE, so will overwrite
(mask) the vegan version if loaded after vegan) which will break all the
permutation code in vegan).
Here is your example, modified to use the code in permute. I post this
to illustrate how you'd use the new code. There are lots of examples
in ?permuted.index (for the permute package, not the vegan package
version), but *don't* touch the permutation t-test example code as it
uses permCheck() and it might call allPerms() and allPerms() *IS*
*WRONG* for some designs --- this is the last bit I need to fix/get
working before we can make our first release of this code.
HTH
G
Here's the example script:
## Load packages
require(vegan)
require(permute)
## Data
set.seed(123)
sp <- matrix(runif(24*3*5, 0, 100), nrow = 24 * 3, ncol = 5)
env <- rnorm(24*3, 10, 2)
rep.mes <- gl(24, 3)
### NMDS:
sol <- metaMDS(sp, trymax = 5)
fit <- envfit(sol~env, permutations = 0) ## perms now won't work!
B <- 999 ## number of perms
### setting up frame for population of r2 values:
pop <- rep(NA, B + 1)
pop[1] <- fit$vectors$r
## set-up a Control object:
ctrl <- permControl(strata = rep.mes,
within = Within(type = "series", mirror = FALSE))
## we turn off mirroring as time should only flow in one direction
## Number of observations
nobs <- nrow(sp)
## check it works
matrix(permuted.index(nobs, control = ctrl), ncol = 3, byrow = TRUE)
## Yep - Phew!!!
### loop:
set.seed(1)
for(i in 2:(B+1)){
idx <- permuted.index(nobs, control = ctrl)
fit.rand <- envfit(sol ~ env[idx], permutations = 0)
pop[i] <- fit.rand$vectors$r
}
### p-value:
pval <- sum(pop >= pop[1]) / (B + 1)
pval
pval
[1] 0.286
Now to compare with the actual permutation you'd have gotten from
env.fit, you first need:
detach(package:permute)
set.seed(1)
fit2 <- envfit(sol~env, permutations = 999, strata = rep.mes)
fit2
***VECTORS
NMDS1 NMDS2 r2 Pr(>r)
env 0.28727 0.95785 0.0315 0.321
P values based on 999 permutations, stratified within strata.
a simplistic approach could be, averaging sites, yielding n=24 for
further testing.
yours,
kay
Post by Gavin SimpsonPost by Kay Cecil Cichinigavin,
sorry - of course it should be permute.strata=F, permuting within
individual sites!
but despite of this the code should work, doesn't it?
Yes, it should - i.e the permutation will be random within the blocks.
Whether it does or not is another matter entirely. AFAICR, this option
in permuted.index2() did work.
*But*, this is doing exactly what the original permuted.index() does if
envfit(sol ~ env, strata = rep.mes, perm = 999)
for example. So there is no need to code up the analysis by hand.
This of course doesn't account for any temporal correlation within sites
nor, if the observations on the 24 blocks were made at the same times,
that you might want to have the same permutation within each block.
In the former there are 3^24 possible permutations (time series within
blocks), so 999 random perms is reasonable, *but* some of these random
perms (in permuted.index()) will not respect the temporal ordering and
thus you aren't really exploring the correct NULL.
With the latter constraint (same temporal perm within blocks), there are
3 random permutations, so good luck getting a reasonable p-value from
that.
The two restricted permutations /should/ work correctly, /but/ if you
are doing this by hand, I'd look at the functions in the 'permute'
package - only on R-Forge, on the Vegan R-Forge area - as I know the
code to generate these permutations in that package *does* work. (It is
the helper cruft around it that needs more work.)
https://r-forge.r-project.org/R/?group_id=68
I've had a busy Summer and not made as much progress as I would have
liked, but I hope to finish this soon and make an initial release to
CRAN so we can start grafting it into vegan.
In the meantime, I can help people try to link the two packages if
needed, but I don't have much time till the end of this month.
G
Post by Kay Cecil Cichinithanks,
kay
Post by Gavin SimpsonPost by Kay Cecil Cichinihi eduard,
i faced similar problems recently and came to the below solution.
i only try to address the pseudoreplication with an appropiate
permutation scheme.
when it comes to testing the interactions, things may get more complicated.
the code is in no way approven of, but at least it maybe good enough
for a starter.
best,
kay
Hi Kay,
I don't think you have this right.
If you have measured repeatedly, say 5 times, on the same 10
individuals, or if you have ten fields and you take 5 quadrats from
each, you need to permute *within* the individuals/fields, not permute
the individuals/fields which is what permute.strata does. permute.strata
would be useful in evaluating factors that vary at the block
(individuals/fields) level, not at the sample levels.