View source: R/conditional_var.R
conditional_var | R Documentation |
This function estimates the variance of a time series conditional on a set of other times series via additive models.
conditional_var(data, formula, family = c("Gamma", "lognormal"), fit_mean)
data |
A tibble containing all the time series which are uniquely identified by the corresponding Timestamp. |
formula |
An object of class "formula": a symbolic description of the model to be fitted. The details of model specification are given under ‘Details’. |
family |
the family to be used in conditional variance model. Currently this can take either "Gamma" or "lognormal". |
fit_mean |
A GAM object return from |
Suppose $x_t$ is a time series where its
variance is a function of $z_t$. i.e. $Var(x_t|z_t) = v_x(z_t)$.
Then $v_x(z_t)$can be estimated via generalised
additive models (GAM). This function uses GAMs implemented
in mgcv
package to estimate the conditional variance
of a time series given a set of time series predictors.
The function returns an object of class
"gam" as described in gamObject
.
gam
and ns
.
data <- NEON_PRIN_5min_cleaned |>
dplyr::filter(site == "upstream") |>
dplyr::select(Timestamp, turbidity, level, conductance, temperature)
fit_mean <- data |>
conditional_mean(turbidity ~ s(level, k = 8) +
s(conductance, k = 8) + s(temperature, k = 8))
## Not run:
fit_var <- data |>
conditional_var(
turbidity ~ s(level, k = 7) + s(conductance, k = 7) + s(temperature, k = 7),
family = "Gamma",
fit_mean = fit_mean
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.