1
votes

My data is a species co-occurrence matrix, I would like to generate randomized matrices in order to test co-occurence patterns.

The only function that I found for this type of analysis is the randomizeMatrix function in the R package picante. It works well, however the number of types of null models available in this function is limited.

Currently implemented null models (arguments to null.model):frequency(maintains species occurence frequency), richness (maintains sample species richness), independentswap and trialswap

Does anyone know of other functions or modifications to this function that will allow me to test other null models such as equiproabable or proportional column sums.

Here's how I'm using the function

> test <- matrix(c(1,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0),nrow=4,ncol=4)
> test
     [,1] [,2] [,3] [,4]
[1,]    1    0    1    0
[2,]    1    1    0    1
[3,]    0    0    0    0
[4,]    1    0    1    0
> randomizeMatrix(test,null.model = "richness",iterations = 1000)
     [,1] [,2] [,3] [,4]
[1,]    1    1    0    0
[2,]    1    1    0    1
[3,]    0    0    0    0
[4,]    0    1    0    1
> randomizeMatrix(test,null.model = "independentswap",iterations = 1000)
     [,1] [,2] [,3] [,4]
[1,]    1    0    1    0
[2,]    1    1    0    1
[3,]    0    0    0    0
[4,]    1    0    1    0
>

I run the function within a loop in order to get multiple iterations

Thank you in advance

1
have you looked at the vegan package ... ? If you post a more specific definition of what you're after, someone might just write it for you here (e.g., generating the equiprobability case sounds pretty easy). You might also ask on the [email protected] mailing list ... - Ben Bolker
Thank you for the suggestion. What I wanted was a way to have more control on the randomizations, that is set different options, equiprobable, proportional or fixed sum for rows and columns seperatley. I did manage to do it using another software but it would be nice to have the option available in R. - Anne Heloise Theo
Well, it can certainly be done in R, but you need to be much more precise/specific about what you want. Most R users are not community ecologists, but if you can define precisely the characteristics of the matrices you want that might help you get an answer. - Ben Bolker

1 Answers

0
votes

I wrote a function to generate a null, random matrix where each column's probabilities are different. This was for species occurrence matrices.

nullMatrix <- function(nrows, ncols, prob1) {
matrixVector <- c()
for(i in 1:ncols){
    columnVector <- sample(c(0,1), nrows, replace = T, prob = c((1-prob1[i]), prob1[i]))
    matrixVector <- c(matrixVector, columnVector)
}
matrix(matrixVector, nrow = nrows, ncol = ncols)
}

This generates a matrix of specified n rows and columns and a vector of the probability for being 1 for each row.

I tested it using the following code.

#generate probability vectore for column matrix, each 10 rows the probability increases by .1
p1 <- c(rep(.1, 10), rep(.2, 10), rep(.3, 10), rep(.4, 10), rep(.5, 10), rep(.6, 10), rep(.7, 10), rep(.8, 10), rep(.9, 10), rep(1, 10) )
#generate the matrix with the nullMatrix function
m1 <- nullMatrix(100, 100, p1)
#The average of every ten rows should roughly = .1, .2, ..., 1
sum(m1[,c(1:10)])/1000 #Should ~.1
sum(m1[,c(11:20)])/1000 #Should ~.2
sum(m1[,c(21:30)])/1000 #Should ~.3
sum(m1[,c(31:40)])/1000 #Should ~.4
sum(m1[,c(41:50)])/1000 #Should ~.5
sum(m1[,c(51:60)])/1000 #Should ~.6
sum(m1[,c(61:70)])/1000 #Should ~.7
sum(m1[,c(71:80)])/1000 #Should ~.8
sum(m1[,c(81:90)])/1000 #Should ~.9
sum(m1[,c(91:100)])/1000 #Should ~1

I'm a little late to the conversation, but hope this is helpful for someone.