metab_Kmodel | R Documentation |
Takes daily estimates of K, usually from nighttime regression, and regresses against predictors such as discharge.daily. Returns a metab_Kmodel object that only predicts daily K, nothing else.
metab_Kmodel(
specs = specs(mm_name("Kmodel")),
data = mm_data(solar.time, discharge, velocity, optional = c("all")),
data_daily = mm_data(date, K600.daily, K600.daily.lower, K600.daily.upper,
discharge.daily, velocity.daily, optional = c("K600.daily.lower", "K600.daily.upper",
"discharge.daily", "velocity.daily")),
info = NULL
)
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 |
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_daily |
data.frame containing inputs with a daily timestep. See the
'Formatting |
info |
any information, in any format, that you would like to store within the metab_model object |
Possible approaches:
"mean"Predict K as the mean of all K values
"weighted mean"Predict K as the mean of all K values, weighted by the inverse of the confidence intervals in the input K values
"KvQ"Regress K versus Q, tending toward overall mean in ranges of Q with sparse data
"weighted KvQ"Regress K versus Q, tending toward overall mean in ranges of Q with sparse data, weighting high-confidence K values more heavily
"T smoother"Predict K using a loess or spline smoother over time
"Q smoother"Predict K using a loess or spline smoother over discharge.daily
"TQ smoother"Predict K using a loess or spline smoother over both time and discharge.daily
A metab_Kmodel object containing the fitted model. This object can be
inspected with the functions in the metab_model_interface
.
Alison Appling
Other metab_model:
metab_bayes
,
metab_mle
,
metab_night
,
metab_sim
library(dplyr)
# create example data
set.seed(24842)
example_Ks <- data.frame(date=seq(as.Date("2012-08-15"),as.Date("2012-09-15"),
as.difftime(1,units='days')), discharge.daily=exp(rnorm(32,2,1)), K600.daily=rnorm(32,30,4)) %>%
mutate(K600.daily.lower=K600.daily-5, K600.daily.upper=K600.daily+6)
# mean
mm <- metab_Kmodel(
specs(mm_name('Kmodel', engine='mean')),
data_daily=example_Ks) # two warnings expected for engine='mean'
get_params(mm)
## Not run:
plot(get_params(mm)$date, get_params(mm)$K600.daily)
## End(Not run)
# linear model
mm <- metab_Kmodel(
specs(mm_name('Kmodel', engine='lm'), predictors='discharge.daily'),
data_daily=example_Ks)
get_params(mm)
## Not run:
plot(get_data_daily(mm)$discharge.daily, get_params(mm)$K600.daily)
## End(Not run)
# loess
mm <- metab_Kmodel( ### breaks ###
specs(mm_name('Kmodel', engine='loess'), predictors='date', other_args=list(span=0.4)),
data_daily=example_Ks)
get_params(mm)
## Not run:
plot(get_params(mm)$date, get_params(mm)$K600.daily)
## End(Not run)
## 3-phase workflow (sort of like complete pooling) for estimating K within
## days, then K across days, then GPP and ER within days
# 1. data and specifications for both of the MLE models
dat <- data_metab('10','15')
mle_specs <- specs(mm_name('mle'))
# fit a first-round MLE and extract the K estimates
mm1 <- metab_mle(mle_specs, data=dat)
K600_mm1 <- get_params(mm1, uncertainty='ci') %>%
select(date, K600.daily, K600.daily.lower, K600.daily.upper)
# smooth the K600s
mm2 <- metab_Kmodel(specs(mm_name('Kmodel', engine='mean'),
day_start=-1, day_end=23), data_daily=K600_mm1)
K600_mm2 <- get_params(mm2) %>% select(date, K600.daily)
# refit the MLE with fixed K
mm3 <- metab_mle(mle_specs, data=dat, data_daily=K600_mm2)
get_params(mm3, fixed='stars')
predict_metab(mm3)
## Not run:
plot_metab_preds(mm1)
plot_metab_preds(mm3)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.