Building better models with reactive applications

Models
Conservation
Communication
Apps make model development more rigourous, and more fun too
Author

Christina Buelow

Published

February 10, 2024

Early this year I sat down to start developing a mathematical model to inform the rates at which mangroves need to be protected and/or restored to achieve ecosystem service targets. I started with a simple schematic of the model - how will different coastal landscape states (e.g., protected forest vs. unprotected deforested areas) transition through time, and what processes cause these transitions?

For me, this often looks like chicken scratch…

Brainstorming and conceptualising…

Once I had the conceptual model, I started writing out the maths to model the transitions through time. Rather than doing this on paper, I chose to write it in Quarto so that I program the model as I was writing the maths.

Quarto is a nice tool that allows you to write markdown and make beautiful webpages very quickly that contain richly formatted text, program code, and code output (e.g., plots and graphs). It allowed me to set model parameters and test my model as I programmed it and visualise model output to make sure the model and code was working as expected. I planned to send a .html version of the doc to collaborators so that they could see exactly how the model was developed and what the expected outputs would be.

Screenshot of standard Quarto doc combinging images, text, code, and code output

Somewhere along the way, however, I started turning the Quarto doc into a shiny app. The main benefit of a shiny app over a standard Quarto doc was the ability to change all of the 20+ model parameters across their ranges, quickly re-run the model, and visualise the model output almost instantly. The shiny app is able to react to changes is model parameters, whereas the standard Quarto is not reactive (note however you can easily embed shiny apps in Quarto docs (which is what I did), or use ObservableJS so you don’t need to host the web app on a server).

Play with the app here

This turned out to be a really fun way to develop a model because I got to see what the model was doing every time I added something new. Also, because I was able to fully explore model outputs across the entire parameter space as I developed the model, I was able to more quickly discover and correct bugs.

I’m hoping the app will also become a tool for communicating with stakeholders, as now that it is a reactive web app, anyone can explore the model without needing programming software on their computer to run it.

Citation

BibTeX citation:
@online{buelow2024,
  author = {Buelow, Christina},
  title = {Building Better Models with Reactive Applications},
  pages = {undefined},
  date = {2024-02-10},
  url = {https://cabuelow.github.io/personal-website/posts/2024-02-10-apps-explore-models/},
  langid = {en}
}
For attribution, please cite this work as:
Buelow, Christina. 2024. “Building Better Models with Reactive Applications.” February 10, 2024. https://cabuelow.github.io/personal-website/posts/2024-02-10-apps-explore-models/.