Mike
Mike

Reputation: 31

Rank Abundance Distribution on Character Matrix (Or Vector) in R

I've got a 1000x1000 matrix consisting of a random distribution of the letters a - z, and I need to be able to plot the data in a rank abundance distribution plot; however I'm having a lot of trouble with it due to a) it all being in character format, b) it being as a matrix and not a vector (though I have changed it to a vector in one attempt to sort it), and c) I seem to have no idea how to summarise the data so that I get species abundance, let alone then be able to rank it.

My code for the matrix is:

##Create Species Vector
species.b<-letters[1:26]


#Matrix creation (Random)
neutral.matrix2<- matrix(sample(species.b,10000,replace=TRUE),
                        nrow=1000,
                        ncol=1000)


##Turn Matrix into Vector
neutral.b<-as.character(neutral.matrix2)



##Loop
lo.op <- 2
neutral.v3 <- neutral.matrix2
neutral.c<-as.character(neutral.v3)

repeat {
  neutral.v3[sample(length(neutral.v3),1)]<-as.character(sample(neutral.c,1))
  neutral.c<-as.character(neutral.v3)
  lo.op <- lo.op+1

  if(lo.op > 10000) {
    break
  }
}

Which creates a matrix, 1000x1000, then replaces 10,000 elements randomly (I think, I don't know how to check it until I can check the species abundances/rank distribution).

I've run it a couple of times to get neutral.v2, neutral.v3, and neutral.b, neutral.c, so I should theoretically have two matrices/vectors that I can plot and compare - I just have no idea how to do so on a purely character dataset.

I also created a matrix of the two vectors:

abundance.matrix<-matrix(c(neutral.vb,neutral.vc),
      nrow=1000000,
      ncol=2)

As a later requirement is for sites, and each repeat of my code (neutral.v2 to neutral.v11 eventually) could be considered a separate site for this; however this didn't change the fact that I have no idea how to treat the character data set in the first place.

I think I need to calculate the abundance of each species in the matrix/vectors, then run it through either radfit (vegan) or some form of the rankabundance/rankabun plot (biodiversityR). However the requirements for those functions:

rankabundance(x,y="",factor="",level,digits=1,t=qt(0.975,df=n-1))

x Community data frame with sites as rows, species as columns and species abundance as cell values. y Environmental data frame. factor Variable of the environment

aren't available in the data I have, as for all intents and purposes I just have a "map" of 1,000,000 species locations, and no idea how to analyse it at all.

Any help would be appreciated: I don't feel like I've explained it very well though, so sorry about that!.

Upvotes: 0

Views: 566

Answers (1)

Richard Telford
Richard Telford

Reputation: 9923

I'm not sure exactly what you want, but this will summarise the data and make it into a data.frame for rankabundance

counts <- as.data.frame(as.list(table(neutral.matrix2)))
BiodiversityR::rankabundance(counts)

Upvotes: 1

Related Questions