ctmm-initiative / ctmmweb

Web app for analyzing animal tracking data, built upon ctmm R package
http://biology.umd.edu/movement.html
GNU General Public License v3.0
32 stars 21 forks source link

Overlap #36

Closed NoonanM closed 4 years ago

NoonanM commented 6 years ago

Are there any plans to implement the overlap() function? My guess is a lot of users would want to use this function for subsequent analyses and it would be good to provide the option within the app.

xhdong-umd commented 6 years ago

@chfleming @jmcalabrese What's the work flow you have in mind?

I saw overlap can be applied to A list of ctmm fit, telemetry, or aligned UD objects. So it can be

There could be a button in each page, or one button to generate all available overlaps for current selected individuals/models/home ranges etc.

The result will be just some tables. How do you want to use the result for subsequent analyses?

chfleming commented 6 years ago

You want the UD overlap only for now, after home range-analysis.

If you calculate all of the UDs on the same grid by feeding them all into akde() at once, then you can more quickly calculate UD overlap from the existing UD objects (+ fit object argument).

NoonanM commented 6 years ago

Most appropriate would probably be an 'Overlap' tab since it's a tangential analysis that people don't have to do, but many will probably want to. But I leave that choice to @chfleming and @jmcalabrese.

My guess is users wanting to estimate overlap will generally use all individuals included in the Home Range tab.

Output is three matrices. I've found visualizing them via the attached ggplot script to be a useful way of quickly seeing what's happening. BC is an object output from overlap()

`dis <- as.matrix(BC[,,2]) #This one plots the point estimate [,,1] and [,,3] are the CIs

dis[upper.tri(dis, diag = FALSE)] <- NA

dis <- data.table::melt(dis, na.rm = TRUE) dis$value <- log(dis$value) #Usually have to log scale to make the colors stand out more

ggplot(dis, aes(Var1,Var2, fill=value)) + geom_tile(color = "black") + theme_bw()+ theme(panel.grid.minor = element_blank(), panel.border = element_blank(), axis.text.y = element_text(size=6, hjust=1, vjust = 0, family = "serif"), axis.title.y = element_blank(), axis.ticks.y = element_blank(), axis.title.x = element_blank(), axis.text.x = element_text(angle=90, size=6, hjust=1, vjust = 0, family = "serif"), legend.background = element_blank(), legend.text = element_text(size=4), legend.key.size = unit(0.4, "cm"), legend.title=element_blank()) + viridis::scale_fill_viridis(na.value = '#440154FF')`

Distances.pdf

If you could have a set up where the user can click on a tile that looks interesting, and they would see the two (or more?) UDs plotted together my guess is many users would find that useful.

xhdong-umd commented 6 years ago

I'm working on maps now, probably will revisit this after maps are finished.

NoonanM commented 6 years ago

@xhdong-umd That's fine. We are currently working on the paper that will accompany the overlap() function. Ideally we would have the two come out around the same time (app functionality and paper), but the paper is still a few months away from publication so there is plenty of time.

xhdong-umd commented 6 years ago

@NoonanM @chfleming I haven't read the full paper yet. Based on the help of overlap and discussions above

For the representation of overlap results

I'll also explore some variations and compare the results.

NoonanM commented 6 years ago

When plotting the matrix, in addition to the concentric circle style that @chfleming suggested, we can also make use of the two halves of the matrix to include more information as in this example:

corr_mixed

(This uses the corrplot.mixed() function from the corrplot package)

chfleming commented 6 years ago

circle

Here's a mock-up of what I was thinking, where the inner most circle radius would be the lower confidence interval, the middle circle radius would be the point estimate, and the outer circle radius would be the upper confidence interval.

xhdong-umd commented 6 years ago

I'm thinking to use color background in the numeric table, which can serve like the overview plot. And use 1 dimension plot instead of a 2-d grid, because the grid gives a pattern which does not exist.

I'll try a arranged bar chart and wrapped facet. 1-d plot is also easy to compare values.

xhdong-umd commented 6 years ago

This is the overview table. I plan to remove the duplicate half, use color background scaled to the value in the app.

screen shot 2018-01-25 at 11 45 25 am

And a plot with error bar for all unique combinations

screen shot 2018-01-25 at 11 44 53 am

point range version

screen shot 2018-01-25 at 11 52 15 am
xhdong-umd commented 6 years ago

I made these changes to the table, try to make it easier to read:

screen shot 2018-01-26 at 4 33 52 pm

Currently I'm using the animal name - model type because they are home ranges and are model specific. This make the names quite long but I can't find better alternatives.

xhdong-umd commented 6 years ago

