Skip to content

trasformation of matrix for iNEXT extrapolation interpolation of Hill's numbers

4 messages · Irene Adamo, Torsten Hauffe, Law, Jason +1 more

#
Hi all,

I am working with iNEXT package for diversity analyses however, I would
like to use a incidence_raw data type which in iNEXT is a list of matrices
like this:

data(ciliates)
head(ciliates)

$SouthernNamibDesert
                                                     x9 x17 x19 x20 x21 x22
x23 x24
Acaryophrya.collaris                                  0   0   0   0   0   0
  0   0
Actinobolina.multinucleata.n..sp.                     0   0   0   0   0   0
  0   0
Afroamphisiella.multinucleata.n..sp.                  0   0   0   0   0   0
  0   0
Afrothrix.multinucleata.n..sp.                        0   1   0   0   0   0
  0   0
Amphisiella.binucleata.multicirrata.n..ssp.           0   0   0   0   0   0
  0   0
Amphisiella.elegans.n..sp.                            0   0   0   0   0   0
  1   0
Amphisiella.longiseries.n..sp.                        0   0   0   0   0   0
  0   0
Amphisiella.magnigranulosa                            0   0   0   0   0   0
  0   1
Amphisiella.multinucleata.n..sp.                      0   0   0   0   0   0
  0   0
Amphisiella.namibiensis.n..sp.                        0   0   0   0   0   0
  0   0
Amphisiella.polycirrata                               0   0   0   0   0   0
  0   0
Amphisiella.procera.n..sp.                            1   0   0   0   0   0
  0   0

do you know how can I create anlist with four matrices like the one they
have in example data?

thanks a lot for any help!
#
Hi,

In general, you can create a list containing matrices, data.frames, or
(almost) any object in the following way:

# 2 Matrices as example
M1 <- matrix(NA, ncol = 5, nrow = 3)
M2 <- matrix(NA, ncol = 3, nrow = 5)

List <- list() # initiate an empty list
List[[1]] <- M1 # Enter M1 as first element of the list
List[[2]] <- M2
names(List) <- c("Matrix1", "Matrix2") # Maybe iNEXT needs names?
List

HTH,
Torsten
On Thu, 20 Jun 2019 at 16:28, Irene Adamo <i.adamo90 at gmail.com> wrote:

            

  
  
#
I'm not sure what your data looks like. But the reshape package can be used to easily create matrix or array data from a 'long' format. Combining that with split would make it relatively to create matrices.

library(iNEXT)
library(reshape2)
data(ciliates)
# Maybe your data is in long format like this:
df <- melt(ciliates, varnames = c('species', 'sample'), value.name = 'count') 
# Then this will work
df.list <- lapply(split(df, df$L1), function(x) acast(x, species ~ sample, value.var='count')) 

# If your data is just one wide (sorted) matrix, then you just need lapply and the column indices
mat <- acast(df, species ~ L1 + sample, value.var='count')
df.list <- lapply(list(c(1,17), c(18,36), c(37,51)), function(i) mat[,i[1]:i[2]])

Regards,

Jason

-----Original Message-----
From: R-sig-ecology <r-sig-ecology-bounces at r-project.org> On Behalf Of Irene Adamo
Sent: Thursday, June 20, 2019 07:28
To: r-sig-ecology at r-project.org
Subject: [R-sig-eco] trasformation of matrix for iNEXT extrapolation interpolation of Hill's numbers

Hi all,

I am working with iNEXT package for diversity analyses however, I would like to use a incidence_raw data type which in iNEXT is a list of matrices like this:

data(ciliates)
head(ciliates)

$SouthernNamibDesert
                                                     x9 x17 x19 x20 x21 x22
x23 x24
Acaryophrya.collaris                                  0   0   0   0   0   0
  0   0
Actinobolina.multinucleata.n..sp.                     0   0   0   0   0   0
  0   0
Afroamphisiella.multinucleata.n..sp.                  0   0   0   0   0   0
  0   0
Afrothrix.multinucleata.n..sp.                        0   1   0   0   0   0
  0   0
Amphisiella.binucleata.multicirrata.n..ssp.           0   0   0   0   0   0
  0   0
Amphisiella.elegans.n..sp.                            0   0   0   0   0   0
  1   0
Amphisiella.longiseries.n..sp.                        0   0   0   0   0   0
  0   0
Amphisiella.magnigranulosa                            0   0   0   0   0   0
  0   1
Amphisiella.multinucleata.n..sp.                      0   0   0   0   0   0
  0   0
Amphisiella.namibiensis.n..sp.                        0   0   0   0   0   0
  0   0
Amphisiella.polycirrata                               0   0   0   0   0   0
  0   0
Amphisiella.procera.n..sp.                            1   0   0   0   0   0
  0   0

do you know how can I create anlist with four matrices like the one they have in example data?

thanks a lot for any help!


_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
Or, if the component matrices need to be numeric with species names as row
names and sites as column names, Dave Roberts' labdsv package has matrify()
that does that and fills in the unseen combinations with 0s as opposed to
NAs.  Converting {site, taxon, abundance} triplets to matrix form is a very
common operation for vegan, labdsv, and other vegetation packages.  Thus,
you could build the list of 4 matrices with something like:

ciliates <- list(
                     M1 = labdsv::matrify(d1),
                     M2 = labdsv::matrify(d2),
                     M3 = labdsv::matrify(d3),
                     M4 = labdsv::matrify(d4)
                    )

Tom



On Thu, Jun 20, 2019 at 11:35 AM Law, Jason <Jason.Law at portlandoregon.gov>
wrote: