Skip to content
Prev 3105 / 7420 Next

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

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