[Vegan-commits] r2888 - in pkg/vegan: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 24 10:53:18 CEST 2014


Author: jarioksa
Date: 2014-09-24 10:53:17 +0200 (Wed, 24 Sep 2014)
New Revision: 2888

Added:
   pkg/vegan/R/gdispweight.R
   pkg/vegan/R/summary.dispweight.R
Modified:
   pkg/vegan/NAMESPACE
   pkg/vegan/R/dispweight.R
   pkg/vegan/man/dispweight.Rd
Log:
Squashed commit of the following:

commit b0dde2c6e4e9d415a56e3fa62740a036a515bd7f
Merge: abb5b0b 1391a30
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Wed Sep 24 11:42:01 2014 +0300

    Merge pull request #43 from jarioksa/veganify-dispweight

    Veganify dispweight

commit 1391a306e31808f4a901d3078764aeadc1eb3461
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Wed Sep 24 10:10:27 2014 +0300

    more detailed authors information for [g]dispweight

commit d688532098d63fbc1faaed66905a13a1eb1230e6
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Wed Sep 24 10:09:58 2014 +0300

    tweak formatting of dispweight summary

commit 3d8b06a476222e8b13ff46a26fad9d5234c6fc8c
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Wed Sep 24 09:57:34 2014 +0300

    edit man/dispweight.Rd

commit 6ce39e51e152f8d3397eb785a446c56ccbf3aaa5
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Tue Sep 23 17:11:05 2014 +0300

    gdispweight cannot handle missing values and fails informatively

    dispweight already fails informatively from nullmodel

commit 6a9d84eb91ab157fc4d430d9d4d54b4a570d51b6
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Tue Sep 23 07:23:26 2014 +0300

    print.summary.dispweight passes ... to printCoefmat

commit 6d5eea1d530fb2131bfb13ea7ff3f1a841e4933a
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Mon Sep 22 21:39:40 2014 +0300

    avoid using anonymous functions in sapply() within gdispweight

commit 704d4c2f3879fd2ffa77cc8ea70df01d331a68ee
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Mon Sep 22 16:42:05 2014 +0300

    add summary.dispweight to extract and print simulation results

commit 00a68c93498e53b0a6bfe967744ecbf90f1dd372
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Mon Sep 22 16:15:44 2014 +0300

    dispweight returns the name of the nullmodel

commit c9b929181efe901d0483e3ed9b07d0e9830d3d1e
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Mon Sep 22 12:47:54 2014 +0300

    dot expansion of terms works in gdispweight(comm ~ ., data=<data>)

commit 02f947d8ac0dadcfafb422e42e2747d5eebede70
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Mon Sep 22 11:07:41 2014 +0300

    [g]dispweight returns attribute on degrees of freedom used ("df")

    gdispweight finds d.f. directly from glm() and this is normally
    constant for all species, but dispweight discards factor levels where
    species does not occur, and degrees of freedom is non-constant for
    species. The d.f. is used to divide the Pearson Chi-square to get
    the overdispersion, and because d.f. is reduced for some species in
    dispweight, these will get higher overdispersion and hence lower
    weight in dispweight than in gdispweight. With this commit, the
    same original Pearson Chi-square will be found for both dispweight
    and gdispweight object:

    attr(object, "D") * attr(object, "df")

commit 99f9a6bc2e2849bb7319157839e69866968b3bd6
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Mon Sep 22 10:53:06 2014 +0300

    export gdispweight from the NAMESPACE

commit 94a0d4349256b423c2a7e9066a73d4216f44e656
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 20:41:51 2014 +0300

    Update author information for dispweight + gdispweight

    I think that email address of Eduard Sz?\195?\182cs also was out of date.

commit 87391813102ed27cadd0986fd8b78ed72d3293fd
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 20:32:00 2014 +0300

    Introduce generalized (parametric) dispersion weighting

    This is a new unpublished method. Original method uses Pearson
    Chi-square for a Poisson model with one factor and assesses the
    significance using multinomial simulation ("c0_ind" nullmodel).
    The new method estimates the same Pearson Chi-square for any glm
    model and evaluates the significance parametrically. Otherwise the
    models are identical except that the original method ignores
    completely the factor levels where species in assessing the number
    of degrees of freedom, but the generalized method defines the
    degrees of freedom in a standard way (number of observations minus
    number of model coefficients). As the degrees of freedom is used as
    divisor for weights, this will influence the strength of downweighting.

