fit_metabolism: Fit stream metabolism models

View source: R/fit_metabolism.R

fit_metabolismR Documentation

Fit stream metabolism models

Description

Passes data and model parameters to streamMetabolizer or BASE according to arguments passed to prep_metabolism. NOTE: support for modeling with BASE is currently in development. Please use streamMetabolizer in the meantime.

Usage

fit_metabolism(
  d,
  pool_K600 = "binned",
  err_obs_iid = TRUE,
  err_proc_acor = FALSE,
  err_proc_iid = TRUE,
  ode_method = "trapezoid",
  deficit_src = "DO_mod",
  skip_prompts = FALSE
)

Arguments

d

the output of prep_metabolism.

pool_K600

character. Should the model pool information among days to get more consistent daily estimates for K600? Options (see Details section of streamMetabolizer's mm_name function for more):

  • none: no pooling of K600

  • binned: K600 ~ N(B[Q_bin], sigma) where mu ~ N(mu_mu, mu_sigma) and sigma ~ N(sigma_mu, sigma_sigma)

err_obs_iid

logical. Should IID observation error be included? If not, the model will be fit to the differences in successive DO measurements, rather than to the DO measurements themselves.

err_proc_acor

logical. Should autocorrelated process error (with the autocorrelation term phi fitted) be included?

err_proc_iid

logical. Should IID process error be included?

ode_method

character. The method to use in solving the ordinary differential equation for DO. Options:

  • euler, formerly Euler: the final change in DO from t=1 to t=2 is solely a function of GPP, ER, DO, etc. at t=1

  • trapezoid, formerly pairmeans: the final change in DO from t=1 to t=2 is a function of the mean values of GPP, ER, etc. across t=1 and t=2.

  • for type='mle', options also include rk2 and any character method accepted by ode in the deSolve package (lsoda, lsode, lsodes, lsodar, vode, daspk, rk4, ode23, ode45, radau, bdf, bdf_d, adams, impAdams, and impAdams_d; note that many of these have not been well tested in the context of streamMetabolizer models)

deficit_src

character. From what DO estimate (observed or modeled) should the DO deficit be computed? Options:

  • DO_mod: the DO deficit at time t will be (DO.sat(t) - DO_mod(t)), the difference between the equilibrium-saturation value and the current best estimate of the true DO concentration at that time

  • DO_obs: the DO deficit at time t will be (DO.sat(t) - DO.obs(t)), the difference between the equilibrium-saturation value and the measured DO concentration at that time

  • DO_obs_filter: applicable only to type='night': a smoothing filter is applied over the measured DO.obs values before applying nighttime regression

  • NA: applicable only to type='Kmodel', for which DO deficit is not estimated

skip_prompts

logical. If TRUE, you will not be prompted with questions about sending your model results to the StreamPULSE server. Prompting occurs in the event that your model outperforms the current best model stored by StreamPULSE for the site and year modeled. When skip_prompts is TRUE, your model results will never be pushed to the StreamPULSE server, unless there are no results currently stored for the site and year modeled. This parameter is useful when fitting models inside a loop.

Details

This function is a wrapper for streamMetabolizer's model specification, (mm_name, specs) fitting (metab), and prediction (predict_metab) functions, and all parameters except for d are streamMetabolizer parameters. Default arguments passed to this function specify the recommended starting point for fitting a metabolism model to data from a typical stream or river. In addition to the parameters documented here, this function calculates K600_lnQ_nodes_centers (parameter of streamMetabolizer's specs function) as a sequence of length 7 from the minimum to the maximum natural log of daily discharge.

To access the full model specification interface of streamMetabolizer, please call its corresponding functions (mm_name, specs, metab, predict_metab) directly. See the example section below for more.

Value

returns a list containing the output of streamMetabolizer's metab function (the model fit object), the output of streamMetabolizer's predict_metab function (metabolism predictions), and additional information about model performance and specifications.

Author(s)

Mike Vlah, vlahm13@gmail.com

Aaron Berdanier

See Also

request_data for acquiring StreamPULSE data; prep_metabolism for organizing data and acquiring additional variables.

Examples

query_available_data(region='all')

streampulse_data = request_data(sitecode='NC_Eno',
    startdate='2016-06-10', enddate='2016-10-23')

fitdata = prep_metabolism(d=streampulse_data, type='bayes',
    model='streamMetabolizer', interval='15 min',
    rm_flagged=list('Bad Data', 'Questionable'), fillgaps=fillgaps,
    zq_curve=list(sensor_height=NULL, Z=Z_data, Q=Q_data,
    fit='power', plot=TRUE), estimate_areal_depth=TRUE)

## fit model with default parameters
modelfit = fit_metabolism(fitdata)

## fit model with custom parameters
class(fitdata) = 'data.frame' #just a formality, execute and disregard
modname = mm_name(type='bayes', pool_K600='binned',
    err_obs_iid=TRUE, err_proc_acor=FALSE, err_proc_iid=TRUE,
    ode_method = 'trapezoid', deficit_src='DO_mod', engine='stan')
modspecs = specs(modname)

#overwrite default ln(Q) node centers
addis = tapply(log(fitdata$discharge), substr(fitdata$solar.time,1,10), mean)
modspecs$K600_lnQ_nodes_centers = seq(from=min(addis),
    to=max(addis), length.out=7)

modelfit = metab(specs=modspecs, data=fitdata)
predictions = predict_metab(modelfit)

streampulse/StreamPULSE documentation built on Nov. 2, 2024, 9:54 p.m.