Learn R Programming

dyn (version 0.2-0)

dyn: dynamic regression class

Description

dyn is constructs objects of class "dyn",

Usage

dyn(x)

Arguments

x
an object, typically a "formula" object or an object produced by "lm", "glm" or other regression function.

Value

  • "dyn" returns its argument with the class name "dyn" prepended to its class vector. The "fitted", "residuals" and "predict" "dyn" methods return time series of the appropriate class. "model.frame" creates a model frame with an attribute of "series" that contains a data frame of the time series and factor variables as columns.

concept

dynamic regression

Details

"dyn" enables regression functions that were not written to handle time series to so handle them. The time series need not have the same indexes (the are automatically intersected) and may have missing values including internal missing values. "dyn" creates a dynamic regression object by returning x with the "dyn" class name prepended to the class of the argument. If the argument to "dyn" is a formula its variables may be time series objects of one of the following classes: "ts", "irts", code{"its"}, "zoo" or "zooreg". "dyn" methods are available for "model.frame", "fitted", "residuals", "predict", "update", "anova" and "$". These methods preprocess their arguments, call the real method which does the actual work and then post process the returned object. In the case of "fitted", "residuals" and "predict" they ensure that the result is a time series. In the case of anova the objects are intersected so that they all have the time indexes to ensure that a meaningful input is provided to "anova". The $ method is always used with a left argument of "dyn" like this "dyn$lm(x, ...)". This expression is equivalent to "dyn(lm(dyn(x), ...))" but is more convenient to write. "dyn" currently works with any regression function that makes use of "model.frame" and is written in the style of "lm". This includes "lm", "glm", "loess", "rlm" (from "MASS"), "lqs" (from pkg{"MASS"}), "randomForest" (from "randomForest"), "rq" (from "quantreg") and likely others.

See Also

See Also model.frame, predict, fitted, residuals, anova, update, lm, glm, loess

Examples

Run this code
y <- ts(1:12, start = c(2000,2), freq = 4)^3
x <- ts(1:9, start = c(2000,3), freq = 4)^2

# can be used with numerous different regression functions
y.lm <- dyn$lm( window(y, start = c(2000,4)) ~ diff(x) )
y.lm <- dyn$lm( y ~ diff(x) )
y.glm <- dyn$glm( y ~ diff(x) )
y.loess <- dyn$loess( y ~ diff(x) )

y.lm <- dyn(lm(dyn(y ~ diff(x))))  # same
y.lm
summary(y.lm)
residuals(y.lm)
fitted(y.lm)
y2.lm <- update(y.lm, . ~ . + lag(x))
y2.lm
anova(y.lm, y2.lm)

# examples of using data
dyn$lm(y ~ diff(x), list(y = y, x = x))
dyn$lm(y ~ diffx, list(y = y, diffx = diff(x)))

# invoke model.frame on formula as a dyn object
dyn$model.frame( y ~ diff(x) )

Run the code above in your browser using DataLab