Message-ID: <CABdHhvHcFL_mVCL-Smi5_2mUK-a-s=o5sk1rvdk_B6+mqLqPHg@mail.gmail.com>
Date: 2014-10-29T13:38:46Z
From: Hadley Wickham
Subject: plyr and mvabund, conceptual issue
In-Reply-To: <5450B205.3030805@gmail.com>
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
--
http://had.co.nz/