lagData: Convert many-obs-per case data into lagged matrices

Description Usage Arguments Details Value Examples

View source: R/lag_data.R

Description

lagData creates two matrix variables: one with the lagged covariates, and a second with the indices used in the smooth term from mgcv.

Usage

1
lagData(lagData, response, unit, startUnit, nUnits, measure)

Arguments

lagData

data.frame or tibble containing the predictor variables to be created as lags. Must be sorted by Location, year, month.

response

data.frame or tibble with the response and one-per-case covariates

unit

character string variable name in lagData by which to lag

startUnit

integer where to start the lagging

nUnits

integer how many rows to lag backwards

measure

character string name of column in lagData to convert to matrices

Details

Assumes that lagData have already been aggregated to the appropriate resolution. lagData should have nrows(response)*nUnits - startUnit *not true.

Value

returns a dataframe or tibble with as many rows as response, and two new matrix columns

Examples

1
2
3
test <- lagData(env_data, response_data, unit = "month", 6, 24, "envVar")
dim(test$envVar_6_24)
test$lag_6_24[1:5,1:5]

atyre2/flmtools documentation built on Oct. 21, 2020, 5:26 a.m.