| B | R Documentation |
'B()' acts as a backshift operator and creates lagged (past values) or lead (future values) versions of a variable for use in regression formulas. This function is designed to work within R formula syntax, similar to how 'I()' or 'log()' work.
B(x, k, ...)
x |
A numeric vector or time series variable to be lagged or lead |
k |
An integer specifying the lag order:
|
... |
Parameters passed to 'xregExpander()'. |
The function calls for the 'xregExpander()' to create lags/leads. So, you can pass additional parameters to it via ellipsis.
When 'k > 0' (lag), the function shifts values forward in time, so 'B(x, 1)' at time 't' contains the value of 'x' at time 't-1'.
When 'k < 0' (lead), the function shifts values backward in time, so 'B(x, -1)' at time 't' contains the value of 'x' at time 't+1'.
A numeric vector of the same length as 'x'. The missing values
are treated by the 'xregExpander()'. By default they are extrapolated
(gaps="auto").
,
xregExpander for data frame lag operations
lag for time series lag (different behavior)
# Create sample time series data
y = rnorm(10)
# Create lags
B(y, 1)
# Create leads
B(y, -1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.