#rstats adventures in the land of @rstudio shiny (apps)

Preamble
Colleagues and I had some sweet telemetry data, we did some simple models (& some relatively more complex ones too), we drew maps, and we wrote a paper. However, I thought it would be great to also provide stakeholders with the capacity to engage with the models, data, and maps. I published the data with a DOI, published the code at zenodo (& online at GitHub), and submitted paper to a journal. We elected not to pre-print because this particular field of animal ecology is not an easy place. My goal was to rapidly spin up some interactive capacity via two apps.

Adventures
Map app is simple but was really surprising once rendered. Very different and much more clear finding through interactivity. This was a fascinating adventure!
Model app exploring the distribution of data and the resource selection function application for this species confirmed what we concluded in the paper.

Workflow
Shiny app steps development flow is straightforward, and I like the logic!!
1. Use RStudio
2. Set up a shiny app account (free for up to 25hrs total use per month)
3. Set up a single r script with three elements
(i) ui
(ii) server
(iii) generate app (typically single line)
4. Click run app in RStudio to see it.
5. Test and play.
6. Publish (click publish button).

There is a bit more to it but not much more.

Rationale
A user interface makes it an app (haha), the server serves up the rstats or your work, and the final line generates app using shiny package. I could have an interactive html page published on GitHub and use plotly and leaflet etc, but I wanted to have the sliders and select input features more like a web app – because it is.

Main challenge to adventure was leaflet and reactive data
The primary challenge, adventure time style, was the reactive data calls and leaflet. If you have to produce an interactive map that can be updated with user input, you change your workflow a tiny bit.
a. The select input becomes an input$var that is in essence the name of vector you can use in your rstats code. So, this intuitive in conventional shiny app to me.
b. To take advantage of user input to render an updated map, I struggled a bit. You still use the input but want to filter your data to replot map. Novel elements include introducing a reactive function call to rewrite your dataframe in server chunk and then in leaflet first renderLeaflet map but them use an observe function to update the map with the reactive, i.e. user-defined, subset of the data. Simple in concept now that I get it, but it was still a bit tweaky to call specific elements from reactive data for mapping.

Summary
Apps from your work can illuminate patterns for others and for you.

Apps can provide a mechanism to interact with your models and see the best fits or outcomes in a more parallel, extemporary capacity

Apps are a gratifying mean to make statistics and data more accessible

Updates
Short-cut/parsimony coding: If you wrap your data script or wrangling into the renderPlot call, your data becomes reactive (without the formal reactive function).

The position of scripts is important – check this – numerous options where to read in data and this has consequences.

Also, consider modularizing your code.

Check out conditionalPanel function for customization across tabPanels. Tips in general here for shiny.

Controls, controls everywhere, and change continues nonetheless

Typically, everyone chases experimental treatments – i.e. direct interventions – as the fundamental means to advance science. We do something to one set of subjects whether plants, animals, or people, and we monitor the other set designated as controls.  The paper ‘Ambient changes exceed treatment effects on plant species abundance in global change experiments‘ very nicely shows that in many if not all natural systems, the ‘controls’ change too.  We cannot ignore the fact that natural ecosystems are changing just as rapidly and just as much due to global change and climate as the treatments we might test.
Solution – do the work and check!

Significant ‘developments’ this last few days associated with how we use lands #evidence #synthesis

This last week has been busy with numerous evidence syntheses highlighting that location, location, location and land use patterns are critical issues.

(1) ‘North American diets require more lands than we have’ was published in PLOS ONE and discussed widely. A compelling map of land spared showed little remains.

(2) On the other side of the coin, retiring lands because of water regulations, limitations, and drought are an opportunity for conservation and restoration was published in Ecosphere. Tools mapped for California studying three endangered animal species highlighted that we do know enough to begin to make evidence-based decisions for strategic retirement.

(3) A compelling map of how America uses land was published at Bloomberg.

(4) Hydraulic fracking is now being considered in the region used a case study for the retired land synthesis in #2 listed above including a map of proposed lands open for leasing.

Implications

