Title: | Dynamic Simulation and Testing for Single-Equation ARDL Models |
---|---|
Description: | While autoregressive distributed lag (ARDL) models allow for extremely flexible dynamics, interpreting substantive significance of complex lag structures remains difficult. This package is designed to assist users in dynamically simulating and plotting the results of various ARDL models. It also contains post-estimation diagnostics, including a test for cointegration when estimating the error-correction variant of the autoregressive distributed lag model (Pesaran, Shin, and Smith 2001 <doi:10.1002/jae.616>). |
Authors: | Soren Jordan [aut, cre, cph], Andrew Q. Philips [aut] |
Maintainer: | Soren Jordan <[email protected]> |
License: | GPL (>=2) |
Version: | 0.1.11 |
Built: | 2025-02-16 05:02:08 UTC |
Source: | https://github.com/andyphilips/dynamac |
Take first difference of a series
dshift(x)
dshift(x)
x |
a series to be differenced |
dshift
assumes that the series are ordered, that there is no missing data, and that the time intervals are even
the differenced series
Soren Jordan and Andrew Q. Philips
x.var <- seq(0, 50, 5) d.x.var <- dshift(x.var) head(x.var) head(d.x.var)
x.var <- seq(0, 50, 5) d.x.var <- dshift(x.var) head(x.var) head(d.x.var)
Estimate autoregressive distributed lag models and simulate interesting values (if desired)
dynardl(formula, data = list(), lags = list(), diffs = c(), lagdiffs = list(), levels = c(), ec = FALSE, trend = FALSE, constant = TRUE, modelout = FALSE, noLDV = FALSE, simulate = FALSE, shockvar = list(), shockval = sd(data[[shockvar]], na.rm = T), time = 10, qoi = "mean", forceset = NULL, range = 20, burnin = 20, sims = 1000, sig = 95, expectedval = FALSE, fullsims = FALSE)
dynardl(formula, data = list(), lags = list(), diffs = c(), lagdiffs = list(), levels = c(), ec = FALSE, trend = FALSE, constant = TRUE, modelout = FALSE, noLDV = FALSE, simulate = FALSE, shockvar = list(), shockval = sd(data[[shockvar]], na.rm = T), time = 10, qoi = "mean", forceset = NULL, range = 20, burnin = 20, sims = 1000, sig = 95, expectedval = FALSE, fullsims = FALSE)
formula |
a symbolic description of the model to be estimated. ARDL models are estimated using linear regression |
data |
an optional data frame or list containing the the variables in the model |
lags |
a list of variables and their corresponding lags to be estimated |
diffs |
a vector of variables to be differenced. Only first differences are supported |
lagdiffs |
a list of variables to be included in lagged differences |
levels |
a vector of variables to be included in levels |
ec |
estimate model in error-correction form, (i.e., |
trend |
include a linear time trend. The default is |
constant |
include a constant. The default is |
modelout |
print the regression estimates in the console |
noLDV |
do not add a lagged dependent variable (LDV) to ARDL models when omitted in formula (special thanks to Hannes Datta). This is not recommended |
simulate |
simulate the reponse. Otherwise, just the regression model will be estimated. If |
shockvar |
the variable to be shocked in the counterfactual simulation. There is no default |
shockval |
the amount by which the |
time |
the time period in the simulation for the variable to be shocked |
qoi |
summarize the response of the dependent variable with the mean or the median. Although the default is |
forceset |
by default, in the simulations, variables in levels will be set to their means; variables in differences will be set to 0. Alternatively, users can set any variable in the model to a different value using a list in |
range |
the range of the simulation to be conducted |
burnin |
the number of time periods to disregard before recording the values. These do not include the |
sims |
the number of simulations to use in creating the quantities of interest (the response of the dependent variable). The default is 1000 |
sig |
the significance level (1 - |
expectedval |
if this is |
fullsims |
whether all of the raw simulations should be stored in the model object. These are required for some of the more advanced plotting functions, especially those that use the simulations to derive confidence intervals about the size of the period-over-period differences. The default is |
Estimate an auto-regressive distributed lag model. Moreover, enable a graphical interpretation of the results (through dynardl.simulation.plot
) by simulating the response of the dependent variable to shocks in one of the regressors, and enable the Pesaran, Shin, and Smith (2001) test for cointegration for error-correction models (through pssbounds
)
dynardl
should always return an estimated model. It may or may not be simulated, according to the user. But the relevant regression output, model residuals (which can be tested for autocorrelation), and simulated response (if created) are stored in a list if the model is assigned to an object
Soren Jordan and Andrew Q. Philips
# Using the inequality data from dynamac ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), ec = TRUE, simulate = FALSE) summary(ardl.model) # Adding a lagged difference of the dependent variable ardl.model.2 <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE) summary(ardl.model.2) # Does not work: levels and diffs must appear as a vector # ardl.model.3 <- dynardl(concern ~ incshare10 + urate, data = ineq, # lags = list("concern" = 1, "incshare10" = 1), # levels = list("urate" = 1), # diffs = list("incshare10" = 1, "urate" = 1), # lagdiffs = list("concern" = 1), # ec = TRUE, simulate = FALSE) ardl.model.3 <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), levels = c("urate"), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE)
# Using the inequality data from dynamac ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), ec = TRUE, simulate = FALSE) summary(ardl.model) # Adding a lagged difference of the dependent variable ardl.model.2 <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE) summary(ardl.model.2) # Does not work: levels and diffs must appear as a vector # ardl.model.3 <- dynardl(concern ~ incshare10 + urate, data = ineq, # lags = list("concern" = 1, "incshare10" = 1), # levels = list("urate" = 1), # diffs = list("incshare10" = 1, "urate" = 1), # lagdiffs = list("concern" = 1), # ec = TRUE, simulate = FALSE) ardl.model.3 <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), levels = c("urate"), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE)
dynardl
modelCombine all of the potential plots of a simulated response in a dynardl
model
dynardl.all.plots(x, type = "area", bw = FALSE, last.period = NULL, start.period = 1, tol = (abs(x$model$ymean) * 0.01), abs.errors = "none", ylim = NULL, xlab = NULL, ylab = NULL, ...)
dynardl.all.plots(x, type = "area", bw = FALSE, last.period = NULL, start.period = 1, tol = (abs(x$model$ymean) * 0.01), abs.errors = "none", ylim = NULL, xlab = NULL, ylab = NULL, ...)
x |
a |
type |
whether the plot should be an area plot ( |
bw |
should the colors be in black and white (for publication)? The default is |
last.period |
when deciding when to stop calculating the absolute value of the shocks to the dependent variable, you can specify a specific period in which to stop calculating absolute cumulative differences. Specify a |
start.period |
which period of the simulation to begin the plot with. You can view the equilibriating behavior of the dependent variable, or you can skip forward in time (maybe to just before the shock). The default is |
tol |
when deciding when to stop calculating the absolute value of the shocks to the dependent variable, you can specify the minimum amount of movement required to qualify as a non-noise change over time periods (for calculating absolute cumulative differences). The default is 0.1 percent of the mean of the dependent variable. Specify a |
abs.errors |
when calculating confidence for the absolute cumulative effect, should differences accumulate in each time time period ( |
ylim |
a user-defined y-limit to be used instead of the default (for instance, for shared axes. Use caution, as it will be passed to all plots) |
xlab |
a user-defined x-label to be used instead of the default (use caution, as it will be passed to all plots) |
ylab |
a user-defined y-label to be used instead of the default (use caution, as it will be passed to all plots) |
... |
other arguments to be passed to the call to plot. Use caution, as they will be passed to all plots |
When running dynardl
, simulate
must be TRUE
so that there is a simulation to plot. Also, fullsims
must be TRUE
as the plot will contain absolute cumulative differences. See dynardl.simulation.plot
for arguments to the individual plotting types
a 2 x 3 grid of the plots of the simulated dynardl model effects plots
Soren Jordan and Andrew Q. Philips
# Using the ineq data in dynamac # Shocking Income Top 10 set.seed(1) ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = TRUE, range = 30, shockvar = "incshare10", fullsims = TRUE) # Shows all of the potential responses dynardl.all.plots(ardl.model) # Same plot, but with spikeplot dynardl.all.plots(ardl.model, type = "spike") # Grayscale plots dynardl.all.plots(ardl.model, bw = TRUE)
# Using the ineq data in dynamac # Shocking Income Top 10 set.seed(1) ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = TRUE, range = 30, shockvar = "incshare10", fullsims = TRUE) # Shows all of the potential responses dynardl.all.plots(ardl.model) # Same plot, but with spikeplot dynardl.all.plots(ardl.model, type = "spike") # Grayscale plots dynardl.all.plots(ardl.model, bw = TRUE)
dynardl
modelCreate a plot of a simulated response in a dynardl
model
dynardl.simulation.plot(x, type = "area", response = "levels", bw = FALSE, last.period = NULL, tol = (abs(x$model$ymean) * 0.01), start.period = 1, abs.errors = "none", ylim = NULL, ylab = NULL, xlab = NULL, ...)
dynardl.simulation.plot(x, type = "area", response = "levels", bw = FALSE, last.period = NULL, tol = (abs(x$model$ymean) * 0.01), start.period = 1, abs.errors = "none", ylim = NULL, ylab = NULL, xlab = NULL, ...)
x |
a |
type |
whether the plot should be an area plot ( |
response |
whether the plot of the response should be shown in levels of the dependent variable ( |
bw |
should the colors be in black and white (for publication)? The default is |
last.period |
when deciding when to stop calculating the absolute value of the shocks to the dependent variable, you can specify a specific period in which to stop calculating absolute cumulative differences. Specify a |
tol |
when deciding when to stop calculating the absolute value of the shocks to the dependent variable, you can specify the minimum amount of movement required to qualify as a non-noise change over time periods (for calculating absolute cumulative differences). The default is 0.1 percent of the mean of the dependent variable. Specify a |
start.period |
which period of the simulation to begin the plot with. You can view the equilibriating behavior of the dependent variable, or you can skip forward in time (maybe to just before the shock). The default is |
abs.errors |
when calculating confidence for the absolute cumulative effect, should differences accumulate in each time time period ( |
ylim |
a user-defined y-limit to be used instead of the default (for instance, for shared axes) |
ylab |
a user-defined y-label to be used instead of the default |
xlab |
a user-defined x-label to be used instead of the default |
... |
other arguments to be passed to the call to plot |
When running dynardl
, simulate
must be TRUE
so that there is a simulation to plot. For types cumulative.diffs
and cumulative.abs.diffs
, fullsims
must be TRUE
in the dynardl
simulation
a plot of the simulated dynardl model
Soren Jordan and Andrew Q. Philips
# Using the ineq data in dynamac # Shocking Income Top 10 set.seed(1) ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = TRUE, range = 30, shockvar = "incshare10", fullsims = TRUE) # Shows absolute levels dynardl.simulation.plot(ardl.model) # Shows changes from mean level dynardl.simulation.plot(ardl.model, response = "levels.from.mean") # Same plot, but with spikeplot dynardl.simulation.plot(ardl.model, type = "spike", response = "levels.from.mean") # Grayscale plots dynardl.simulation.plot(ardl.model, bw = TRUE)
# Using the ineq data in dynamac # Shocking Income Top 10 set.seed(1) ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = TRUE, range = 30, shockvar = "incshare10", fullsims = TRUE) # Shows absolute levels dynardl.simulation.plot(ardl.model) # Shows changes from mean level dynardl.simulation.plot(ardl.model, response = "levels.from.mean") # Same plot, but with spikeplot dynardl.simulation.plot(ardl.model, type = "spike", response = "levels.from.mean") # Grayscale plots dynardl.simulation.plot(ardl.model, bw = TRUE)
Data on GDP are from World Bank World Development Indicators. Data on energy consumption are from the PB Statistical Review of World Energy (June 2018).
data(france.data)
data(france.data)
A data frame with 53 rows and 4 variables:
Country
Year
ln(GDP), constant 2010 US dollars
ln(energy consumption), millions tons oil equivalent
A dataset from: Wright, Graham. 2017. "The political implications of American concerns about economic inequality." Political Behavior 40(2): 321-346.
data(ineq)
data(ineq)
A data frame with 49 rows and 9 variables:
Year
Public mood liberalism
Unemployment rate
Concern about economic inequality
Democratic control of congress
Proportion of income of top 10 percent
Consumer sentiment
Proportion of income of top 1 percent
http://dx.doi.org/10.7910/DVN/UYUU9G
Take the lagged first difference of a series
ldshift(x, l)
ldshift(x, l)
x |
a series to be differenced |
l |
the number of lags |
ldshift
assumes that the series are ordered, that there is no missing data, and that the time intervals are even
the lagged differenced series
Soren Jordan and Andrew Q. Philips
x.var <- runif(50) ld.1.x.var <- ldshift(x.var, 1) ld.2.x.var <- ldshift(x.var, 2) head(x.var) head(ld.1.x.var) head(ld.2.x.var)
x.var <- runif(50) ld.1.x.var <- ldshift(x.var, 1) ld.2.x.var <- ldshift(x.var, 2) head(x.var) head(ld.1.x.var) head(ld.2.x.var)
Take lag transformation of a series
lshift(x, l)
lshift(x, l)
x |
a series to be lagged |
l |
the number of lags |
lshift
assumes that the series are ordered, that there is no missing data, and that the time intervals are even
the lagged series
Soren Jordan and Andrew Q. Philips
x.var <- runif(50) l.1.x.var <- lshift(x.var, 1) l.2.x.var <- lshift(x.var, 2) head(x.var) head(l.1.x.var) head(l.2.x.var)
x.var <- runif(50) l.1.x.var <- lshift(x.var, 1) l.2.x.var <- lshift(x.var, 2) head(x.var) head(l.1.x.var) head(l.2.x.var)
Perform Pesaran, Shin, and Smith (2001) cointegration test
pssbounds(data = list(), obs = NULL, fstat = NULL, tstat = NULL, case = NULL, k = NULL, restriction = FALSE, digits = 3, object.out = FALSE)
pssbounds(data = list(), obs = NULL, fstat = NULL, tstat = NULL, case = NULL, k = NULL, restriction = FALSE, digits = 3, object.out = FALSE)
data |
an optional |
obs |
number of observations |
fstat |
F-statistic of the joint test that variables in first lags are equal to zero: the specific restriction tested
is |
tstat |
t-statistic of the lagged dependent variable |
case |
The case of the test, as per Pesaran, Shin, and Smith (2001). Case I: no intercept or trend; case II: restricted intercept, no trend; case III: unrestricted intercept with no trend; case IV: unrestricted intercept and restricted trend; case V: unrestricted intercept and trend. Case III is most frequently specified |
k |
number of regressors appearing in levels in the estimated model, not including the lagged dependent variable |
restriction |
if you design to test case II or IV of pssbounds, where it is assumed that the constant (case 2) or trend (case 4) are restricted in the resulting F-test, indicate that restriction = |
digits |
the number of digits to round to when showing output. The default is |
object.out |
if |
pssbounds performs post-estimation cointegration testing using the bounds testing procedure from Pesaran, Shin, and Smith (2001). Since test statistics vary based on the number of k
regressors, length of the series, these are required, in addition to F- and t-statistics
Soren Jordan and Andrew Q. Philips
# Using the ineq data from dynamac # We can get all the values by hand ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE) summary(ardl.model) pssbounds(obs = 47, fstat = 7.01578, tstat = -3.223, case = 3, k = 1) # Or just pass a dynardl model. pssbounds(ardl.model)
# Using the ineq data from dynamac # We can get all the values by hand ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE) summary(ardl.model) pssbounds(obs = 47, fstat = 7.01578, tstat = -3.223, case = 3, k = 1) # Or just pass a dynardl model. pssbounds(ardl.model)
dynardl
model objectsEnable summary calls to dynardl
model objects
## S3 method for class 'dynardl' summary(object, ...)
## S3 method for class 'dynardl' summary(object, ...)
object |
a |
... |
additional arguments in the generic summary call |
dynardl
, by default, stores regression results in foo$model
. This calls those results directly with summary
A summary of the fitted ARDL model.
Soren Jordan and Andrew Q. Philips
# Using the ineq data from dynamac ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE) summary(ardl.model)
# Using the ineq data from dynamac ardl.model <- dynardl(concern ~ incshare10 + urate, data = ineq, lags = list("concern" = 1, "incshare10" = 1), diffs = c("incshare10", "urate"), lagdiffs = list("concern" = 1), ec = TRUE, simulate = FALSE) summary(ardl.model)
A dataset from: Durr, Robert H., Andrew D. Martin, and Christina Wolbrecht. 2000. "Ideological divergence and public support for the Supreme Court." American Journal of Policial Science 44(4): 768-776.
data(supreme.sup)
data(supreme.sup)
A data frame with 42 rows and 9 variables:
Supreme Court support
Lagged Supreme Court spport
Ideological divergence
Mean deviation of Mood
Mean deviation of percent liberal decisions
Rulings against Solicitor General's amicus briefs
Laws declared unconstitutional
Approval of president
Approval of Congress
http://dx.doi.org/10.2307/2669280