makelags | R Documentation |
Create a lag matrix for a time series (or suite of time series) using given E
and tau values. Like in fitGP, either a data frame and column names or vectors/matrices
can be provided. Use forecast=TRUE
to generate a forecast matrix. Use
vtimestep=TRUE
to use the variable timestep method.
makelags(
data = NULL,
y,
pop = NULL,
E,
tau,
yname = NULL,
forecast = FALSE,
vtimestep = FALSE,
x = NULL,
time = NULL,
augment = FALSE,
Tdiff_max = NULL,
Tdiff_fore = NULL,
nreps = NULL,
append = FALSE
)
data |
A data frame, or matrix with named columns. |
y |
A vector containing a time series (usually the response variable).
Alternatively, a matrix or data frame where each column is a time series
(usually the response variable and covariates). In the case of multiple
time series, lags will be generated for each variable. If |
pop |
A vector of populations (optional, if not supplied defaults to 1
population). If |
E |
Embedding dimension. Required. |
tau |
Time delay. Required. |
yname |
Optional, name of the variable if |
forecast |
Produce a forecast matrix instead of the standard training/test matrix. |
vtimestep |
Use variable timestep method. |
x |
If using |
time |
Used to generate forecast time if |
augment |
If |
Tdiff_max |
If |
Tdiff_fore |
If |
nreps |
If |
append |
Return |
When using the standard (fixed timestep) method, the response variable and
covariates can all be input under y
, and lags will be generated for
all variables.
When using the variable timestep method, it is necessary to differentiate
between the response variable and covariates, as they are handled
differently. The response variable should go under y
and the
covariates should go under x
. The output matrix will include lags of
Tdiff (time difference).
An augmentation matrix for use with the variable timestep method can be
generated by setting vtimestep=TRUE
and augment=TRUE
. Under
default behavior, the augmentation matrix will include only the Tdiff
combinations observed in the original vtimestep matrix, up to nreps
.
If you supply a vector Tdiff_fore
, then the augmentation matrix will
include or all possible combinations of the Tdiff values supplied in
Tdiff_fore
, even if they weren't in the original vtimestep matrix,
up to nreps
.
If generating forecasts, the output matrix will include a column for
population if there is more than one, and will include a time column if
time
is supplied. The time increment is based on the minimum
difference between timepoints. If generating forecasts using the variable
timestep method, a vector of time units to forecast beyond the last timestep
can be provided under Tdiff_fore
.
A matrix with named columns, the appended number indicating the time lag. If
y
has named columns, named columns in the lag matrix will match. If
generating forecasts, the output matrix will include a column for
population if there is more than one, and will include a time column if
time
is supplied. If using the variable timestep method, the output matrix
will include lags of Tdiff (time difference).
set.seed(1)
yrand <- rnorm(20)
site <- rep(c("a","b"),each=10)
dfrand <- data.frame(firstvar=rnorm(20),secondvar=rnorm(20))
makelags(y=yrand,E=3,tau=1)
makelags(y=dfrand,E=2,tau=2)
makelags(y=dfrand,pop=site,E=2,tau=1)
makelags(y=yrand,pop=site,E=2,tau=3,forecast = TRUE, yname="SomeName",time=c(1:10,1:10))
dfrand2 <- cbind.data.frame(Time=c(1:10,1:10),Site=site,dfrand)
makelags(data=dfrand2, y=c("firstvar","secondvar"),pop="Site",E=2,tau=3)
makelags(data=dfrand2, y=c("firstvar","secondvar"),pop="Site",E=2,tau=3,
forecast = TRUE,time="Time")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.