Learn R Programming

ARDL (version 0.2.3)

to_lm: Convert dynlm model (ardl, uecm, recm) to lm model

Description

Takes a dynlm model of class 'ardl', 'uecm' or 'recm' and converts it into an lm model. This can help using the model as a regular lm model with functions that are not compatible with dynlm models such as the predict function to forecast.

Usage

to_lm(object, ...)

Value

to_lm returns an object of class

"lm".

Arguments

object

An object of class 'ardl', 'uecm' or 'recm'.

...

Currently unused argument.

Author

Kleanthis Natsiopoulos, klnatsio@gmail.com

See Also

ardl, uecm, recm

Examples

Run this code
## Convert ARDL into lm ------------------------------------------------

ardl_3132 <- ardl(LRM ~ LRY + IBO + IDE, data = denmark, order = c(3,1,3,2))
ardl_3132_lm <- to_lm(ardl_3132)
summary(ardl_3132)$coefficients
summary(ardl_3132_lm)$coefficients

## Convert UECM into lm ------------------------------------------------

uecm_3132 <- uecm(ardl_3132)
uecm_3132_lm <- to_lm(uecm_3132)
summary(uecm_3132)$coefficients
summary(uecm_3132_lm)$coefficients

## Convert RECM into lm ------------------------------------------------

recm_3132 <- recm(ardl_3132, case = 2)
recm_3132_lm <- to_lm(recm_3132)
summary(recm_3132)$coefficients
summary(recm_3132_lm)$coefficients

## Use the lm model to forecast ----------------------------------------

# Forecast using the in-sample data
insample_data <- ardl_3132$model
head(insample_data)
predicted_values <- predict(ardl_3132_lm, newdata = insample_data)

# The predicted values are expected to be the same as the fitted values
ardl_3132$fitted.values
predicted_values

# Convert to ts class for the plot
predicted_values <- ts(predicted_values, start = c(1974,4), frequency=4)
plot(denmark$LRM, lwd=4) #The input dependent variable
lines(ardl_3132$fitted.values, lwd=4, col="blue") #The fitted values
lines(predicted_values, lty=2, lwd=2, col="red") #The predicted values

Run the code above in your browser using DataLab