View source: R/lagTimeSeries.R
| lagTimeSeries | R Documentation |
Takes a multivariate time series and creates time-lagged columns for modeling. This generates one new column per lag and variable, enabling analysis of how past values influence current observations.
lagTimeSeries(
input.data = NULL,
response = NULL,
drivers = NULL,
time = NULL,
oldest.sample = "first",
lags = NULL,
time.zoom = NULL,
scale = FALSE
)
prepareLaggedData(
input.data = NULL,
response = NULL,
drivers = NULL,
time = NULL,
oldest.sample = "first",
lags = NULL,
time.zoom = NULL,
scale = FALSE
)
input.data |
a dataframe with one time series per column. Default: |
response |
character string, name of the numeric column to be used as response in the model. Default: |
drivers |
character vector, names of the numeric columns to be used as predictors in the model. Default: |
time |
character vector, name of the numeric column with the time. Default: |
oldest.sample |
character string, either "first" or "last". When "first", the first row taken as the oldest case of the time series and the last row is taken as the newest case, so ecological memory flows from the first to the last row of |
lags |
numeric vector, lags to be used in the equation, in the same units as |
time.zoom |
numeric vector of two values from the range of the |
scale |
boolean, if TRUE, applies the |
The function interprets the time column as an index representing the temporal position of each sample. It uses the lag function from the zoo package to shift columns by the specified lags, generating one new column per lag and variable.
A dataframe with columns representing time-delayed values of the drivers and the response. Column names have the lag number as a suffix. Has the attributes 'response' and 'drivers', later used by [computeMemory()].
Blas M. Benito <blasbenito@gmail.com>
computeMemory
Other data_preparation:
alignTimeSeries()
#loading data
data(palaeodata)
#adding lags
lagged.data <- lagTimeSeries(
input.data = palaeodata,
response = "pollen.pinus",
drivers = c("climate.temperatureAverage", "climate.rainfallAverage"),
time = "age",
oldest.sample = "last",
lags = seq(0.2, 1, by=0.2)
)
str(lagged.data)
# Check attributes (used by computeMemory)
attributes(lagged.data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.