lags {dynamite}R Documentation

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"))

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.

Value

An object of class lags.

See Also

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

Examples

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")


[Package dynamite version 1.4.9 Index]