Bias correction in betadisper with unequal sample sizes

HI Gavin, Jari, and Marti,

I'm writing to inquire about the importance of unequal sample sizes in
deriving and comparing beta diversity estimates across different groups.
My phd has focused on coral reef fish communities and in response to an
experiment with unequal sample sizes, a reviewer recently raised the
issue of unequal sample sizes in biasing beta diversity estimates when
comparing across groups. I've been working on this project with my
collaborator Ben Bolker (cc'd here). A numerical simulation he
constructed suggests that there is indeed bias in estimates of beta
diversity when sample sizes are unequal and sample sizes are small.

The solution that Ben converged on was a sqrt(n/(n-1)) correction factor
that can be applied to estimated distances to centroid for each group
(i.e. analogous to the correction commonly applied at the for sample
standard deviations).

 We attach a PDF file showing how we guessed this correction factor
(which makes sense in hindsight, although I would have difficulty coming
up with a rigorous derivation).

 We also attach a diff file from the current vegan version on r-forge
(r2127) which includes an option to correct the bias in this way (as
well as a one-line fix for an edge case, where there is only one
non-zero eigenvalue -- we came across this situation in the course of
running simulations, although it's probably not practically important
much of the time).  We think this should also work in the presence of NA
values, although we haven't tested it in that case.)
canonical way of creating 1x1 diagonal matrices
document bias.adjust in betadisper()
Squashed commit of the following:

commit 3bb2f744f63f96d6a9f2160f8c967749c80e42ab
Merge: fa4e49c cc0ba26
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Wed May 2 08:49:26 2012 +0300

    Merge branch 'master' of https://github.com/jarioksa/vegan

commit fa4e49ce75abf027347db8d6eca03d3415b0622e
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Sun Apr 29 09:04:57 2012 +0300

    monoMDS checks that there are enough dissimilarities for the analysis

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2150 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Squashed commit of the following:

commit 3bb2f744f63f96d6a9f2160f8c967749c80e42ab
Merge: fa4e49c cc0ba26
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Wed May 2 08:49:26 2012 +0300

    Merge branch 'master' of https://github.com/jarioksa/vegan

commit fa4e49ce75abf027347db8d6eca03d3415b0622e
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Sun Apr 29 09:04:57 2012 +0300

    monoMDS checks that there are enough dissimilarities for the analysis

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2150 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Fix calculation of ordimedian

Influences also betadisper
Merge branch 'master' into betadisper
Merge branch 'ordimedian' into betadisper
Change betadisper example now that median is the default

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2156 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Change betadisper example now that median is the default

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2156 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Merge branch 'r-forge-svn-local'
ordiplot3d returns projected origin and function envfit.convert

The envfit.convert function projects a 3-d envfit object to the
the current 3d plot, and together with projected origin can be used
to project the result to the plot:

mod <- cca(varespec)
ef <- envfit(mod ~ ., varechem, choices = 1:3)
pl3 <- ordiplot3d(mod)
plot(pl3$envfit.convert(ef), at = pl3$origin, p.max = 0.05)
Merge branch 'master' of https://github.com/jarioksa/vegan
Squashed commit of the following:

commit ffa3ddf9d62bc8d7afd62abe60fce9960625f474
Merge: ddad83c 4ebe87b
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Wed May 9 23:10:15 2012 +0300

    Merge branch 'master' of https://github.com/jarioksa/vegan

commit ddad83cce47306420223502d69cacc7f15e9c912
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Wed May 9 23:04:57 2012 +0300

    ordiplot3d returns projected origin and function envfit.convert

    The envfit.convert function projects a 3-d envfit object to the
    the current 3d plot, and together with projected origin can be used
    to project the result to the plot:

    mod <- cca(varespec)
    ef <- envfit(mod ~ ., varechem, choices = 1:3)
    pl3 <- ordiplot3d(mod)
    plot(pl3$envfit.convert(ef), at = pl3$origin, p.max = 0.05)

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2157 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Squashed commit of the following:

commit ffa3ddf9d62bc8d7afd62abe60fce9960625f474
Merge: ddad83c 4ebe87b
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Wed May 9 23:10:15 2012 +0300

    Merge branch 'master' of https://github.com/jarioksa/vegan

commit ddad83cce47306420223502d69cacc7f15e9c912
Author: Jari Oksanen <jari.oksanen@oulu.fi>
Date:   Wed May 9 23:04:57 2012 +0300

    ordiplot3d returns projected origin and function envfit.convert

    The envfit.convert function projects a 3-d envfit object to the
    the current 3d plot, and together with projected origin can be used
    to project the result to the plot:

    mod <- cca(varespec)
    ef <- envfit(mod ~ ., varechem, choices = 1:3)
    pl3 <- ordiplot3d(mod)
    plot(pl3$envfit.convert(ef), at = pl3$origin, p.max = 0.05)

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2157 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
rotated arrows must be expressed against projected origin in ordiplot3d

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2158 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
rotated arrows must be expressed against projected origin in ordiplot3d

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2158 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
matrix could drop to a vector in envfit.convert() returned by ordiplot3d

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2159 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
matrix could drop to a vector in envfit.convert() returned by ordiplot3d

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2159 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
example on envfit & ordiplot3d interfaces

git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/vegan/pkg/vegan@2160 edb9625f-4e0d-4859-8d74-9fd3b1da38cb