knitr::opts_chunk$set(echo = TRUE) options(width=100)
This vignette demonstrates a few of the options for relating GPP and ER to light and/or temperature.
Load streamMetabolizer and dplyr.
library(streamMetabolizer) library(dplyr)
Get some data to work with: here we're requesting three days of data at 15-minute resolution. Thanks to Bob Hall for the test data.
dat <- data_metab('3', '15')
Here's a basic model with GPP proportional to light and ER constant over time.
# the Classic: linear GPP, constant ER (also the default) mm_classic <- mm_name('mle', GPP_fun='linlight', ER_fun='constant') %>% specs() %>% metab(dat) mm_classic
Here's one where GPP is a saturating function of light. ER is still constant.
# the Saturator: GPP saturating with light, constant ER mm_saturator <- mm_name('mle', GPP_fun='satlight', ER_fun='constant') %>% specs() %>% metab(dat) mm_saturator
The Saturator produces fitting warnings, which are condensed to 'w' and a summary in the above print-out. They can be inspected in detail by looking directly at the fitted daily parameters:
get_params(mm_saturator) %>% select(date, warnings, errors)
Similary, you can inspect the warnings and errors that arise during prediction by pulling out the daily metabolism predictions (but there aren't any, so those columns are empty):
predict_metab(mm_saturator) %>% select(date, warnings, errors)
You can predict and/or plot instantaneous DO values from the fitted daily parameters.
predict_DO(mm_saturator) %>% head plot_DO_preds(mm_saturator)
Yep, that fitting warning on day 2 was meaningful! We can encourage the model toward a good fit by adjusting the initial values of Pmax and alpha from which the fitting function should explore likelihood space. There are two ways to do this - as date-specific values in data_daily, or as values that apply to every date in specs(). The two methods can even be combined.
mm_saturator2 <- mm_name('mle', GPP_fun='satlight', ER_fun='constant') %>% specs() %>% metab(dat, data_daily=select(get_params(mm_saturator), date, init.Pmax=Pmax, init.alpha=alpha)) get_params(mm_saturator2) mm_saturator3 <- mm_name('mle', GPP_fun='satlight', ER_fun='constant') %>% specs(init.Pmax=6.2, init.alpha=0.008) %>% metab(dat) get_params(mm_saturator3) mm_saturator4 <- mm_name('mle', GPP_fun='satlight', ER_fun='constant') %>% specs(init.Pmax=6.2, init.alpha=0.008) %>% metab(dat, transmute(get_params(mm_saturator), date, init.Pmax=Pmax[1], init.alpha=alpha[1])[2,]) get_params(mm_saturator4)
Despite the remaining warnings, DO predictions from the saturating GPP-light function do look better than from the classic model for this particular dataset.
plot_DO_preds(mm_classic) plot_DO_preds(mm_saturator4)
See the full list of available functions for gross primary productivity (GPP) and
ecosystem respiration (ER) in ?mm_name
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.