Skip to contents

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

Usage

metab(
  specs = specs(mm_name()),
  data = mm_data(NULL),
  data_daily = 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

A data frame or tibble 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

A data frame or tibble 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().

Author

Alison Appling

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.obsnumericmgO₂ L⁻¹required
DO.satnumericmgO₂ L⁻¹required
depthnumericmrequired
temp.waternumeric°Crequired
lightnumericµmol m⁻² s⁻¹required
dischargenumericm³ s⁻¹optional

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.obsnumericmgO₂ L⁻¹required
DO.satnumericmgO₂ L⁻¹required
depthnumericmrequired
temp.waternumeric°Crequired
lightnumericµmol m⁻² s⁻¹required
dischargenumericm³ s⁻¹optional

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³ s⁻¹optional
velocitynumericm s⁻¹optional

Example:

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

sim

colnameclassunitsneed
solar.timePOSIXct,POSIXtrequired
DO.obsnumericmgO₂ L⁻¹optional
DO.satnumericmgO₂ L⁻¹required
depthnumericmrequired
temp.waternumeric°Crequired
lightnumericµmol m⁻² s⁻¹required

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⁻¹optional
init.GPP.dailynumericgO₂ m⁻² d⁻¹optional
init.PmaxnumericgO₂ m⁻² d⁻¹optional
init.alphanumericgO₂ s d⁻¹ µmol⁻¹optional
init.ER.dailynumericgO₂ m⁻² d⁻¹optional
init.ER20numericgO₂ m⁻² d⁻¹optional
init.K600.dailynumericd⁻¹optional

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³ s⁻¹optional

Example:

date discharge.daily
2050-03-149

Kmodel

colnameclassunitsneed
dateDaterequired
K600.dailynumericd⁻¹required
K600.daily.lowernumericd⁻¹optional
K600.daily.uppernumericd⁻¹optional
discharge.dailynumericm³ s⁻¹optional
velocity.dailynumericm s⁻¹optional

Example:

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

sim

colnameclassunitsneed
dateDateoptional
discharge.dailynumericm³ s⁻¹optional
DO.mod.1numericmgO₂ L⁻¹optional
K600.dailynumericd⁻¹optional
GPP.dailynumericgO₂ m⁻² d⁻¹optional
PmaxnumericgO₂ m⁻² d⁻¹optional
alphanumericgO₂ s d⁻¹ µmol⁻¹optional
ER.dailynumericgO₂ m⁻² d⁻¹optional
ER20numericgO₂ m⁻² d⁻¹optional
err.obs.sigmanumericmgO₂ L⁻¹optional
err.obs.phinumericoptional
err.proc.sigmanumericgO₂ m⁻² d⁻¹optional
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

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)
#> # A tibble: 3 × 10
#>   date         GPP GPP.lower GPP.upper    ER ER.lower ER.upper msgs.fit warnings
#>   <date>     <dbl>     <dbl>     <dbl> <dbl>    <dbl>    <dbl> <chr>    <chr>   
#> 1 2012-09-18  2.81      2.44      3.19 -2.10    -2.41    -1.80 """      
#> 2 2012-09-19  3.28      2.87      3.69 -2.47    -2.81    -2.13 "    W … ""      
#> 3 2012-09-20  2.58      2.31      2.85 -1.71    -1.91    -1.50 """      
#> # ℹ 1 more variable: errors <chr>
get_info(mm)
#> [1] "my info"
get_fitting_time(mm)
#>    user  system elapsed 
#>   0.763   0.000   0.763 

# with chaining & customization
library(dplyr)
#> 
#> 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)
#> # A tibble: 3 × 10
#>   date         GPP GPP.lower GPP.upper    ER ER.lower ER.upper msgs.fit warnings
#>   <date>     <dbl>     <dbl>     <dbl> <dbl>    <dbl>    <dbl> <chr>    <chr>   
#> 1 2012-09-18  2.81      2.40      3.22 -2.10    -2.43    -1.77 "    W … ""      
#> 2 2012-09-19  3.27      2.84      3.70 -2.46    -2.82    -2.11 "    W … ""      
#> 3 2012-09-20  2.57      2.29      2.85 -1.70    -1.91    -1.48 "    W … ""      
#> # ℹ 1 more variable: errors <chr>
plot_DO_preds(predict_DO(mm))

plot_DO_preds(predict_DO(mm), y_var = "pctsat", style = "dygraphs")