(a) Scientific synthesis rapidly advances the big picture and both different synthesis tools (maps, systematic reviews, and ideally meta-analyses too) and syntheses with different purposes facilitate a more balanced weighting of issues. Even better, reproducible syntheses provided by different sets of stakeholders would elevate discussion and decision making.

(b) Agriculture, restoration, and energy development (both sustainable and non) must be better balanced through contrasted, transparently aggregated evidence.

(c) The ecological services and functions we get from lands ‘for free’ are precarious and precious.

(d) Whilst we cannot ignore human needs (and their likelihood of continued increases),  it is hard not to imagine that a buffer for other living creatures should also be factored into proposed land use trajectories.

(e) Ecology, socioeconomics, and other fields need to much more rapidly crunch current evidence because the clock is ticking.

 

Fix-it Facilitation: additional resources

A super fun process exploring how empirical contributions can reshape and embrace theory by addressing gaps in better designs and clear interpretations of findings.

Fix-it Felix: advances in testing plant facilitation as a restoration tool in Applied Vegetation Science.

The original contribution was longer with a more complete set of resources. Here is the full citation list that framed and supported the story and discussion.

Literature cited

Badano, E.I., Bustamante, R.O., Villarroel, E., Marquet, P.A. & Cavieres, L.A. 2015. Facilitation by nurse plants regulates community invasibility in harsh environments. Journal of Vegetation Science: 756-767.

Badano, E.I., Samour-Nieva, O.R., Flores, J., Flores-Flores, J.L., Flores-Cano, J.A. & Rodas-Ortíz, J.P. 2016. Facilitation by nurse plants contributes to vegetation recovery in human-disturbed desert ecosystems. Journal of Plant Ecology 9: 485-497.

Barney, J.N. 2016. Invasive plant management must be driven by a holistic understanding of invader impacts. Applied Vegetation Science 19: 183-184.

Bertness, M.D. & Callaway, R. 1994. Positive interactions in communities. Trends in Ecology and Evolution 9: 191-193.

Bronstein, J.L. 2009. The evolution of facilitation and mutualism. Journal of Ecology 97: 1160-1170.

Bruno, J.F., Stachowicz, J.J. & Bertness, M.D. 2003. Inclusion of facilitation into ecological theory. Trends in Ecology and Evolution 18: 119-125.

Bulleri, F., Bruno, J.F., Silliman, B.R. & Stachowicz, J.J. 2016. Facilitation and the niche: implications for coexistence, range shifts and ecosystem functioning. Functional Ecology 30: 70-78.

Callaway, R.M. 1998. Are positive interactions species-specific? Oikos 82: 202-207.

Chamberlain, S.A., Bronstein, J.L. & Rudgers, J.A. 2014. How context dependent are species interactions? Ecology Letters 17: 881-890.

Filazzola, A. & Lortie, C.J. 2014. A systematic review and conceptual framework for the mechanistic pathways of nurse plants. Global Ecology and Biogeography 23: 1335-1345.

Gomez-Aparicio, L., Zamora, R., Gomez, J.M., Hodar, J.A., Castro, J. & Baraza, E. 2004. Applying plant facilitation to forest restoration: a meta-analysis of the use of shrubs as nurse plants. Ecological Applications 14: 1128-1138.

Holmgren, M. & Scheffer, M. 2010. Strong facilitation in mild environments: the stress gradient hypothesis revisited. Journal of Ecology 98: 1269-1275.

James, J.J., Rinella, M.J. & Svejcar, T. 2012. Grass Seedling Demography and Sagebrush Steppe Restoration. Rangeland Ecology & Management 65: 409-417.

Lortie, C.J., Filazzola, A., Welham, C. & Turkington, R. 2016. A cost–benefit model for plant–plant interactions: a density-series tool to detect facilitation. Plant Ecology: 1-15.

Macek, P., Schöb, C., Núñez-Ávila, M., Hernández Gentina, I.R., Pugnaire, F.I. & Armesto, J.J. 2017. Shrub facilitation drives tree establishment in a semiarid fog-dependent ecosystem. Applied Vegetation Science.

