Title: | Parameter Estimation and Inference in a Cointegrating Regression |
---|---|
Description: | Cointegration methods are widely used in empirical macroeconomics and empirical finance. It is well known that in a cointegrating regression the ordinary least squares (OLS) estimator of the parameters is super-consistent, i.e. converges at rate equal to the sample size T. When the regressors are endogenous, the limiting distribution of the OLS estimator is contaminated by so-called second order bias terms, see e.g. Phillips and Hansen (1990) <DOI:10.2307/2297545>. The presence of these bias terms renders inference difficult. Consequently, several modifications to OLS that lead to zero mean Gaussian mixture limiting distributions have been proposed, which in turn make standard asymptotic inference feasible. These methods include the fully modified OLS (FM-OLS) approach of Phillips and Hansen (1990) <DOI:10.2307/2297545>, the dynamic OLS (D-OLS) approach of Phillips and Loretan (1991) <DOI:10.2307/2298004>, Saikkonen (1991) <DOI:10.1017/S0266466600004217> and Stock and Watson (1993) <DOI:10.2307/2951763> and the new estimation approach called integrated modified OLS (IM-OLS) of Vogelsang and Wagner (2014) <DOI:10.1016/j.jeconom.2013.10.015>. The latter is based on an augmented partial sum (integration) transformation of the regression model. IM-OLS is similar in spirit to the FM- and D-OLS approaches, with the key difference that it does not require estimation of long run variance matrices and avoids the need to choose tuning parameters (kernels, bandwidths, lags). However, inference does require that a long run variance be scaled out. This package provides functions for the parameter estimation and inference with all three modified OLS approaches. That includes the automatic bandwidth selection approaches of Andrews (1991) <DOI:10.2307/2938229> and of Newey and West (1994) <DOI:10.2307/2297912> as well as the calculation of the long run variance. |
Authors: | Philipp Aschersleben [aut, cre], Martin Wagner [aut] (Author of underlying MATLAB code.) |
Maintainer: | Philipp Aschersleben <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0.9000 |
Built: | 2024-11-07 03:26:18 UTC |
Source: | https://github.com/aschersleben/cointreg |
Parameter Estimation and Inference in a Cointegrating Regression
See the vignette:vignette("cointReg")
See the DESCRIPTION:help(package = cointReg)
See the README:
https://github.com/aschersleben/cointReg/blob/master/README.md
Open the package documentation page:package?cointReg
Further information and bug reporting:
https://github.com/aschersleben/cointReg
cointReg(method = c("FM", "D", "IM"), ...)
General function to estimate parameters of
the given model. Three methods are possible;
they can be choosen directly by using one of the following
functions:
cointRegFM
: Fully Modified OLS
cointRegD
: Dynamic OLS
cointRegIM
: Integrated Modified OLS
print
Print clear results.
plot
Plot the residuals of a cointReg
model.
Helper functions:
Checking inputs and arguments:checkObject
, checkVars
Calculation of bandwidth and long run variance:getBandwidth
, getBandwidthAnd
,
getBandwidthNW
getLongRunVar
, getLongRunWeights
Additional D-OLS functions:getLeadLag
, makeLeadLagMatrix
,
getModD
, checkDoptions
Checking the list D.options, that is an argument of
cointRegD
.
checkDoptions(n.lag = NULL, n.lead = NULL, kmax = c("k4", "k12"), info.crit = c("AIC", "BIC"))
checkDoptions(n.lag = NULL, n.lead = NULL, kmax = c("k4", "k12"), info.crit = c("AIC", "BIC"))
n.lag , n.lead
|
[ |
kmax |
[ |
info.crit |
[ |
[list
]. List with the checked and (if necessary)
converted arguments.
If one of n.lag
and n.lead
is
NULL
, only kmax
and info.crit
will be not NULL
.
Other check: checkObject
,
checkVars
checkDoptions(n.lag = 3, n.lead = 4) checkDoptions(info.crit = "BIC") checkDoptions() # It's not sufficient to include only one of "n.lag" and "n.lead": checkDoptions(n.lag = 2)
checkDoptions(n.lag = 3, n.lead = 4) checkDoptions(info.crit = "BIC") checkDoptions() # It's not sufficient to include only one of "n.lag" and "n.lead": checkDoptions(n.lag = 2)
Checking the variable and convert it for internal use, if necessary.
(Also used by the cointmonitoR
package.)
checkObject(obj, obj.name, ..., out = "return", .env)
checkObject(obj, obj.name, ..., out = "return", .env)
obj |
[ |
obj.name |
[ |
... |
[ |
out |
[ |
.env |
[ |
Possible values of obj.name
to check:
"y"
, "x.stat"
:Of type numeric
, matrix
or data.frame
.
Only the first row/column will be used.
Converted to object: column matrix
"y.fm"
, "x.coint"
, "deter"
:Of type numeric
, matrix
or data.frame
.
Converted to object: column matrix
"m"
:Of type numeric(1)
, has to be greater than 0.
"model"
:One of c("FM", "D", "IM")
.
"signif.level"
:Of type numeric(1)
, has to be in the interval [0.01, 0.1].
"trend"
, "return.stats"
, "return.input"
,
"demeaning"
, "t.test"
:Converted to object: logical(1)
.
"kernel"
:One of c("ba", "bo", "da", "pa", "qs", "th", "tr")
.
"bandwidth"
:One of c("and", "nw")
.
"selector"
:One or both c(1, 2)
.
The checked and converted argument is assigned to
the given environment (.env
) and/or returned (depending on the
argument out
).
Other check: checkDoptions
,
checkVars
x = matrix(1:20, nrow = 2) x2 = checkObject(x, "x.coint") x2 env = environment() y = 1:10 checkObject(y, out = "assign", .env = env) y # example for the use of the ... argument: det = rbind(1, 1:10) x3 = sin(10:20) det2 = checkObject(deter = det) det2 (checkObject(deter = det, x.stat = x3))
x = matrix(1:20, nrow = 2) x2 = checkObject(x, "x.coint") x2 env = environment() y = 1:10 checkObject(y, out = "assign", .env = env) y # example for the use of the ... argument: det = rbind(1, 1:10) x3 = sin(10:20) det2 = checkObject(deter = det) det2 (checkObject(deter = det, x.stat = x3))
Check the arguments and convert them for internal use, if necessary.
checkVars(..., out = "assign", .env)
checkVars(..., out = "assign", .env)
... |
[ |
out |
[ |
.env |
[ |
See checkObject
for details.
The checked and converted arguments are assigned to
the given environment (.env
) or invisibly returned as a list
.
Other check: checkDoptions
,
checkObject
env = environment() x.data = data.frame(a = 1:10, b = 20:11) y.data = 1:10 checkVars(x.coint = x.data, y = y.data, .env = env) x.coint y test = checkVars(x.coint = x.data, y = y.data, out = "return") str(test) # If the variables already have the "right" (= argument's) name, # there's no need to do something like # checkVars(kernel = kernel, bandwidth = bandwidth) - # just call checkVars without specifing the arguments: kernel = "q" bandwidth = "a" (checkVars(kernel, bandwidth, out = "return"))
env = environment() x.data = data.frame(a = 1:10, b = 20:11) y.data = 1:10 checkVars(x.coint = x.data, y = y.data, .env = env) x.coint y test = checkVars(x.coint = x.data, y = y.data, out = "return") str(test) # If the variables already have the "right" (= argument's) name, # there's no need to do something like # checkVars(kernel = kernel, bandwidth = bandwidth) - # just call checkVars without specifing the arguments: kernel = "q" bandwidth = "a" (checkVars(kernel, bandwidth, out = "return"))
Computes either the Phillips and Hansen (1990) Fully Modified OLS estimator, or the Saikkonen (1990) Dynamic OLS estimator, or the Vogelsang and Wagner (2014) Integrated Modified OLS estimator.
cointReg(method = c("FM", "D", "IM"), x, y, ...)
cointReg(method = c("FM", "D", "IM"), x, y, ...)
method |
[
|
x |
[ |
y |
[ |
... |
[
|
[cointReg
] object.
Phillips, P.C.B. and B. Hansen (1990): "Statistical Inference in Instrumental Variables Regression with I(1) Processes," Review of Economic Studies, 57, 99–125, DOI:10.2307/2297545.
Phillips, P.C.B. and M. Loretan (1991): "Estimating Long Run Economic Equilibria," Review of Economic Studies, 58, 407–436, DOI:10.2307/2298004.
Saikkonen, P. (1991): "Asymptotically Efficient Estimation of Cointegrating Regressions," Econometric Theory, 7, 1–21, DOI:10.1017/S0266466600004217.
Stock, J.H. and M.W. Watson (1993): "A Simple Estimator of Cointegrating Vectors in Higher Order Integrated Systems," Econometrica, 61, 783–820, DOI:10.2307/2951763.
Vogelsang, T.J. and M. Wagner (2014): "Integrated Modified OLS Estimation and Fixed-b Inference for Cointegrating Regressions," Journal of Econometrics, 148, 741–760, DOI:10.1016/j.jeconom.2013.10.015.
Other cointReg: cointRegD
,
cointRegFM
, cointRegIM
,
plot.cointReg
, print.cointReg
set.seed(1909) x1 = cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 = cumsum(rnorm(100, sd = 0.1)) + 1 x3 = cumsum(rnorm(100, sd = 0.2)) + 2 x = cbind(x1, x2, x3) y = x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter = cbind(level = 1, trend = 1:100) cointReg("FM", x = x, y = y, deter = deter, kernel = "ba", bandwidth = "and") # Compare the results of all three models: res = sapply(c("FM", "D", "IM"), cointReg, x = x, y = y, deter = deter) do.call(cbind, lapply(res, "[[", "theta"))
set.seed(1909) x1 = cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 = cumsum(rnorm(100, sd = 0.1)) + 1 x3 = cumsum(rnorm(100, sd = 0.2)) + 2 x = cbind(x1, x2, x3) y = x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter = cbind(level = 1, trend = 1:100) cointReg("FM", x = x, y = y, deter = deter, kernel = "ba", bandwidth = "and") # Compare the results of all three models: res = sapply(c("FM", "D", "IM"), cointReg, x = x, y = y, deter = deter) do.call(cbind, lapply(res, "[[", "theta"))
Computes the Saikkonen (1990) Dynamic OLS estimator.
cointRegD(x, y, deter, kernel = c("ba", "pa", "qs", "tr"), bandwidth = c("and", "nw"), n.lead = NULL, n.lag = NULL, kmax = c("k4", "k12"), info.crit = c("AIC", "BIC"), demeaning = FALSE, check = TRUE, ...)
cointRegD(x, y, deter, kernel = c("ba", "pa", "qs", "tr"), bandwidth = c("and", "nw"), n.lead = NULL, n.lag = NULL, kmax = c("k4", "k12"), info.crit = c("AIC", "BIC"), demeaning = FALSE, check = TRUE, ...)
x |
[ |
y |
[ |
deter |
[ |
kernel |
[ |
bandwidth |
[ |
n.lead , n.lag
|
[ |
kmax |
[ |
info.crit |
[ |
demeaning |
[ |
check |
[ |
... |
Arguments passed to |
The equation for which the FM-OLS estimator is calculated:
with as the deterministics matrix.
Then
is the full parameter vector.
Information about the D-OLS specific arguments:
n.lag
, n.lead
A positive number to set the number
of lags and leads. If at least one of them is equal to NULL
(default), the function getLeadLag
will be used to
calculate them automatically (see Choi and Kurozumi (2012) for details).
In that case, the following two arguments are needed.
kmax
Maximal value for lags and leads, when they are
calculated automatically. If "k4", then the maximum is equal to
floor(4 * (x.T/100)^(1/4))
, else it's
floor(12 * (x.T/100)^(1/4))
with x.T
is equal
to the data's length. One of "k4"
or "k12"
.
Default is "k4"
.
info.crit
Information criterion to use for the automatical
calculation of lags and leads. One of "AIC"
or "BIC"
.
Default is "AIC"
.
[cointReg
]. List with components:
beta
[numeric
]coefficients of the regressors
delta
[numeric
]coefficients of the deterministics
theta
[numeric
]combined coefficients of beta
and delta
sd.theta
[numeric
]standard errors for theta
t.theta
[numeric
]t-values for theta
p.theta
[numeric
]p-values for theta
theta.all
[numeric
]combined coefficients of beta
, delta
and the auxiliary
leads-and-lags regressors
residuals
[numeric
]D-OLS residuals (length depends on leads and lags)
omega.u.v
[numeric
]conditional long-run variance based on OLS residuals
varmat
[matrix
]variance-covariance matrix
Omega
[list
]the whole long-run variance matrix and parts of it
bandwidth
[list
]number and name of the calculated bandwidth
kernel
[character
]abbr. name of kernel type
lead.lag
[list
]leads-and-lags parameters
Phillips, P.C.B. and M. Loretan (1991): "Estimating Long Run Economic Equilibria," Review of Economic Studies, 58, 407–436, DOI:10.2307/2298004.
Saikkonen, P. (1991): "Asymptotically Efficient Estimation of Cointegrating Regressions," Econometric Theory, 7, 1–21, DOI:10.1017/S0266466600004217.
Stock, J.H. and M.W. Watson (1993): "A Simple Estimator of Cointegrating Vectors in Higher Order Integrated Systems," Econometrica, 61, 783–820, DOI:10.2307/2951763.
Other D-OLS: getLeadLag
,
getModD
, makeLeadLagMatrix
Other cointReg: cointRegFM
,
cointRegIM
, cointReg
,
plot.cointReg
, print.cointReg
set.seed(1909) x1 <- cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 <- cumsum(rnorm(100, sd = 0.1)) + 1 x3 <- cumsum(rnorm(100, sd = 0.2)) + 2 x <- cbind(x1, x2, x3) y <- x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter <- cbind(level = 1, trend = 1:100) test <- cointRegD(x, y, deter, n.lead = 2, n.lag = 2, kernel = "ba", bandwidth = "and") print(test) test2 <- cointRegD(x, y, deter, kmax = "k4", info.crit = "BIC", kernel = "ba", bandwidth = "and") print(test2)
set.seed(1909) x1 <- cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 <- cumsum(rnorm(100, sd = 0.1)) + 1 x3 <- cumsum(rnorm(100, sd = 0.2)) + 2 x <- cbind(x1, x2, x3) y <- x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter <- cbind(level = 1, trend = 1:100) test <- cointRegD(x, y, deter, n.lead = 2, n.lag = 2, kernel = "ba", bandwidth = "and") print(test) test2 <- cointRegD(x, y, deter, kmax = "k4", info.crit = "BIC", kernel = "ba", bandwidth = "and") print(test2)
Computes the Phillips and Hansen (1990) Fully Modified OLS estimator.
cointRegFM(x, y, deter, kernel = c("ba", "pa", "qs", "tr"), bandwidth = c("and", "nw"), demeaning = FALSE, check = TRUE, ...)
cointRegFM(x, y, deter, kernel = c("ba", "pa", "qs", "tr"), bandwidth = c("and", "nw"), demeaning = FALSE, check = TRUE, ...)
x |
[ |
y |
[ |
deter |
[ |
kernel |
[ |
bandwidth |
[ |
demeaning |
[ |
check |
[ |
... |
Arguments passed to |
The equation for which the FM-OLS estimator is calculated:
with as the deterministics matrix.
Then
is the full parameter vector.
The calculation of t-values and the variance-covariance matrix is only
possible, if y
is one-dimensional.
[cointReg
]. List with components:
delta
[numeric
| matrix
]coefficients of the deterministics
beta
[numeric
| matrix
]coefficients of the regressors
theta
[numeric
| matrix
]combined coefficients of beta
and delta
sd.theta
[numeric
]standard errors for theta
t.theta
[numeric
]t-values for theta
p.theta
[numeric
]p-values for theta
residuals
[numeric
]FM-OLS residuals (first value is always missing)
omega.u.v
[numeric
]conditional long-run variance based on OLS residuals.
varmat
[matrix
]variance-covariance matrix
Omega
[list
]the whole long-run variance matrix and parts of it
beta.OLS
[numeric
| matrix
]OLS coefficients as vector / matrix
delta.OLS
[numeric
| matrix
]OLS coefficients as vector / matrix
u.OLS
[numeric
]OLS residuals
bandwidth
[list
]number
and name
of bandwidth
kernel
[character
]abbr. name of kernel type
Phillips, P.C.B. and B. Hansen (1990): "Statistical Inference in Instrumental Variables Regression with I(1) Processes," Review of Economic Studies, 57, 99–125, DOI:10.2307/2297545.
Other cointReg: cointRegD
,
cointRegIM
, cointReg
,
plot.cointReg
, print.cointReg
set.seed(1909) x1 = cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 = cumsum(rnorm(100, sd = 0.1)) + 1 x3 = cumsum(rnorm(100, sd = 0.2)) + 2 x = cbind(x1, x2, x3) y = x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter = cbind(level = 1, trend = 1:100) test = cointRegFM(x, y, deter, kernel = "ba", bandwidth = "and") print(test)
set.seed(1909) x1 = cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 = cumsum(rnorm(100, sd = 0.1)) + 1 x3 = cumsum(rnorm(100, sd = 0.2)) + 2 x = cbind(x1, x2, x3) y = x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter = cbind(level = 1, trend = 1:100) test = cointRegFM(x, y, deter, kernel = "ba", bandwidth = "and") print(test)
Computes the Vogelsang and Wagner (2014) Integrated Modified OLS estimator.
cointRegIM(x, y, deter, selector = 1, t.test = TRUE, kernel = c("ba", "pa", "qs", "tr"), bandwidth = c("and", "nw"), check = TRUE, ...)
cointRegIM(x, y, deter, selector = 1, t.test = TRUE, kernel = c("ba", "pa", "qs", "tr"), bandwidth = c("and", "nw"), check = TRUE, ...)
x |
[ |
y |
[ |
deter |
[ |
selector |
[ |
t.test |
[ |
kernel |
[ |
bandwidth |
[ |
check |
[ |
... |
Arguments passed to |
The equation for which the IM-OLS estimator is calculated (type 1):
where ,
and
are the cumulated
sums of
,
and
(with
as the deterministics
matrix).
Then
is the full parameter vector.
The equation for which the IM-OLS estimator is calculated (type 2):
where ,
and
are the cumulated
sums of
,
and
(with
as the deterministics
matrix) and
as defined in equation (19) in Vogelsang and Wagner
(2015).
Then
is the full
parameter vector.
[cointReg
]. List with components:
delta
[numeric
]coefficients of the deterministics (cumulative sum )
beta
[numeric
]coefficients of the regressors (cumulative sum )
gamma
[numeric
]coefficients of the regressors (original regressors )
theta
[numeric
]combined coefficients of beta
, delta
sd.theta
[numeric
]standard errors for the theta
coefficients
t.theta
[numeric
]t-values for the theta
coefficients
p.theta
[numeric
]p-values for the theta
coefficients
theta.all
[numeric
]combined coefficients of beta
, delta
, gamma
residuals
[numeric
]IM-OLS residuals. Attention: These are the first differences of
– the original residuals are stored in
u.plus
.
u.plus
[numeric
]IM-OLS residuals, not differenced. See residuals
above.
omega.u.v
[numeric
]conditional long-run variance based on OLS residuals, via
cointRegFM
(in case of argument t.test
is TRUE
)
or NULL
varmat
[matrix
]variance-covariance matrix
Omega
[matrix
]NULL
(no long-run variance matrix for this regression type)
bandwidth
[list
]number
and name
of bandwidth if t.test = TRUE
kernel
[character
]abbr. name of kernel type if t.test = TRUE
delta2
[numeric
]coefficients of the deterministics (cumulative sum )
for regression type 2
beta2
[numeric
]coefficients of the regressors (cumulative sum )
for regression type 2
gamma2
[numeric
]coefficients of the regressors (original regressors )
for regression type 2
lambda2
[numeric
]coefficients of the Z regressors for regression type 2
theta2
[numeric
]combined coefficients of beta2
, delta2
, gamma2
and
lambda2
for regression type 2
u.plus2
[numeric
]IM-OLS residuals for regression type 2
Vogelsang, T.J. and M. Wagner (2014): "Integrated Modified OLS Estimation and Fixed-b Inference for Cointegrating Regressions," Journal of Econometrics, 148, 741–760, DOI:10.1016/j.jeconom.2013.10.015.
Other cointReg: cointRegD
,
cointRegFM
, cointReg
,
plot.cointReg
, print.cointReg
set.seed(1909) x1 = cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 = cumsum(rnorm(100, sd = 0.1)) + 1 x3 = cumsum(rnorm(100, sd = 0.2)) + 2 x = cbind(x1, x2, x3) y = x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter = cbind(level = 1, trend = 1:100) test = cointRegIM(x, y, deter, selector = c(1, 2), t.test = TRUE, kernel = "ba", bandwidth = "and") print(test)
set.seed(1909) x1 = cumsum(rnorm(100, mean = 0.05, sd = 0.1)) x2 = cumsum(rnorm(100, sd = 0.1)) + 1 x3 = cumsum(rnorm(100, sd = 0.2)) + 2 x = cbind(x1, x2, x3) y = x1 + x2 + x3 + rnorm(100, sd = 0.2) + 1 deter = cbind(level = 1, trend = 1:100) test = cointRegIM(x, y, deter, selector = c(1, 2), t.test = TRUE, kernel = "ba", bandwidth = "and") print(test)
Automatic bandwidth selection of Andrews (1991) and of Newey and West (1994).
getBandwidth(u, bandwidth = c("and", "nw"), kernel, ..., check = TRUE) getBandwidthAnd(u, kernel = c("ba", "pa", "qs", "th", "tr"), check = TRUE) getBandwidthNW(u, kernel = c("ba", "pa", "qs"), inter = FALSE, u.weights = NULL, check = TRUE)
getBandwidth(u, bandwidth = c("and", "nw"), kernel, ..., check = TRUE) getBandwidthAnd(u, kernel = c("ba", "pa", "qs", "th", "tr"), check = TRUE) getBandwidthNW(u, kernel = c("ba", "pa", "qs"), inter = FALSE, u.weights = NULL, check = TRUE)
u |
[ |
bandwidth |
[ |
kernel |
[ |
... |
Arguments passed to |
check |
[ |
inter |
[ |
u.weights |
[ |
For Andrews (1991), the AR(1) individual version is implemented.
The kernel that is used for calculating the long-run variance can be one of the following:
"ba"
: Bartlett kernel
"pa"
: Parzen kernel
"qs"
: Quadratic Spectral kernel
"th"
: Tukey-Hanning kernel (only if bandwidth = "and"
)
"tr"
: Truncated kernel (only if bandwidth = "and"
)
[numeric(1)
]. Bandwidth
getBandwidthAnd
: Automatic bandwidth selection of Andrews (1991).
getBandwidthNW
: Automatic bandwidth selection of Newey and West (1994).
Andrews, D.W.K. (1991): "Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation," Econometrica, 59, 817–854, DOI:10.2307/2938229.
Newey, W.K. and K.D. West (1994): "Automatic Lag Selection in Covariance Matrix Estimation", Review of Economic Studies, 61, 631–653, DOI:10.2307/2297912.
set.seed(1909) x <- rnorm(100) getBandwidth(x, kernel = "ba") getBandwidth(x, bandwidth = "nw", kernel = "ba") x2 <- arima.sim(model = list(ar = c(0.7, 0.2)), innov = x, n = 100) getBandwidth(x2, kernel = "qs") getBandwidth(x2, bandwidth = "nw", kernel = "qs")
set.seed(1909) x <- rnorm(100) getBandwidth(x, kernel = "ba") getBandwidth(x, bandwidth = "nw", kernel = "ba") x2 <- arima.sim(model = list(ar = c(0.7, 0.2)), innov = x, n = 100) getBandwidth(x2, kernel = "qs") getBandwidth(x2, bandwidth = "nw", kernel = "qs")
Generates "optimal" numbers of leads and lags for the Dynamic OLS estimator.
getLeadLag(x, y, deter, max.lag, max.lead, ic = c("AIC", "BIC"), symmet = FALSE, check = FALSE)
getLeadLag(x, y, deter, max.lag, max.lead, ic = c("AIC", "BIC"), symmet = FALSE, check = FALSE)
x |
[ |
y |
[ |
deter |
[ |
max.lead , max.lag
|
[ |
ic |
[ |
symmet |
[ |
check |
[ |
[numeric(2)
]. "Optimal" numbers of leads and lags.
Other D-OLS: cointRegD
,
getModD
, makeLeadLagMatrix
set.seed(1909) y <- matrix(cumsum(rnorm(100)), ncol = 1) x <- matrix(rep(y, 4) + rnorm(400, mean = 3, sd = 2), ncol = 4) deter <- cbind(1, 1:100) cointReg:::getLeadLag(x = x, y = y, deter = deter, max.lag = 5, max.lead = 5, ic = "AIC", symmet = FALSE)
set.seed(1909) y <- matrix(cumsum(rnorm(100)), ncol = 1) x <- matrix(rep(y, 4) + rnorm(400, mean = 3, sd = 2), ncol = 4) deter <- cbind(1, 1:100) cointReg:::getLeadLag(x = x, y = y, deter = deter, max.lag = 5, max.lead = 5, ic = "AIC", symmet = FALSE)
This function computes the long-run variance Omega, the one sided long-run variance Delta (starting with lag 0) and the variance Sigma from an input matrix of residuals.
getLongRunVar(u, bandwidth = c("and", "nw"), kernel = c("ba", "bo", "da", "pa", "qs", "tr"), demeaning = FALSE, check = TRUE, ...)
getLongRunVar(u, bandwidth = c("and", "nw"), kernel = c("ba", "bo", "da", "pa", "qs", "tr"), demeaning = FALSE, check = TRUE, ...)
u |
[ |
bandwidth |
[ |
kernel |
[ |
demeaning |
[ |
check |
[ |
... |
Arguments passed to |
The bandwidth can be one of the following:
"ba"
: Bartlett kernel
"bo"
: Bohmann kernel
"da"
: Daniell kernel
"pa"
: Parzen kernel
"qs"
: Quadratic Spectral kernel
"tr"
: Truncated kernel
[list
] with components:
Omega
[matrix
]Long-run variance matrix
Delta
[matrix
]One-sided long-run variance matrix
Sigma
[matrix
]Variance matrix
set.seed(1909) x <- rnorm(100) band <- getBandwidthAnd(x, kernel = "ba") getLongRunVar(x, kernel = "ba", bandwidth = band) # shorter: getLongRunVar(x, kernel = "ba", bandwidth = "and") x2 <- arima.sim(model = list(ar = c(0.7, 0.2)), innov = x, n = 100) x2 <- cbind(a = x2, b = x2 + rnorm(100)) getLongRunVar(x2, kernel = "ba", bandwidth = "nw")
set.seed(1909) x <- rnorm(100) band <- getBandwidthAnd(x, kernel = "ba") getLongRunVar(x, kernel = "ba", bandwidth = band) # shorter: getLongRunVar(x, kernel = "ba", bandwidth = "and") x2 <- arima.sim(model = list(ar = c(0.7, 0.2)), innov = x, n = 100) x2 <- cbind(a = x2, b = x2 + rnorm(100)) getLongRunVar(x2, kernel = "ba", bandwidth = "nw")
Compute the weights corresponding to some kernel funtions.
getLongRunWeights(n, bandwidth, kernel)
getLongRunWeights(n, bandwidth, kernel)
n |
[ |
bandwidth |
[ |
kernel |
[ |
[list
] with components:
w
[numeric
]Vector of weights
upper
[numeric(1)
]Index to largest non-zero entry in w
lrw.ba = cointReg:::getLongRunWeights(100, kernel = "ba", bandwidth = 25) plot(lrw.ba$w)
lrw.ba = cointReg:::getLongRunWeights(100, kernel = "ba", bandwidth = 25) plot(lrw.ba$w)
Generates an lm
model for the Dynamic OLS estimator.
getModD(x, y, deter, n.lag, n.lead, check = FALSE)
getModD(x, y, deter, n.lag, n.lead, check = FALSE)
x |
[ |
y |
[ |
deter |
[ |
n.lag , n.lead
|
[ |
check |
[ |
[lm
]. An lm
object, containing an additional
list element (aux
) with D-OLS specific objects:
Z
[matrix
]jointed matrix of deterministics and x
x.delta
[matrix
]differences of x
dx.all
[matrix
]leads-and-lags matrix
all.trunc
[matrix
]truncated version of jointed matrix of Z
and dx.all
y.trunc
[matrix
]truncated version of y
Other D-OLS: cointRegD
,
getLeadLag
, makeLeadLagMatrix
set.seed(1909) y <- matrix(cumsum(rnorm(100)), ncol = 1) x <- matrix(rep(y, 4) + rnorm(400, mean = 3, sd = 2), ncol = 4) deter <- cbind(1, 1:100) cointReg:::getModD(x = x, y = y, deter = deter, n.lag = 2, n.lead = 3)
set.seed(1909) y <- matrix(cumsum(rnorm(100)), ncol = 1) x <- matrix(rep(y, 4) + rnorm(400, mean = 3, sd = 2), ncol = 4) deter <- cbind(1, 1:100) cointReg:::getModD(x = x, y = y, deter = deter, n.lag = 2, n.lead = 3)
Generates leads-and-lags matrix for the Dynamic OLS estimator.
makeLeadLagMatrix(x, n.lag, n.lead)
makeLeadLagMatrix(x, n.lag, n.lead)
x |
[ |
n.lag , n.lead
|
[ |
[matrix
]. Leads-and-lags matrix.
Other D-OLS: cointRegD
,
getLeadLag
, getModD
x <- matrix(1:20, 2, byrow = TRUE) cointReg:::makeLeadLagMatrix(x = x, n.lag = 2, n.lead = 3)
x <- matrix(1:20, 2, byrow = TRUE) cointReg:::makeLeadLagMatrix(x = x, n.lag = 2, n.lead = 3)
Plotting objects of class "cointReg"
. Currently, only the residuals
will be plotted.
## S3 method for class 'cointReg' plot(x, type, main, xlab, ylab, axes = TRUE, ...)
## S3 method for class 'cointReg' plot(x, type, main, xlab, ylab, axes = TRUE, ...)
x |
[ |
type |
[ |
main , xlab , ylab
|
[ |
axes |
[ |
... |
[ |
Other cointReg: cointRegD
,
cointRegFM
, cointRegIM
,
cointReg
, print.cointReg
set.seed(42) x = data.frame(x1 = cumsum(rnorm(200)), x2 = cumsum(rnorm(200))) eps1 = rnorm(200, sd = 2) y = x$x1 - x$x2 + 10 + eps1 deter = cbind(level = rep(1, 200)) test = cointRegFM(x = x, y = y, deter = deter) plot(test)
set.seed(42) x = data.frame(x1 = cumsum(rnorm(200)), x2 = cumsum(rnorm(200))) eps1 = rnorm(200, sd = 2) y = x$x1 - x$x2 + 10 + eps1 deter = cbind(level = rep(1, 200)) test = cointRegFM(x = x, y = y, deter = deter) plot(test)
Printing objects of class "cointReg"
.
## S3 method for class 'cointReg' print(x, ..., digits = getOption("digits"), all.coeffs = FALSE)
## S3 method for class 'cointReg' print(x, ..., digits = getOption("digits"), all.coeffs = FALSE)
x |
[ |
... |
ignored |
digits |
[ |
all.coeffs |
[ |
[matrix
]
A matrix including the coefficients along with standard errors,
t and p values.
Other cointReg: cointRegD
,
cointRegFM
, cointRegIM
,
cointReg
, plot.cointReg
set.seed(42) x = data.frame(x1 = cumsum(rnorm(200)), x2 = cumsum(rnorm(200))) eps1 = rnorm(200, sd = 2) y = x$x1 - x$x2 + 10 + eps1 deter = cbind(level = rep(1, 200)) test.fm = cointRegFM(x = x, y = y, deter = deter) print(test.fm) test.d = cointRegD(x = x, y = y, deter = deter) print(test.d) test.im2 = cointRegIM(x = x, y = y, deter = deter) print(test.im2) ## Not run: # The coefficients matrix can be transferred e.g. to LaTeX via xtable: if (!require("xtable")) {install.packages("xtable"); library("xtable")} xtab = xtable(print(test.fm)) print.xtable(xtab) ## End(Not run)
set.seed(42) x = data.frame(x1 = cumsum(rnorm(200)), x2 = cumsum(rnorm(200))) eps1 = rnorm(200, sd = 2) y = x$x1 - x$x2 + 10 + eps1 deter = cbind(level = rep(1, 200)) test.fm = cointRegFM(x = x, y = y, deter = deter) print(test.fm) test.d = cointRegD(x = x, y = y, deter = deter) print(test.d) test.im2 = cointRegIM(x = x, y = y, deter = deter) print(test.im2) ## Not run: # The coefficients matrix can be transferred e.g. to LaTeX via xtable: if (!require("xtable")) {install.packages("xtable"); library("xtable")} xtab = xtable(print(test.fm)) print.xtable(xtab) ## End(Not run)