prepareLaggedData.Rd
Takes a multivariate time series, where at least one variable is meant to be used as a response while the others are meant to be used as predictors in a model, and organizes it in time lags, generating one new column per lag and variable in the model.
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. |
---|---|
response | character string, name of the numeric column to be used as response in the model. |
drivers | character vector, names of the numeric columns to be used as predictors in the model. |
time | character vector, name of the numeric column with the time/age. |
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 of positive integers, lags to be used in the equation. Generally, a regular sequence of numbers, in the same units as |
time.zoom | numeric vector of two numbers of the |
scale | boolean, if TRUE, applies the |
A dataframe with columns representing time-delayed values of the drivers and the response. Column names have the lag number as a suffix. The response variable is identified in the output as "Response_0".
The function interprets the time
column as an index representing the
#loading data data(palaeodata) #adding lags lagged.data <- prepareLaggedData( 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), time.zoom=NULL, scale=FALSE ) str(lagged.data)#> 'data.frame': 3988 obs. of 19 variables: #> $ Response_0 : num 0 2.5 6.97 10.64 13.39 ... #> $ Response_0.2 : num 2.5 6.97 10.64 13.39 15.02 ... #> $ Response_0.4 : num 6.97 10.64 13.39 15.02 15.62 ... #> $ Response_0.6 : num 10.6 13.4 15 15.6 14.5 ... #> $ Response_0.8 : num 13.4 15 15.6 14.5 10.9 ... #> $ Response_1 : num 15 15.6 14.5 10.9 6 ... #> $ climate.temperatureAverage_0 : num 14.1 14.1 14 14 14 ... #> $ climate.temperatureAverage_0.2: num 14.1 14 14 14 14 ... #> $ climate.temperatureAverage_0.4: num 14 14 14 14 14 ... #> $ climate.temperatureAverage_0.6: num 14 14 14 14 14 ... #> $ climate.temperatureAverage_0.8: num 14 14 14 14 14 ... #> $ climate.temperatureAverage_1 : num 14 14 14 14 14 ... #> $ climate.rainfallAverage_0 : num 1.57 1.57 1.57 1.57 1.57 ... #> $ climate.rainfallAverage_0.2 : num 1.57 1.57 1.57 1.57 1.57 ... #> $ climate.rainfallAverage_0.4 : num 1.57 1.57 1.57 1.57 1.57 ... #> $ climate.rainfallAverage_0.6 : num 1.57 1.57 1.57 1.57 1.57 ... #> $ climate.rainfallAverage_0.8 : num 1.57 1.57 1.57 1.57 1.56 ... #> $ climate.rainfallAverage_1 : num 1.57 1.57 1.57 1.56 1.56 ... #> $ time : num 0.5 0.7 0.9 1.1 1.3 1.5 1.7 1.9 2.1 2.3 ...