Malanson, G.P. & Resler, L.M. 2015. Neighborhood functions alter unbalanced facilitation on a stress gradient. Journal of Theoretical Biology 365: 76-83.

McIntire, E. & Fajardo, A. 2011. Facilitation within species: a possible origin of group-selected superoorganisms. American Naturalist 178: 88-97.

McIntire, E.J.B. & Fajardo, A. 2014. Facilitation as a ubiquitous driver of biodiversity. New Phytologist 201: 403-416.

Michalet, R., Brooker, R.W., Cavieres, L.A., Kikvidze, Z., Lortie, C.J., Pugnaire, F.I., Valiente‐Banuet, A. & Callaway, R.M. 2006. Do biotic interactions shape both sides of the humped‐back model of species richness in plant communities? Ecology Letters 9: 767-773.

Michalet, R., Le Bagousse-Pinguet, Y., Maalouf, J.-P. & Lortie, C.J. 2014. Two alternatives to the stress-gradient hypothesis at the edge of life: the collapse of facilitation and the switch from facilitation to competition. Journal of Vegetation Science 25: 609-613.

Noumi, Z., Chaieb, M., Michalet, R. & Touzard, B. 2015. Limitations to the use of facilitation as a restoration tool in arid grazed savanna: a case study. Applied Vegetation Science 18: 391-401.

O’Brien, M.J., Pugnaire, F.I., Armas, C., Rodríguez-Echeverría, S. & Schöb, C. 2017. The shift from plant–plant facilitation to competition under severe water deficit is spatially explicit. Ecology and Evolution 7: 2441-2448.

Pescador, D.S., Chacón-Labella, J., de la Cruz, M. & Escudero, A. 2014. Maintaining distances with the engineer: patterns of coexistence in plant communities beyond the patch-bare dichotomy. New Phytologist 204: 140-148.

Rydgren, K., Hagen, D., Rosef, L., Pedersen, B. & Aradottir, A.L. 2017. Designing seed mixtures for restoration on alpine soils: who should your neighbours be? Applied Vegetation Science.

Sheley, R.L. & James, J.J. 2014. Simultaneous intraspecific facilitation and interspecific competition between native and annual grasses. Journal of Arid Environments 104: 80-87.

Silliman, B.R., Schrack, E., He, Q., Cope, R., Santoni, A., van der Heide, T., Jacobi, R., Jacobi, M. & van de Koppel, J. 2015. Facilitation shifts paradigms and can amplify coastal restoration efforts. Proceedings of the National Academy of Sciences 112: 14295-14300.

Stachowicz, J.J. 2001. Mutualism, facilitation, and the structure of ecological communities. Bioscience 51: 235-246.

von Gillhaussen, P., Rascher, U., Jablonowski, N.D., Plückers, C., Beierkuhnlein, C. & Temperton, V.M. 2014. Priority Effects of Time of Arrival of Plant Functional Groups Override Sowing Interval or Density Effects: A Grassland Experiment. PLoS ONE 9: e86906.

Went, F.W. 1942. The dependence of certain annual plants on shrubs in southern California deserts. Bulletin of the Torrey Botanical Club 69: 100-114.

Xiao, S. & Michalet, R. 2013. Do indirect interactions always contribute to net indirect facilitation? Ecological Modelling 268: 1-8.

Overdispersion tests in #rstats

A brief note on overdispersion

Assumptions

Poisson distribution assume variance is equal to the mean.

Quasi-poisson model assumes variance is a linear function of mean.

Negative binomial model assumes variance is a quadratic function of the mean.

rstats implementation

#to test you need to fit a poisson GLM then apply function to this model

library(AER)

dispersiontest(object, trafo = NULL, alternative = c(“greater”, “two.sided”, “less”))

trafo = 1 is linear testing for quasipoisson or you can fit linear equation to trafo as well

#interpretation

c = 0 equidispersion

c > 0 is overdispersed

Resources

  1. Function description from vignette for AER package.
  2. Excellent StatsExchange description of interpretation.