Skip to contents

Runs the metabolism model specified by the specs argument. Returns a fitted model.

Usage

metab(
  specs = specs(mm_name()),
  data = v(mm_data(NULL)),
  data_daily = v(mm_data(NULL)),
  info = NULL
)

Arguments

specs

a list of model specifications and parameters for a model. Although this may be specified manually (it's just a list), it is easier and safer to use specs to generate the list, because the set of required parameters and their defaults depends on the model given in the model_name argument to specs. The help file for specs lists the necessary parameters, describes them in detail, and gives default values.

data

data.frame (not a tbl_df) of input data at the temporal resolution of raw observations (unit-value). Columns must have the same names, units, and format as the default. The solar.time column must also have a timezone code ('tzone' attribute) of 'UTC'. See the 'Formatting data' section below for a full description.

data_daily

data.frame containing inputs with a daily timestep. See the 'Formatting data_daily' section below for a full description.

info

any information, in any format, that you would like to store within the metab_model object

Value

An object inheriting from metab_model and containing the fitted model. This object can be inspected with the functions in the

metab_model_interface.

Formatting data

Unit-value model inputs passed via the data argument should be formatted as a data.frame with column names and values that depend on the model type, as follows. (If all columns are optional, data may equal NULL.)

mle or night

colnameclassunitsneed
solar.timePOSIXct,POSIXtrequired
DO.obsnumericmgO2 L^-1required
DO.satnumericmgO2 L^-1required
depthnumericmrequired
temp.waternumericdegCrequired
lightnumericumol m^-2 s^-1required
dischargenumericm^3 s^-1optional

Example:

solar.time DO.obsDO.satdepthtemp.waterlightdischarge
2050-03-14 15:10:0010.1 14.2 0.5 21.8 300.99

bayes

colnameclassunitsneed
solar.timePOSIXct,POSIXtrequired
DO.obsnumericmgO2 L^-1required
DO.satnumericmgO2 L^-1required
depthnumericmrequired
temp.waternumericdegCrequired
lightnumericumol m^-2 s^-1required
dischargenumericm^3 s^-1optional

Example:

solar.time DO.obsDO.satdepthtemp.waterlightdischarge
2050-03-14 15:10:0010.1 14.2 0.5 21.8 300.99

Kmodel

colnameclassunitsneed
solar.timePOSIXct,POSIXtoptional
dischargenumericm^3 s^-1optional
velocitynumericm s^-1optional

Example:

solar.time dischargevelocity
2050-03-14 15:10:009 2

sim

colnameclassunitsneed
solar.timePOSIXct,POSIXtrequired
DO.obsnumericmgO2 L^-1optional
DO.satnumericmgO2 L^-1required
depthnumericmrequired
temp.waternumericdegCrequired
lightnumericumol m^-2 s^-1required

Example:

solar.time DO.obsDO.satdepthtemp.waterlight
2050-03-14 15:10:0010.1 14.2 0.5 21.8 300.9

Formatting data_daily

Daily-value model inputs passed via the data_daily argument should be formatted as a data.frame with column names and values that depend on the model type, as follows. (If all columns are optional, data_daily may equal NULL.)

night

NULL

mle

colnameclassunitsneed
dateDateoptional
K600.dailynumericd^-1optional
init.GPP.dailynumericgO2 d^-1 m^-2optional
init.PmaxnumericgO2 d^-1 m^-2optional
init.alphanumericgO2 s d^-1 umol^-1optional
init.ER.dailynumericgO2 d^-1 m^-2optional
init.ER20numericgO2 d^-1 m^-2optional
init.K600.dailynumericd^-1optional

Example:

date K600.dailyinit.GPP.dailyinit.Pmaxinit.alphainit.ER.dailyinit.ER20init.K600.daily
2050-03-1410 5 10 1e-04 -10 -10 10

bayes

colnameclassunitsneed
dateDateoptional
discharge.dailynumericm^3 s^-1optional

Example:

date discharge.daily
2050-03-149

Kmodel

colnameclassunitsneed
dateDaterequired
K600.dailynumericd^-1required
K600.daily.lowernumericd^-1optional
K600.daily.uppernumericd^-1optional
discharge.dailynumericm^3 s^-1optional
velocity.dailynumericm s^-1optional

Example:

date K600.dailyK600.daily.lowerK600.daily.upperdischarge.dailyvelocity.daily
2050-03-1410 4.5 15.6 9 2

sim

colnameclassunitsneed
dateDateoptional
discharge.dailynumericm^3 s^-1optional
DO.mod.1numericmgO2 L^-1optional
K600.dailynumericd^-1optional
GPP.dailynumericgO2 d^-1 m^-2optional
PmaxnumericgO2 d^-1 m^-2optional
alphanumericgO2 s d^-1 umol^-1optional
ER.dailynumericgO2 d^-1 m^-2optional
ER20numericgO2 d^-1 m^-2optional
err.obs.sigmanumericmgO2 L^-1optional
err.obs.phinumericoptional
err.proc.sigmanumericgO2 d^-1 m^-2optional
err.proc.phinumericoptional

Example:

date discharge.dailyDO.mod.1K600.dailyGPP.dailyPmaxalphaER.dailyER20err.obs.sigmaerr.obs.phierr.proc.sigmaerr.proc.phi
2050-03-149 7.5 10 5 10 1e-04-10 -10 0.01 0 5 0

Author

Alison Appling

Examples

dat <- data_metab(num_days='3')

# fit a basic MLE model
mm <- metab(specs(mm_name('mle')), data=dat, info='my info')
predict_metab(mm)
#>         date      GPP GPP.lower GPP.upper        ER  ER.lower  ER.upper
#> 1 2012-09-18 2.812955  2.435230  3.190680 -2.103521 -2.410113 -1.796930
#> 2 2012-09-19 3.277526  2.866958  3.688094 -2.470115 -2.808856 -2.131375
#> 3 2012-09-20 2.582700  2.313734  2.851666 -1.709653 -1.914700 -1.504606
#>   msgs.fit warnings errors
#> 1                         
#> 2      W                  
#> 3                         
get_info(mm)
#> [1] "my info"
get_fitting_time(mm)
#>    user  system elapsed 
#>   2.175   0.042   2.225 

# with chaining & customization
library(dplyr)
#> ------------------------------------------------------------------------------
#> You have loaded dplyr after unitted - this is likely to cause problems.
#> If you need functions from both dplyr and unitted, please load dplyr first, then unitted:
#> library(dplyr); library(unitted)
#> ------------------------------------------------------------------------------
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
mm <- mm_name('mle', ode_method='euler') %>%
  specs(init.GPP.daily=40) %>%
  metab(data=dat)
predict_metab(mm)
#>         date      GPP GPP.lower GPP.upper        ER  ER.lower  ER.upper
#> 1 2012-09-18 2.809444  2.402234  3.216654 -2.098404 -2.427638 -1.769169
#> 2 2012-09-19 3.271351  2.838930  3.703772 -2.463138 -2.818887 -2.107388
#> 3 2012-09-20 2.568592  2.286376  2.850807 -1.697389 -1.911571 -1.483207
#>   msgs.fit warnings errors
#> 1      W                  
#> 2      W                  
#> 3      W                  
if (FALSE) {
plot_DO_preds(predict_DO(mm))
plot_DO_preds(predict_DO(mm), y_var='pctsat', style='dygraphs')
}