Learn R Programming

dynamite (version 1.5.6)

lags: Add Lagged Responses as Predictors to Each Channel of a dynamite Model

Description

Adds the lagged value of the response of each channel specified via dynamiteformula() as a predictor to each channel. The added predictors can be either time-varying or time-invariant.

Usage

lags(k = 1L, type = c("fixed", "varying", "random"))

Value

An object of class lags.

Arguments

k

[integer()]
Values lagged by k units of time of each observed response variable will be added as a predictor for each channel. Should be a positive (unrestricted) integer.

type

[integer(1)]
Either "fixed" or "varying" which indicates whether the coefficients of the added lag terms should vary in time or not.

See Also

Model formula construction dynamite(), dynamiteformula(), lfactor(), random_spec(), splines()

Examples

Run this code
data.table::setDTthreads(1) # For CRAN
obs(y ~ -1 + varying(~x), family = "gaussian") +
  lags(type = "varying") + splines(df = 20)

# A two-channel categorical model with time-invariant predictors
# here, lag terms are specified manually
obs(x ~ z + lag(x) + lag(y), family = "categorical") +
  obs(y ~ z + lag(x) + lag(y), family = "categorical")

# The same categorical model as above, but with the lag terms
# added using 'lags'
obs(x ~ z, family = "categorical") +
  obs(y ~ z, family = "categorical") +
  lags(type = "fixed")

Run the code above in your browser using DataLab