I also tried the following:

library(BiodiversityR)
library(vegan)
data(mite)

mite <- mite[1:60,]
env <- data.frame(Fac = rep(LETTERS[1:2], each = 30), NFac =
rep(letters[1:4], each = 15))

nested.npmanova(mite ~ Fac + NFac, data = env, method = "jac", permutations
= 1000)

throwing this error:

Total sum of squares of distance matrix: 16.77718
Fehler in model.frame(data = data1, na.action = function (object, ...)  :
  Objekt 'data1' nicht gefunden

I inspected the source of the function but can not figure out why data1 is
not assigned correctly:

function (formula, data, method = "euc", permutations = 100,
    warnings = FALSE)
{
    randomize = function(data, toplev, lowlev) {
        newdata <- data
        orig.levs <- levels(data[, lowlev])
        nl <- length(orig.levs)
        new.levs <- orig.levs[sample(nl)]
        for (i in 1:nl) {
            subs1 <- data[, lowlev] == orig.levs[i]
            subs2 <- data[, lowlev] == new.levs[i]
            newtops <- data[subs2, toplev]
            newtops <- newtops[1]
            newtops <- rep(newtops, sum(subs1))
            newdata[subs1, toplev] <- newtops
        }
        return(newdata)
    }
    randomize2 = function(data, strata) {
        newdata <- data
        orig.levs <- levels(data[, strata])
        nl <- length(orig.levs)
        for (i in 1:nl) {
            subs <- data[, strata] == orig.levs[i]
            nsub <- sum(subs == T)
            subdata <- data[subs, ]
            newdata[subs, ] <- subdata[sample(nsub), ]
        }
        return(newdata)
    }
    ow <- options("warn")
    if (warnings == FALSE) {
        options(warn = 0)
    }
    formula <- as.formula(formula)
    .BiodiversityR <- new.env()
    environment(formula) <- .BiodiversityR
    if (length(all.vars(formula)) > 3)
        stop(paste("function only works with one main and one nested
factor"))
    x <- eval(as.name((all.vars(formula)[1])))
    if (inherits(x, "dist")) {
        distmatrix <- as.matrix(x)
    }
    else {
        distmatrix <- as.matrix(vegdist(x, method = method))
    }
    SStot <- sum(distmatrix^2)/(2 * nrow(distmatrix))
    cat("Total sum of squares of distance matrix:", SStot, "\n")
    resp <- all.vars(formula)[1]
    toplev <- all.vars(formula)[2]
    lowlev <- all.vars(formula)[3]
    environment(formula) <- .GlobalEnv
    data1 <- data
    assign("data1", data, envir = .BiodiversityR)
    model <- capscale(formula, data1, distance = "euclidean")
    anovares <- anova(model, perm.max = 1, by = "terms")
    anovadat <- data.frame(anovares)
    df1 <- anovadat[1, 1]
    df2 <- anovadat[2, 1]
    df3 <- nrow(distmatrix) - df1 - df2 - 1
    adonis1 <- adonis(formula, data1, permutations = 2, method = method)
    adonis1 <- data.frame(adonis1$aov.tab)
    sstop <- anovadat[1, 2] <- adonis1[1, 2]
    sslow <- anovadat[2, 2] <- adonis1[2, 2]
    ssres <- anovadat[3, 2] <- adonis1[3, 2]
    vartot <- adonis1[4, 2]
    Ftop <- anovadat[1, 3] <- (sstop/df1)/(sslow/df2)
    Flow <- anovadat[2, 3] <- (sslow/df2)/(ssres/df3)
    counter <- 1
    for (i in 1:permutations) {
        data2 <- randomize(data, toplev, lowlev)
        assign("data2", data2, envir = .BiodiversityR)
        adonis2 <- adonis(formula, data = data2, method = method,
            permutations = 2)
        adonis2 <- data.frame(adonis2$aov.tab)
        Frand <- (adonis2[1, 2]/df1)/(adonis2[2, 2]/df2)
        if (Frand >= Ftop) {
            counter <- counter + 1
        }
    }
    signi <- counter/(permutations + 1)
    anovadat[1, 4] <- anovadat[2, 4] <- permutations
    anovadat[1, 5] <- signi
    counter <- 1
    for (i in 1:permutations) {
        data2 <- randomize2(data, toplev)
        assign("data2", data2, envir = .BiodiversityR)
        adonis2 <- adonis(formula, data = data2, method = method,
            permutations = 2)
        adonis2 <- data.frame(adonis2$aov.tab)
        Frand <- (adonis2[2, 2]/df2)/(adonis2[3, 2]/df3)
        if (Frand >= Flow) {
            counter <- counter + 1
        }
    }
    remove("data1", envir = .BiodiversityR)
    remove("data2", envir = .BiodiversityR)
    signi <- counter/(permutations + 1)
    anovadat[2, 5] <- signi
    colnames(anovadat) <- c("Df", "SumsofSquares", "F", "N.Perm",
        "Pr(>F)")
    mod <- paste("Nested anova for", lowlev, "nested within",
        toplev, "\n")
    head <- paste("Total sum of squares for non-parametric manova:",
        vartot, "\n")
    options(ow)
    structure(anovadat, heading = c(head, mod), Random.seed = NA,
        class = c("anova.cca", "anova", "data.frame"))
}
<environment: namespace:BiodiversityR>


2013/2/23 Jari Oksanen <jari.oksanen@oulu.fi>

> Kay,
>
> This should not work if the function is correctly written. You say that
> the terms in your formula are in data=env, but there are no variables
> env$NFac and env$Fac in env -- but there are NFac and Fac.
>
> Cheers, Jari
>
> Sent from my iPad
>
> On 23.2.2013, at 12.15, "Kay Cichini" <kay.cichini@gmail.com> wrote:
>
> > Hi all,
> >
> > Does anyone have a clue why this is not working:
> >
> > library(BiodiversityR)
> > library(vegan)
> >
> > data(mite)
> > mite <- mite[1:60,]
> >
> > env <- data.frame(Fac = rep(LETTERS[1:2], each = 30), NFac =
> > rep(letters[1:4], each = 15))
> >
> > nested.npmanova(mite ~ env$Fac + env$NFac, data = env, method = "jac",
> > permutations = 1000)
> >
> > Regards,
> > Kay
> >
> > --
> >
> > Kay Cichini, MSc Biol
> >
> > Grubenweg 22, 6071 Aldrans
> >
> > Tel.: 0650 9359101
> >
> > E-Mail: kay.cichini@gmail.com
> >
> > Web: www.theBioBucket.blogspot.co.at<
> http://www.thebiobucket.blogspot.co.at/><
> http://www.theBioBucket.blogspot.co.at>
> > --
> >
> >    [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-ecology mailing list
> > R-sig-ecology@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



-- 

Kay Cichini, MSc Biol

Grubenweg 22, 6071 Aldrans

Tel.: 0650 9359101

E-Mail: kay.cichini@gmail.com

Web: www.theBioBucket.blogspot.co.at<http://www.thebiobucket.blogspot.co.at/><http://www.theBioBucket.blogspot.co.at>
--

	[[alternative HTML version deleted]]

