What are the advantages of using dynlm instead of LM?
The interface and internals of dynlm are very similar to lm , but currently dynlm offers three advantages over the direct use of lm: 1. extended formula processing, 2. preservation of time series attributes, 3. instrumental variables regression (via two-stage least squares).
Which is the default for K in dynlm?
The default for k is in both cases 1 . The specification of dynamic relationships only makes sense if there is an underlying ordering of the observations. Currently, lm offers only limited support for such data, hence a major aim of dynlm is to preserve time-series properties of the data.
Why do we need dynlm for dynamic regression?
The specification of dynamic relationships only makes sense if there is an underlying ordering of the observations. Currently, lm offers only limited support for such data, hence a major aim of dynlm is to preserve time-series properties of the data. Explicit support is currently available for “ts” and “zoo” series.
How does the predict function in dynlm work?
Without newdata argument, the predict function basically grabs model element from the dynlm output. With newdata argument predict tries to form new model matrix from newdata. Since this involves parsing formula supplied to dynlm and the formula has function L, which is defined only internaly in function dynlm, the incorrect model matrix is formed.
When to use trend y or trend y in dynlm?
Trends: y ~ trend (y) specifies a linear time trend where (1:n)/freq is used by default as the regressor. n is the number of observations and freq is the frequency of the series (if any, otherwise freq = 1 ). Alternatively, trend (y, scale = FALSE) would employ 1:n and time (y) would employ the original time index.
What to do when dependent variable is not included in newdata?
If you try to debug, you will see, that the lagged dependent variable is not being lagged in the case of newdata argument is supplied. What you can do is to lag the dependent variable and include it in the newdata. Here is the code illustrating this approach.