GotelliLab / EcoSimR

Repository for EcoSimR, by Gotelli, N.J. , Hart E. M. and A.M. Ellison. 2014. EcoSimR 0.1.0
http://ecosimr.org
Other
29 stars 10 forks source link

R code error implementing co-ocurrence models #73

Closed drcala closed 7 years ago

drcala commented 7 years ago

Hi!, I am trying to implement the co-ocurrence model for two binary datasets that I have. But when I am calling the "cooc_null_model" function, R gives me an error like this; "0%Error in speciesData[2, 1] : subscript out of bounds". Below I copied my code to illustrate the problem.

Thank you in advance

no_i<-read.csv("no invaded.csv", header = TRUE) inv<-read.csv("invaded.csv", header = TRUE)

media de la abundancia de cada sp en las parcelas no invadidas

row_weights_non<-rowMeans(no_i)

media de la abundancia de cada sp en las parcelas no invadidas

row_weights_inv<-rowMeans(inv)

col_weights<-rep(1, times=8)

myModel_inv<- cooc_null_model(speciesData="binary_in.csv", algo="sim10", suppressProg=TRUE, algoOpts = list(rowWeights=row_weights_inv,colWeights=col_weights))

ngotelli commented 7 years ago

Can you please send me one of the data sets that is throwing this error? Thanks.

drcala commented 7 years ago

binary_in.xlsx Thank you for your time

ngotelli commented 7 years ago

Looking quickly at your data set, I see several rows of zero, in which the species never occurs. That is probably what is throwing the error. Try deleting those rows and see if the analysis works.

drcala commented 7 years ago

The problem is that the file I sent you is the fragment of bigger one that has two types of plot in it. One with an invasive species as dominant and the other without this dominance. I am trying to analyse both types separately and see what results I have. But yes, I will do what you advice. There is no point of maintaining species that are not ocurring. Thank you

drcala commented 7 years ago

Hi again. I deleted the species that never occur and it is throwing the same error. It seems as I am asking to do something that is out of the boundaries of my data.

Thank you in advance

emhart commented 7 years ago

@drcala I'll take a look and see if I can track down what's throwing the error.

drcala commented 7 years ago

Ok, many thanks. Cheers

emhart commented 7 years ago

The error is actually due to how you're calling it. You're passing a string as the data matrix, not the actual object that you read in. You have to read the file "binary_in.csv" in to the matrix. It's giving you subscript out of bounds because it's expecting a dataframe, not a string (a string has no bounds). Here's an example based on the data you posted that worked for me....

testin <- read.csv("~/Documents/binary_in.csv",header=T,row.names = 1)
fixed_mat <- testin[apply(testin,1,sum) > 0,]

row_weights<-rowMeans(fixed_mat)
col_weights<-rep(1, times=6)

myModel_inv<- cooc_null_model(speciesData="fixed_mat", algo="sim10", suppressProg=TRUE,algoOpts = list(rowWeights=row_weights,colWeights=col_weights))

Here's my output:

> summary(myModel_inv)
Time Stamp:  Mon Nov  6 14:18:46 2017 
Reproducible:  FALSE 
Number of Replications:  1000 
Elapsed Time:  0.18 secs 
Metric:  c_score 
Algorithm:  sim10 
Observed Index:  0.98268 
Mean Of Simulated Index:  1.4734 
Variance Of Simulated Index:  0.045183 
Lower 95% (1-tail):  1.1225 
Upper 95% (1-tail):  1.8288 
Lower 95% (2-tail):  1.066 
Upper 95% (2-tail):  1.9118 
Lower-tail P =  0.014 
Upper-tail P =  0.986 
Observed metric > 14 simulated metrics 
Observed metric < 986 simulated metrics 
Observed metric = 0 simulated metrics 
Standardized Effect Size (SES):  -2.3088 
ngotelli commented 7 years ago

@emhart many thanks for quickly resolving this! @drcala I think you should be able to complete your analyses now, including the use of different indices with the EcoSim null models.

drcala commented 7 years ago

Oh Thank you @emhart !!! My bad! Now I see clearly what you mean. But what does the second line means? This one: fixed_mat <- testin[apply(testin,1,sum) > 0,] Many thanks

drcala commented 7 years ago

Oh, @emhart . I knew what you mean with the second line of the code. I already accounted for that issue because I deleted the rows (spp) that never occur. Thank you very much for your help