commit 37f5261e2f2933c90c6521f6c258c1a850a3426b
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 08:50:24 2014 +0300

    Relax data requirements in dispweight: reject only binary models

    The test of data properties was moved to checking properties of
    defined nullmodel, and only binary null models are rejected (these
    would all have p=1). We now accept also non-integer quantitative
    data. I don't know if these make sense, but that is none of my
    business -- users decide.

commit f4d1394fd7216effef1b3670974b44627b2fc08c
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 08:38:45 2014 +0300

    dispweight handles 1-level 'groups': analysis wrt community mean

commit 9092774c0f46c177a6ca4ce254478e4a348141fb
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 08:28:21 2014 +0300

    Expose nullmodel and plimit as user arguments in dispweight

commit 21e0362b1f7ee3ae101684466921b59919008b89
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 08:24:11 2014 +0300

    adapt docs to 999 simulations of commit 67adb96

commit 67adb967a5d13bc439cfa52844dc4fb9f10cd0c9
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 08:17:05 2014 +0300

    default to 999 simulations in dispweight

commit 7ba5092c9bbbd6519fdba2c1e590e9f4f5000e64
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Sep 21 08:08:22 2014 +0300

    major rewrite of dispweight: rethink, streamline & use vegan::nullmodel

    The function was completely rewritten to use vegan::nullmodel
    "c0_ind" which is equal to the simulation used in the original
    function. The original function looped over species, but  now we
    perform simulation for all species simultaneously using nullmodel,
    and loop over levels of 'groups'. All code that could be moved
    out of this loop was moved, and calculation of 'dhat' statistics
    was refactored and streamlined -- and done outside the loop.

    There are not many unchanged lines, but the results are equal provided
    the 'p' values are on the same side of the fixed critical level.

    In my laptop, this is also about 3x faster than the original.

