conditional_var: Estimating conditional variance of a time series

View source: R/conditional_var.R

conditional_varR Documentation

Estimating conditional variance of a time series

Description

This function estimates the variance of a time series conditional on a set of other times series via additive models.

Usage

conditional_var(data, formula, family = c("Gamma", "lognormal"), fit_mean)

Arguments

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 conditional_mean

Details

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.

Value

The function returns an object of class "gam" as described in gamObject.

See Also

gam and ns.

Examples

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)

PuwasalaG/conduits documentation built on April 22, 2023, 3:40 p.m.