@jmcalabrese @chfleming @NoonanM The basic parts of the overlap page are ready now.

The different views of the summary table

screen shot 2018-01-29 at 2 04 08 pm screen shot 2018-01-29 at 2 04 23 pm

The plot of the value range for each combination

screen shot 2018-01-29 at 2 04 30 pm

The location tab will show the animal locations plot.

I'm trying to add interactivity among the table and plots for now:

xhdong-umd commented 6 years ago

I found this version of summary table is better than the 2d matrix table above:

screen shot 2018-01-30 at 5 01 37 pm

I updated the app and included both versions of summary table so you can play with it and compare them.

xhdong-umd commented 6 years ago

@jmcalabrese @chfleming If we simplify the model name to just animal name when there is no conflict, should we also change the variogram/home range plot title from the animal - model type full name to just animal name?

xhdong-umd commented 6 years ago

I found both the overlap result matrix names and the home range plot titles come from the names of the home range list, they need to be consistent.

I have made them to be animal names only when there is no duplicates, and change to full names when there are multiple models from same animal.

In the other hand, the modeled variogram plot title is still full names with model part now. It can be changed, but I'm wondering maybe it make sense to include model name in this plot?

xhdong-umd commented 6 years ago

I also need to change the map part, because there are layers of animal locations and home ranges. Previously the location layer name is animal name, home range layer name is id - model type full name.

screen shot 2018-02-01 at 12 01 17 pm

Now there will be conflicts if we just use animal name for home ranges when there is no duplicate.

Option 1: change the home range layer name to

Option 2 is still use the previous setup in maps:

xhdong-umd commented 6 years ago

I took option 1 as it is easier to read in simple cases.

screen shot 2018-02-01 at 12 22 34 pm
xhdong-umd commented 6 years ago

Sorting table and plot at the same time is also done.

When you input a word to filter the table, the plot also updates.

xhdong-umd commented 6 years ago

Previously I added a location plot tab in overlap page. Now I think maybe it's better to just use the map tab for this purpose.

screen shot 2018-02-01 at 2 15 44 pm

The only benefit from a separate location plot tab is that we can also make the location plot respond to selected overlaps thus highlight them. Though the map page also have layer selectors to check a subset only.

Should we just remove this tab?

chfleming commented 6 years ago

I think what most of us want on the location tab is that after selecting one row from the table, the location tab will show a plot of the two animal's locations and home ranges.

If multiple rows are selected, I suppose you could show a grid of plots.

xhdong-umd commented 6 years ago

Previously I planned to add some interactivity between the table and the value range plot:

Now with the sorting and filtering working, I think this is not really needed anymore. It's very easy to map from table to plot.

screen shot 2018-02-01 at 2 23 11 pm screen shot 2018-02-01 at 2 23 18 pm

Sorted

screen shot 2018-02-01 at 2 23 56 pm screen shot 2018-02-01 at 2 24 07 pm

Filtering

screen shot 2018-02-01 at 2 24 21 pm screen shot 2018-02-01 at 2 24 33 pm
xhdong-umd commented 6 years ago

I agree a group of plots of overlap pairs will be most helpful. Though we will need 15 plots for 6 animals, (n**2 - n)/2 for more animals.

Is this acceptable?

chfleming commented 6 years ago

I would only plot the selected pairs.

xhdong-umd commented 6 years ago

And my previous plan of two direction interactivity can cause a loop:

It should still doable, maybe with some additional refreshes.

It'll be much simpler if we only do one direction:

Is this enough?

xhdong-umd commented 6 years ago

For the variogram plot of models, should we use animal name only or the animal - model type as plot title?

chfleming commented 6 years ago

I don't think you would want to have one big plot, but zoomed in plots of the pairs. In many cases, individuals will be very spread out.

chfleming commented 6 years ago

I would only include the model name in cases where models are being compared.

xhdong-umd commented 6 years ago

I agree. So we will keep the location plot tab

xhdong-umd commented 6 years ago

I'm referring to this plot:

screen shot 2018-02-01 at 3 05 22 pm

It can be changed to similar arrangement of home range plot, i.e.

But I feel the current arrangement is somewhat useful to always show the model detail in this place.

chfleming commented 6 years ago

I think that's probably fine as is.

xhdong-umd commented 6 years ago

OK. I will work on the paired location plots.

Is one direction interactivity from table to plot enough? i.e. no "clicking on plot to highlight rows in table".

chfleming commented 6 years ago

I don't have a preference for the reverse direction. @jmcalabrese @NoonanM

xhdong-umd commented 6 years ago

Selecting table rows will change color of corresponding values in plot.

