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
27 stars 10 forks source link

Minor error in plotting of sim9 results in #53

Closed ngotelli closed 9 years ago

ngotelli commented 9 years ago

There is one small fly left in the ointment:

  Fun.Alg <- sim9_single

When we use sim9 this fork calls in sim9_single to create a single random matrix for plotting. Unfortunately, however, sim9_single does not give a random matrix, it just gives a matrix that is a single step in the Markov chain removed from the original matrix. This is why there are only minor changes that show up in the simulated matrices (which you highlighted). For some matrices there may be no change at all because the randomly selected pair of rows in sim9_single don't contain any swappable elements.

We could correct this by adding the burn in to sim9_single, but that is incredibly slow and inefficient for large matrices to redo the entire thing just to get a single matrix out for plotting. What I would suggest is the following:

  1. When you create nullmodObj, add a new data structure to it: nullmodObj$Random.Matrix
  2. Place into this structure the last data matrix that is created by whatever algorithm you are using.
  3. Now for the plotting functions, use nullmodObj$speciesData and nullmodObj$Random.Matrix.

Now we don't need to awkwardly fork out a special exception for sim9. Regardless of what the simulation algorithm is, the object will always contain the matrix of the observed data (nullmodObj$speciesData) and one matrix of simulated data (nullmodObj$Random.Matrix). These are the two things we need to create the "cooc" plot. We also use them of course for all algorithms where there is a graphic type that shows the observed versus the simulated data. So this will work in niche overlap, size overlap, and all future modules.

It also seems cleaner to me because all of the simulating is done in only one place, and then we use the results of that simulation to calculate summary statsitics and create graphs.

Unfortunately, working with objects and classes is a bit above my R-skills, so I would be grateful if you could implement this. I do think we will need this in place before we release the package. About 98% of the co-occurrence simulations are made with sim9 (I will probably switch that to the default), and the current graph is going to raise eyebrows and cause people to suspect there is a flaw in the algorithm.

Thanks!

Nick