commit 824de6ca248a29faa0290b4f4fda8b7ef9aa3994
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sat Sep 20 08:54:09 2014 +0300

    remove empty levels from "groups" or dispweight fails cryptically

    Error in if (any(means == 0)) { : missing value where TRUE/FALSE needed

commit 70277611eacc86153d56cac101f076d547bf3666
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sat Sep 20 08:45:20 2014 +0300

    dispweight used arg 'group', but other vegan functions use 'groups'

commit ae6c6af97b7a033e85931ba9801d5cf8db8c074f
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Fri Sep 19 08:45:15 2014 +0300

    dispweight doc says that it is 'nsimul' (not 'nperm')

commit cd129e362142ba2b4b08d70a2da1a4710c9e6c85
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Fri Sep 19 08:40:57 2014 +0300

    document that dispweight returns transformed data

commit 8087340689d133b6dd5b34aae136452687a99984
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Tue Aug 6 17:37:36 2013 +0300

    check that input are integers, fix docs

commit bff23ee508a7338503f9ac2eb7280bf0217e0432
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Tue Aug 6 16:53:46 2013 +0300

    dispweight does simulations, not permutations

commit 7d5a6ed8828ead61c81b6b4f9ebe9d651253f8c7
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Mon Aug 5 08:55:18 2013 +0300

    all dispweights return transformed data (with attributes)

commit 6b6a47b9dd16bc0421103a0900f659f15d7f8bc8
Author: Jari Oksanen <jari.oksanen at oulu.fi>
Date:   Sun Aug 4 09:04:39 2013 +0300

    dispweights work without 'group' argument

Modified: pkg/vegan/NAMESPACE
===================================================================
--- pkg/vegan/NAMESPACE	2014-09-23 07:20:05 UTC (rev 2887)
+++ pkg/vegan/NAMESPACE	2014-09-24 08:53:17 UTC (rev 2888)
@@ -10,7 +10,7 @@
 decostand, designdist, coverscale, dispweight, dispindmorisita, distconnected,
 diversity, downweight, drarefy, eigengrad, eigenvals, envfit,
 estaccumR, estimateR, eventstar, factorfit, fisherfit, fitspecaccum,
-goodness, hiersimu, humpfit, indpower, inertcomp, initMDS,
+gdispweight,goodness, hiersimu, humpfit, indpower, inertcomp, initMDS,
 intersetcor, isomapdist, isomap, linestack, mantel, meandist,
 metaMDSdist, metaMDSiter, metaMDSredist, MDSrotate, metaMDS, monoMDS,
 mrpp, msoplot, mso, multipart, make.commsim, nestedbetajac, nestedbetasor, nestedchecker,
@@ -356,6 +356,7 @@
 S3method(print, summary.cca)
 S3method(print, summary.clamtest)
 S3method(print, summary.decorana)
+S3method(print, summary.dispweight)
 S3method(print, summary.humpfit)
 S3method(print, summary.isomap)
 S3method(print, summary.meandist)
@@ -428,6 +429,7 @@
 S3method(summary, cca)
 S3method(summary, clamtest)
 S3method(summary, decorana)
+S3method(summary, dispweight)
 S3method(summary, eigenvals)
 S3method(summary, humpfit)
 S3method(summary, isomap)

Modified: pkg/vegan/R/dispweight.R
===================================================================
--- pkg/vegan/R/dispweight.R	2014-09-23 07:20:05 UTC (rev 2887)
+++ pkg/vegan/R/dispweight.R	2014-09-24 08:53:17 UTC (rev 2888)
@@ -1,66 +1,59 @@
 `dispweight` <-
-    function(comm, group, nperm = 1000)
+    function(comm, groups, nsimul = 999, nullmodel = "c0_ind",
+             plimit = 0.05)
 {
-    # number of replicates per group
-    nrep <- tabulate(group) 
-    # workhorse
-    dfun <- function(comm, group, nperm, nrep) {
-        ## Calc Dispersion
-        # group means
-        means <-  tapply(comm, group, mean)
-        # omit groups with mean == 0
-        if(any(means == 0)) {
-            comm <- comm[means[group] != 0]
-            group <- group[means[group] != 0, drop = TRUE]
-            nrep <- nrep[means != 0]
-            means <- means[means != 0]
-        }
-        # group variances
-        vars <-  tapply(comm, group, var)
-        # dispersion
-        d <- vars / means
-        # average dispersion 
-        d_hat <- sum(d * (nrep - 1)) / sum(nrep - 1)
-        
-        ## Test
-        # original chisq values
-        chi_o <- sum((comm - means[group])^2 / means[group])
-        
-        # permutations
-        # calculate chisq
-        pfun <- function(comm, group){
-            means <-  tapply(comm, group, mean)
-            if(any(means == 0)) {
-                comm <- comm[means[group] != 0]
-                group <- group[means[group] != 0, drop = TRUE]
-                means <- means[means != 0]
-            }
-            chi <- sum((comm - means[group])^2 / means[group])
-            return(chi)
-        }
-        # sum of individuals per group
-        sums <- tapply(comm, group, sum)
-        # realocate randomly individuals to replications
-        perms <- vector('list', length(sums))
-        for(i in seq_along(sums)) {
-            perms[[i]] <- rmultinom(n = nperm, size = sums[i], prob = rep(1, nrep[i]) / nrep[i])
-        }
-        perms <- t(do.call(rbind, perms))
-        chi_p <- apply(perms, 1, pfun, sort(group))
-        p <- (sum(chi_p >= chi_o) + 1) / (nperm + 1)
-        out <- list(D = d_hat, p = p, weights = ifelse(p < 0.05, 1/d_hat, 1))
-        return(out)
+    ## no groups?
+    if (missing(groups))
+        groups <- rep(1, nrow(comm))
+    ## Remove empty levels of 'groups' or this fails cryptically (and
+    ## take care 'groups' is a factor)
+    groups <- factor(groups)
+    ## Statistic is the sum of squared differences by 'groups'
+    means <- apply(comm, 2, function(x) tapply(x, groups, mean))
+    ## handle 1-level factors: all sites belong to the same 'groups'
+    if (is.null(dim(means)))
+        means <- matrix(means, nrow=1, ncol = length(means),
+                        dimnames = list(levels(groups), names(means)))
+    ## expand to matrix of species means
+    fitted <- means[groups,]
+    dhat <- colSums((comm - fitted)^2/fitted, na.rm = TRUE)
+    ## Get df for non-zero blocks of species. Completely ignoring
+    ## all-zero blocks for species sounds strange, but was done in the
+    ## original paper, and we follow here. However, this was not done
+    ## for significance tests, and only concerns 'D' and 'weights'.
+    nreps <- table(groups)
+    div <- colSums(sweep(means > 0, 1, nreps - 1, "*"))
+    ## "significance" of overdispersion is assessed from Chi-square
+    ## evaluated separately for each species. This means fixing only
+    ## marginal totals for species but letting row marginals vary
+    ## freely, unlike in standard Chi-square where both margins are
+    ## fixed. In vegan this is achieved by nullmodel 'c0_ind'. Instead
+    ## of one overall simulation, nullmodel is generated separately
+    ## for each of 'groups'
+    chisq <- function(x) {
+        fitted <- colMeans(x)
+        colSums(sweep(x, 2, fitted)^2, na.rm = TRUE) / fitted
     }
-    # apply workhorse to every species
-    out <- apply(comm, 2, dfun, group, nperm, nrep)
-    
-    # format output
-    weights <-  unlist(sapply(out, '[', 3))
-    out <- list(D = unlist(sapply(out, '[', 1)), 
-                p = unlist(sapply(out, '[', 2)),
-                weights = weights,
-                transformed = sweep(comm, MARGIN = 2, weights, `*`))
-    attr(out, "permutations") <- nperm
-    class(out) <- "dispweight"
-    return(out)
-}
\ No newline at end of file
+    simulated <- matrix(0, nrow = ncol(comm), ncol = nsimul)
+    for (lev in levels(groups)) {
+        nm <- nullmodel(comm[groups == lev,], nullmodel)
+        if (nm$commsim$binary)
+            stop("'binary' nullmodel cannot be used")
+        tmp <- apply(simulate(nm, nsimul), 3, chisq)
+        ok <- !is.na(tmp)
+        simulated[ok] <- simulated[ok] + tmp[ok] 
+    }
+    ## p value based on raw dhat, then we divide
+    p <- (rowSums(dhat <= simulated) + 1) / (nsimul + 1)
+    dhat <- dhat/div
+    weights <- ifelse(p <= plimit, 1/dhat, 1)
+    comm <- sweep(comm, 2, weights, "*")
+    attr(comm, "D") <- dhat
+    attr(comm, "df") <- div
+    attr(comm, "p") <- p
+    attr(comm, "weights") <-  weights
+    attr(comm, "nsimul") <- nsimul
+    attr(comm, "nullmodel") <- nullmodel
+    class(comm) <- c("dispweight", class(comm))
+    comm
+}

Added: pkg/vegan/R/gdispweight.R
===================================================================
--- pkg/vegan/R/gdispweight.R	                        (rev 0)
+++ pkg/vegan/R/gdispweight.R	2014-09-24 08:53:17 UTC (rev 2888)
@@ -0,0 +1,52 @@
+### Clarke's dispweight is based on the hypothesis that count data
+### should follow Poisson distribution, and species overdispersed to
+### the Poisson should be downweighted. The basic model assesses the
+### expected values of species and their overdispersion wrt to class
+### means for a single factor and then estimates the significance of
+### the overdispersion using individual-based simulation within these
+### same classes. Function gdispweight generalizes this by allowing a
+### formula that specifies any fitted model, but estimates the
+### significance of the overdispersion analytically from Pearson
+### residuals.
+
+`gdispweight` <-
+    function(formula, data, plimit = 0.05)
+{
+    ## We do not handle missing values (yet?)
+    op <- options(na.action = "na.fail")
+    on.exit(op)
+    ## extract response data
+    comm <- eval(formula[[2]])
+    ## extract rhs
+    if (missing(data))
+        data <- environment(formula)
+    x <- model.matrix(delete.response(terms(formula, data = data)),
+                      data = data)
+    ## Quasi-Poisson
+    family <- quasipoisson()
+    V <- family$variance
+    ## fit models to all species separately and extract results
+    mods <- lapply(comm, function(y) glm.fit(x, y, family = family))
+    y <- sapply(mods, '[[', "y")
+    mu <- sapply(mods, fitted)
+    wts <- sapply(mods, '[[',  "prior.weights")
+    res <- (y-mu) * sqrt(wts) / sqrt(V(mu))
+    df <- sapply(mods, df.residual)
+    ## the same stats as in Clarke's original, but parametrically
+    stat <- colSums(res^2)
+    p <- pchisq(stat, df, lower.tail = FALSE)
+    dhat <- stat/df
+    w <- ifelse(p < plimit, 1/dhat, 1)
+    ## do not upweight underdispersed species
+    w <- ifelse(w > 1, 1, w)
+    ## done
+    comm <- sweep(comm, 2, w, "*")
+    class(comm) <- c("dispweight", class(comm))
+    attr(comm, "D") <- dhat
+    attr(comm, "df") <- df
+    attr(comm, "p") <- p
+    attr(comm, "weights") <- w
+    attr(comm, "nsimul") <- NA
+    attr(comm, "nullmodel") <- NA
+    comm
+}

Added: pkg/vegan/R/summary.dispweight.R
===================================================================
--- pkg/vegan/R/summary.dispweight.R	                        (rev 0)
+++ pkg/vegan/R/summary.dispweight.R	2014-09-24 08:53:17 UTC (rev 2888)
@@ -0,0 +1,22 @@
+### summary methods extracts dispweight attributes, and prints a table
+### of dispersion statistics
+
+`summary.dispweight`  <-
+    function(object, ...)
+{
+    x <- attributes(object)
+    class(x) <- "summary.dispweight"
+    x
+}
+
+`print.summary.dispweight` <-
+    function(x, ...)
+{
+    tab <- with(x, cbind(D, weights, df, p))
+    colnames(tab) <- c("Dispersion", "Weight", "Df", "Pr(Disp.)")
+    printCoefmat(tab, cs.ind = NA, ...)
+    if (!is.na(x$nsimul))
+        cat(gettextf("Based on %d simulations on '%s' nullmodel\n",
+                     x$nsimul, x$nullmodel))
+    invisible(x)
+}

Modified: pkg/vegan/man/dispweight.Rd
===================================================================
--- pkg/vegan/man/dispweight.Rd	2014-09-23 07:20:05 UTC (rev 2887)
+++ pkg/vegan/man/dispweight.Rd	2014-09-24 08:53:17 UTC (rev 2888)
@@ -1,57 +1,120 @@
 \encoding{UTF-8}
 \name{dispweight}
 \alias{dispweight}
+\alias{gdispweight}
+\alias{summary.dispweight}
 \title{Dispersion-based weighting of species counts}
 
-\description{Transform abundance data using dispersion-based weighting of species counts}
+\description{Transform abundance data downweighting species that are 
+  overdispersed to the Poisson error.}
 
-\usage{dispweight(comm, group, nperm = 1000)}
+\usage{
+dispweight(comm, groups, nsimul = 999, nullmodel = "c0_ind",
+    plimit = 0.05)
+gdispweight(formula, data, plimit = 0.05)
+\method{summary}{dispweight}(object, ...)
+}
 
 \arguments{
   \item{comm}{Community data matrix.}
-  \item{group}{Factor describing the group structure.}
-  \item{nperm}{Number of permutations.}
+  \item{groups}{Factor describing the group structure. If missing, all 
+     sites are regarded as belonging to one group. \code{NA} values are 
+     not allowed.}
+  \item{nsimul}{Number of simulations.}
+  \item{nullmodel}{The \code{\link{nullmodel}} used in
+    \code{\link{commsim}} within \code{groups}. The default
+    follows Clarke et al. (2006).}
+  \item{plimit}{Downweight species if their \eqn{p}-value is at or
+     below this limit.}
+  \item{formula, data}{Formula where the left-hand side is the
+    community data frame and right-hand side gives the explanatory
+    variables. The explanatory variables are found in the data frame
+    given in \code{data} or in the parent frame.}
+  \item{object}{Result object from \code{dispweight} or
+    \code{gdispweight}.}
+  \item{\dots}{Other parameters passed to functions.}
 }
 
 \details{
-Dispersion weighting can be used when there are \emph{a priori} defined groups 
-(eg. lacation of samples). 
 
-The dispersion index (\eqn{D}) is calculated as ratio between 
-variance and mean and averaged across groups. D can then be used as divisor to 
-downweight species abundances.
+The dispersion index (\eqn{D}) is calculated as ratio between variance
+and expected value for each species.  If the species abundances follow
+Poisson distribution, expected dispersion is \eqn{E(D) = 1}, and if
+\eqn{D > 1}, the species is overdispersed. The inverse \eqn{1/D} can
+be used to downweight species abundances.  Species are only
+downweighted when overdispersion is judged to be statistically
+significant (Clarke et al. 2006).
 
-However species should be only downweighted, when there is evidence for 
-over-dispersion (\eqn{D > 1}). This is tested using a permutational Chi-squared test. 
-If this test shows statistically significant over-dispersion then the species is 
-downweighted by \eqn{1/D}, else the divisor is \eqn{1}.
+Function \code{dispweight} implements the original procedure of Clarke
+et al. (2006). Only one factor can be used to group the sites and to
+find the species means. The significance of overdispersion is assessed
+freely distributing individuals of each species within factor
+levels. This is achieved by using \code{\link{nullmodel}}
+\code{"c0_ind"} (which accords to Clarke et al. 2006), but other
+nullmodels can be used, though they may not be meaningful (see
+\code{\link{commsim}} for alternatives). If a species is absent in
+some factor level, the whole level is ignored in calculation of
+overdispersion, and the number of degrees of freedom can vary among
+species. The reduced number of degrees of freedom is used as a divisor
+for overdispersion \eqn{D}, and such species have higher dispersion
+and hence lower weights in transformation.
+
+Function \code{gdispweight} is a generalized parametric version of
+\code{dispweight}. The function is based on \code{\link{glm}} with
+\code{\link{quasipoisson}} error \code{\link{family}}. Any
+\code{\link{glm}} model can be used, including several factors or
+continuous covariates. Function \code{gdispweight} uses the same test
+statistic as \code{dispweight} (Pearson Chi-square), but it does not
+ignore factor levels where species is absent, and the number of
+degrees of freedom is equal for all species. Therefore transformation
+weights can be higher than in \code{dispweight}. The
+\code{gdispweight} function evaluates the significance of
+overdispersion parametrically from Chi-square distribution
+(\code{\link{pchisq}}).
+
+Functions \code{dispweight} and \code{gdispweight} transform data, but
+they add information on overdispersion and weights as attributes of
+the result. The \code{summary} can be used to extract and print that
+information.  
 }
 
 \value{
-A list of class \code{dispweight} with the following items:
-    \item{D}{Average Dispersion index.}
-    \item{p}{\eqn{p}-value of permutation test that \eqn{D = 1}.}
+Function returns transformed data with the following new attributes:
+    \item{D}{Dispersion statistic.}
+    \item{df}{Degrees of freedom for each species.}
+    \item{p}{\eqn{p}-value of the Dispersion statistic \eqn{D}.}
     \item{weights}{weights applied to community data.}
-    \item{transformed}{transformed community data.}
+    \item{nsimul}{Number of simulations used to assess the \eqn{p}-value,
+      or \code{NA} when simulations were not performed.}
+    \item{nullmodel}{The name of \code{\link{commsim}} null model, or
+      \code{NA} when simulations were not performed.}
 }
 
 \references{
-Clarke, K. R., M. G. Chapman, P. J. Somerfield, and H. R. Needham. 2006. Dispersion-based Weighting of Species Counts in Assemblage Analyses. \emph{Marine Ecology Progress Series}, 320, 11–27.
+Clarke, K. R., M. G. Chapman, P. J. Somerfield, and
+H. R. Needham. 2006. Dispersion-based weighting of species counts in
+assemblage analyses. \emph{Marine Ecology Progress Series}, 320,
+11–27.
 }
+
 \author{
-  Eduard Szöcs \email{szoe8822 at uni-landau.de}
+  Eduard Szöcs \email{eduardszoesc at gmail.com} wrote the original
+  \code{dispweight}, Jari Oksanen significantly modified the code,
+  provided support functions and developed \code{gdispweight}.
 }
 
 
 \examples{
-data(dune)
-data(dune.env)
-# calculate weights
-dpw <- dispweight(dune, dune.env$Management, nperm = 100)
-# transformed community data
-dpw$transformed
+data(mite, mite.env)
+## dispweight and its summary
+mite.dw <- with(mite.env, dispweight(mite, Shrub, nsimul = 99))
+summary(mite.dw)
+## generalized dispersion weighting
+mite.dw <- gdispweight(mite ~ Shrub + WatrCont, data = mite.env)
+rda(mite.dw ~ Shrub + WatrCont, data = mite.env)
 }
 
 
 \keyword{multivariate}
+\keyword{manip}
 



More information about the Vegan-commits mailing list