screen shot 2018-02-01 at 4 42 40 pm

It's difficult to have more specific non-default color mappings in ggplot.

I wanted to just keep non-selected values in blue point and red error bar, and change selected ones to other color. That means two separate color palette for point and error bar, which is quite difficult.

Hopefully the current state is good enough.

xhdong-umd commented 6 years ago

For the overlap summary table, do you want to sort by ML value descendingly by default?

chfleming commented 6 years ago

That makes sense to me.

xhdong-umd commented 6 years ago

I have finished the grouped location plot of overlap pairs, made the summary table sorted by default.

There is a brief error message in certain cases #48, I have to leave it as is now since I have spent several hours on it without success.

Previously we talked about "jump to home range page if user clicked overlap page directly". That turned out to be difficult because it's hard to determine whether the home range is available. It could be updating and not NULL. The only way to do that seemed to be maintain a page click history and check the history, then there could be multiple corner cases of different click combinations.

I think most user will not jump to overlap directly like what I did, so I'm leaving this as is now too.

Other than this two points, all discussed features above have been implemented. I have updated the app and you can try it out.

xhdong-umd commented 6 years ago

I managed to silent the warning and error messages for the special case. That should be enough because it only happened briefly then update to correct data automatically.

xhdong-umd commented 6 years ago

I have finished the help page for overlap, and is looking at the parallel functions for integration into ctmm now.

xhdong-umd commented 6 years ago

I'm experimenting with home range plots.

Here is location points and home range contours

plot(tele_list_sub3, UD = hrange_list_sub3, col = c("red", "blue"), labels = names(tele_list_sub3))

screen shot 2018-02-15 at 10 09 51 am

Without location points

plot(hrange_list_sub3, col.level = c("red", "blue"), labels = names(tele_list_sub3))

screen shot 2018-02-15 at 10 10 03 am

I'm not familiar with base plot, and I'm not sure how to customize these issues:

  1. The home range contour label is a little bit small and not obvious. A bigger font or bold should be better.

Here is another plot (there are 3 animals in plot while we only need plot of pairs, but I want to use this plot to show that when two animals are far away and stretched plot to bigger scale, it's even more difficult to read the labels.

screen shot 2018-02-15 at 10 13 38 am
  1. Maybe we should only draw one contour for each home range by default? Of course we can add an input to customize levels, just like the other pages.

  2. Should we remove the grid and density function to make the overlapped pair easy to read?

NoonanM commented 6 years ago

I would remove the grid for sure. I don't think it adds any additional information at this stage. I think it would also be good to change the color of the UDs for each individual.

I would also consider removing the labels on the confidence interval contours.

xhdong-umd commented 6 years ago

By color of the UDs do you mean the blue density in plot? I'm not sure if mixed colors in overlapped area will work well.

screen shot 2018-02-15 at 11 52 27 am

If we removed the labels on contours, we will need a color legend or some other label to show which is which.

NoonanM commented 6 years ago

Yes that's what I meant. I personally find the different colours more informative. The information on the overlap estimate comes from the density estimate, so it's good to see where the high/low density regions for each animal are.

xhdong-umd commented 6 years ago

OK, actually we can make them all as options. By default all will be shown, user can toggle off some elements if they are too busy for a specific plot.

NoonanM commented 6 years ago

Yes, that makes sense. I think locations and labels off by default is the cleanest baseline option?

xhdong-umd commented 6 years ago

If we decide to use a color legend in case label is off, then maybe we can disable label all together, since the current label font is too small/fade anyway.

NoonanM commented 6 years ago

I think the legend option is a better idea.

xhdong-umd commented 6 years ago

I think we can use home range plot as default and put the current ggplot2 points plot into another tab. It could be a useful option, especially since the code is already there.

xhdong-umd commented 6 years ago

The legend for base plot is placed inside the plot region by default. If I draw both location points and home range contours, then add legend for them, the legend could take too much space and overlap with plot.

screen shot 2018-02-22 at 1 40 33 pm

(the plot above don't have points drawn yet)

It's possible to move the legend outside but the parameter often need manual tweaking depend on legend name lengths.

I'm inclined to just disable location points in this plot, which make the home range contour and density easier to read, and we have the ggplot point plot tab if user need to check the location points.

xhdong-umd commented 6 years ago

So I'm planning to just draw contour and densities, with a color legend.

screen shot 2018-02-22 at 4 00 58 pm

There is no need for controls of layers since we only have contours and densities, and they don't interfere with each other.

xhdong-umd commented 6 years ago

How should I remove the grids? I only saw col.grid, which is not really an option to turn it off unless I make some transparent color?