[R-sig-eco] How to transform a cross-tabulated matrix (as provided by mefa4::Xtab) for further multivariate analyses

Peter Solymos solymos at ualberta.ca
Tue Jun 12 18:11:41 CEST 2012


Ivailo,

Some (but not all) vegan functions internally coerce the "matrix like"
input object to matrix using 'x <- as.matrix(x)'. The as.matrix()
coercion method is defined for sparse matrices in the Matrix package,
and that is why it works for some (but not all) vegan functions. In
case it does not happen I'd recommend using the 'x <- as.matrix(x)'
coercion prior to supplying the data to a vegan function.

Cheers,

Peter

--
Péter Sólymos, Dept Biol Sci, Univ Alberta, T6G 2E9, Canada AB
solymos at ualberta.ca, Ph 780.492.8534, http://psolymos.github.com
Alberta Biodiversity Monitoring Institute, http://www.abmi.ca
Boreal Avian Modelling Project, http://www.borealbirds.ca


On Tue, Jun 12, 2012 at 8:08 AM, Ivailo <ubuntero.9161 at gmail.com> wrote:
> Dear Listmembers,
>
> I have a large data-set that I try to manage (gracefully) according to
> the mefa framework, but have noticed that cross-tabulated matrices
> obtained using mefa4::Xtab can be directly submitted to some of the
> multivariate functions in vegan but not to others.
>
> Here is an example:
>
> # example data
> #
> x <- data.frame(
>  sample = paste("Sample", c(1,1,2,2,3,4), sep="."),
>  species = c(paste("Species", c(1,1,1,2,3), sep="."),  "zero.pseudo"),
>  count = c(1,2,10,3,4,0))
>
> # create a cross-tabulated matrix; drop empty columns and rows to be
> able to dca()
> #
> x1 <- Xtab(count ~ sample + species, x, cdrop=T, rdrop=T)
>
> # now perform some analyses
> #
> dca <- decorana(x1)
> # works OK
>
> vegemite(x1, dca, "Hill", zero="-")
> ##Error in colSums(x[site.ind, ]) :
> ##  'x' must be an array of at least two dimensions
>
> # Trying to make 'x1' a data-frame does not work either
> #
> as.data.frame(x1)
> ##Error in as.data.frame.default(x1) :
> ## cannot coerce class 'structure("dgCMatrix", package = "Matrix")'
> into a data.frame
>
> What would be the correct/recommended way of transforming such
> matrices for use in subsequent multivariate analyses?
>
> Any hints would be much appreciated.
>
> Cheers,
> Ivailo
> --
> UBUNTU: a person is a person through other persons.
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list