stuartWagenius / mateable

Tools to Assess Mating Potential in Space and Time
0 stars 4 forks source link

add Mahoro synchrony method #42

Open amywaananen opened 7 years ago

amywaananen commented 7 years ago

Not sure if this method is already included under a different name

swnordstrom commented 7 years ago

It looks like this method requires a different set of data than the other methods do (individuals with multiple floret and a start and end date for each floret). This would require a different type of scene object -- should we look into expanding the scene object to be more flexible with different datasets? I could see this used on Lea's dataset.

Another option is to try this method on a different scale, where instead of looking at an individual as one stem with multiple florets, we consider individual populations with multiple individual flowers. This could be used used for cross-population comparisons but there would be no way to compute the measure for a single population.

swnordstrom commented 7 years ago

If each individual has only one flowering head, then the Mahoro synchrony can be calculated, but it will just be y_i = (n_i - 1)/(n-1) where n_i is the number of individuals flowering on the same day that i flowers (this can be demonstrated by hand).

We can calculate the more interesting Mahoro synchrony when there is more than one floret/inflorescence per individual in one of two ways. One would be to create a mating scene where the florets (instead of the individuals) go in the "id" column of a mating scene object. I don't like this because then we'll probably lose individual-level information which is probably more interesting. The other way to calculate this is to change the mating scene object so that there was an inflorescence column as well as an "id" column.

The computational backbone of the a function to calculate the Mahoro distance for a single population is below. This just returns the synchrony values without doing any formatting, row-naming, error-handling, etc.

mahoro = function(scene) {

y = diag((1 / table(scene$id))) %% table(scene$id,scene$start) ybar = 0y

for (i in 1:nrow(y)) ybar[i,] = apply(y[-i,],2,mean)

mSync = 1 - .5*rowSums(abs(y - ybar))

return(mSync)

}