plyr and mvabund, conceptual issue
On Wed, Oct 29, 2014 at 4:23 AM, Eduard Sz?cs <eduardszoecs at gmail.com> wrote:
Hai Kendra,
i've used a simple for-loop to do this in the past.
Something along these lines:
###-----------------------------------------------------------------
mymv <- function(response, env, zone) {
df <- data.frame(env = env, zone = zone)
out <- NULL
for (i in levels(zone)) {
rsp <- mvabund(response[zone == i, ])
out[[i]]$mod <- manyglm(rsp ~ env, data = df[zone == i, ])
out[[i]]$anova <- anova(out[[i]]$mod, p.uni = "adjusted", resamp =
"perm.resid", nBoot = 10)
}
return(out)
}
If you're going to use a for-loop, you need to preallocate the output:
out <- vector("list", length(levels(zone))
Otherwise each iteration of the loop needs to copy all previous output
to a new location, making things rather slow.
Hadley