dataframe_DLM: Creating a DLM-Ready Dataframe

View source: R/dataframe_DLM.R

dataframe_DLMR Documentation

Creating a DLM-Ready Dataframe

Description

Transforms a dataframe to prepare it for distributed lag modelling.

Usage

dataframe_DLM(X, lag, dynamic_vars = NULL, arglag = list(fun = "bs"), ...)

Arguments

X

A dataframe, or something that can be coerced into one.

lag

Lag length of the dynamic variable. See crossbasis for more details.

dynamic_vars

The column name or indices that correspond to the longitudinal variables. If left missing, the dataset is not altered in any way and a warning is supplied.

arglag

A list that is passed into onebasis for generating a basis matrix for the lag space. See crossbasis.

...

Further arguments to be passed into the crossbasis function.

Details

The purpose of this function is to streamline the preperation of the data for distributed lag modelling in the case where every dynamic variable is handled the same way.

If no dynamic variables are given, the input dataframe is returned unaltered with a warning. Otherwise, the function returns a dataframe_DLM object, which is essentially treated like a standard dataframe but contains extra information to simplify the process of distributed lag modelling when using the NB_MCMC or QB_MCMC functions.

Value

The input is returned unchanged if no dynamic variables are given. Otherwise a dataframe_DLM object is returned. See details.

Author(s)

Daniel Dempsey (daniel.dempsey0@gmail.com)

Examples

X <- dplyr::select( dlnm::chicagoNMMAPS, c('cvd', 'dow', 'temp', 'dptp', 'o3') )
X <- na.omit( X )
arglag <- list( fun = 'bs', df = 4 )
DLM_dat <- dataframe_DLM( X, lag = 40, dynamic_vars =  c('temp', 'dptp', 'o3'), arglag = arglag )

DiscreteDLM documentation built on April 3, 2025, 6:19 p.m.