Title: | Numerical Standard Errors Computation in R |
---|---|
Description: | Collection of functions designed to calculate numerical standard error (NSE) of univariate time series as described in Ardia et al. (2018) <doi:10.1515/jtse-2017-0011> and Ardia and Bluteau (2017) <doi:10.21105/joss.00172>. |
Authors: | David Ardia [aut] |
Maintainer: | Keven Bluteau <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.21 |
Built: | 2025-02-13 04:42:51 UTC |
Source: | https://github.com/keblu/nse |
nse
(Ardia and Bluteau, 2017) is an R package for computing the numerical standard error (NSE), an estimate
of the standard deviation of a simulation result, if the simulation experiment were to be repeated
many times. The package provides a set of wrappers around several R packages, which give access to
more than thirty NSE estimators, including batch means
estimators (Geyer, 1992, Section 3.2), initial sequence estimators Geyer (1992, Equation 3.3),
spectrum at zero estimators (Heidelberger and Welch, 1981), heteroskedasticity
and autocorrelation consistent (HAC) kernel estimators (Newey and West, 1987; Andrews, 1991; Andrews and
Monahan, 1992; Newey and West, 1994; Hirukawa, 2010), and bootstrap estimators Politis and
Romano (1992, 1994); Politis and White (2004). The full set of estimators is described in
Ardia et al. (2018).
nse.geyer
: Geyer NSE estimator.
nse.spec0
: Spectral density at zero NSE estimator.
nse.nw
: Newey-West NSE estimator.
nse.andrews
: Andrews NSE estimator.
nse.hiruk
: Hirukawa NSE estimator.
nse.boot
: Bootstrap NSE estimator.
Functions rely on the packages coda
, mcmc
,mcmcse
, np
, and sandwich
.
Please cite the package in publications. Use citation("nse")
.
David Ardia and Keven Bluteau
Andrews, D.W.K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica 59(3), 817-858.
Andrews, D.W.K, Monahan, J.C. (1992). An improved heteroskedasticity and autocorrelation consistent covariance matrix estimator. Econometrica 60(4), 953-966.
Ardia, D., Bluteau, K., Hoogerheide, L. (2018). Methods for computing numerical standard errors: Review and application to Value-at-Risk estimation. Journal of Time Series Econometrics 10(2), 1-9. doi:10.1515/jtse-2017-0011 doi:10.2139/ssrn.2741587
Ardia, D., Bluteau, K. (2017). nse: Computation of numerical standard errors in R. Journal of Open Source Software 10(2). doi:10.21105/joss.00172
Geyer, C.J. (1992). Practical Markov chain Monte Carlo. Statistical Science 7(4), 473-483.
Heidelberger, P., Welch, Peter D. (1981). A spectral method for confidence interval generation and run length control in simulations. Communications of the ACM 24(4), 233-245.
Hirukawa, M. (2010). A two-stage plug-in bandwidth selection and its implementation for covariance estimation. Econometric Theory 26(3), 710-743.
Newey, W.K., West, K.D. (1987). A simple, positive semi-definite, heteroskedasticity and autocorrelationconsistent covariance matrix. Econometrica 55(3), 703-708.
Newey, W.K., West, K.D. (1994) . Automatic lag selection in covariance matrix estimation. Review of Economic Studies 61(4), 631-653.
Politis, D.N., Romano, and J.P. (1992). A circular block-resampling procedure for stationary data. In Exploring the limits of bootstrap, John Wiley & Sons, 263-270.
Politis, D.N., Romano, and J.P. (1994). The stationary bootstrap. Journal of the American Statistical Association 89(428), 1303-1313.
Politis, D.N., White, H. (2004). Automatic block-length selection for the dependent bootstrap. Econometric Reviews 23(1), 53-70.
Useful links:
Report bugs at https://github.com/keblu/nse/issues
Function which calculates the numerical standard error with the kernel based variance estimator by Andrews (1991).
nse.andrews( x, type = c("bartlett", "parzen", "tukey", "qs", "trunc"), lag.prewhite = 0, approx = c("AR(1)", "ARMA(1,1)") )
nse.andrews( x, type = c("bartlett", "parzen", "tukey", "qs", "trunc"), lag.prewhite = 0, approx = c("AR(1)", "ARMA(1,1)") )
x |
A numeric vector. |
type |
The type of kernel used among which |
lag.prewhite |
Prewhite the series before analysis (integer or |
approx |
Andrews approximation, either |
This kernel based variance estimation apply weight to the auto-covariance function with a kernel and sums up the value.
The NSE estimator.
nse.andrews
is a wrapper around lrvar
from the sandwich
package and uses Andrews (1991) automatic bandwidth estimator. See the documentation of sandwich
for details.
David Ardia and Keven Bluteau
Andrews, D.W.K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica 59(3), 817-858.
Andrews, D.W.K, Monahan, J.C. (1992). An improved heteroskedasticity and autocorrelation consistent covariance matrix estimator. Econometrica 60(4), 953-966.
Newey, W.K., West, K.D. (1987). A simple, positive semi-definite, heteroskedasticity and autocorrelationconsistent covariance matrix. Econometrica 55(3), 703-708.
Newey, W.K., West, K.D. (1994) . Automatic lag selection in covariance matrix estimation. Review of Economic Studies 61(4), 631-653.
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.andrews(x = x, type = "parzen", lag.prewhite = 0) nse.andrews(x = x, type = "tukey", lag.prewhite = 1) nse.andrews(x = x, type = "qs", lag.prewhite = NULL) ## End(Not run)
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.andrews(x = x, type = "parzen", lag.prewhite = 0) nse.andrews(x = x, type = "tukey", lag.prewhite = 1) nse.andrews(x = x, type = "qs", lag.prewhite = NULL) ## End(Not run)
Function which calculates the numerical standard error with bootstrap estimator.
nse.boot(x, nb, type = c("stationary", "circular"), b = NULL, lag.prewhite = 0)
nse.boot(x, nb, type = c("stationary", "circular"), b = NULL, lag.prewhite = 0)
x |
A numeric vector. |
nb |
The number of bootstrap replications. |
type |
The bootstrap scheme used, among |
b |
The block length for the block bootstrap. If |
lag.prewhite |
Prewhite the series before analysis (integer or |
The NSE estimator.
nse.boot
uses b.star
of the np
package
for the optimal block length selection.
David Ardia and Keven Bluteau
Politis, D.N., Romano, and J.P. (1992). A circular block-resampling procedure for stationary data. In Exploring the limits of bootstrap, John Wiley & Sons, 263-270.
Politis, D.N., Romano, and J.P. (1994). The stationary bootstrap. Journal of the American Statistical Association 89(428), 1303-1313.
Politis, D.N., White, H. (2004). Automatic block-length selection for the dependent bootstrap. Econometric Reviews 23(1), 53-70.
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) set.seed(1234) nse.boot(x = x, nb = 1000, type = "stationary", b = NULL, lag.prewhite = 0) nse.boot(x = x, nb = 1000, type = "circular", b = NULL, lag.prewhite = NULL) nse.boot(x = x, nb = 1000, type = "circular", b = 10, lag.prewhite = NULL) ## End(Not run)
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) set.seed(1234) nse.boot(x = x, nb = 1000, type = "stationary", b = NULL, lag.prewhite = 0) nse.boot(x = x, nb = 1000, type = "circular", b = NULL, lag.prewhite = NULL) nse.boot(x = x, nb = 1000, type = "circular", b = 10, lag.prewhite = NULL) ## End(Not run)
Function which calculates the numerical standard error with low-frequency cosine weighted averages of the original serie.
nse.cos(x, q = 12, lag.prewhite = 0)
nse.cos(x, q = 12, lag.prewhite = 0)
x |
A numeric vector. |
q |
Number of consine series. |
lag.prewhite |
Prewhite the series before analysis (integer or |
The method estimate the series with a linear regression using cosine low frequency series. It than derived the NSE from the coefficient of the cosine series (Ulrich and Watson, 2017).
The NSE estimator.
David Ardia and Keven Bluteau
Muller, Ulrich K., and Mark W. Watson. (2015) Low-frequency econometrics. National Bureau of Economic Research, No. w21564.
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.cos(x = x, q = 12, lag.prewhite = 0) nse.cos(x = x, q = 12, lag.prewhite = NULL) ## End(Not run)
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.cos(x = x, q = 12, lag.prewhite = 0) nse.cos(x = x, q = 12, lag.prewhite = NULL) ## End(Not run)
Function which calculates the numerical standard error with the method of Geyer (1992).
nse.geyer( x, type = c("iseq", "bm", "obm", "iseq.bm"), nbatch = 30, iseq.type = c("pos", "dec", "con") )
nse.geyer( x, type = c("iseq", "bm", "obm", "iseq.bm"), nbatch = 30, iseq.type = c("pos", "dec", "con") )
x |
A numeric vector. |
type |
The type which can be either |
nbatch |
Number of batches when |
iseq.type |
Constraints on function: |
The type "iseq"
gives the positive intial sequence estimator, "bm"
is the batch mean estimator,
"obm"
is the overlapping batch mean estimator and "iseq.bm"
is a combination of "iseq"
and "bm"
.
The NSE estimator.
nse.geyer
relies on the packages mcmc
and mcmcse
; see
the documentation of these packages for more details.
David Ardia and Keven Bluteau
Geyer, C.J. (1992). Practical Markov chain Monte Carlo. Statistical Science 7(4), .473-483.
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.geyer(x = x, type = "bm", nbatch = 30) nse.geyer(x = x, type = "obm", nbatch = 30) nse.geyer(x = x, type = "iseq", iseq.type = "pos") nse.geyer(x = x, type = "iseq.bm", iseq.type = "con") ## End(Not run)
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.geyer(x = x, type = "bm", nbatch = 30) nse.geyer(x = x, type = "obm", nbatch = 30) nse.geyer(x = x, type = "iseq", iseq.type = "pos") nse.geyer(x = x, type = "iseq.bm", iseq.type = "con") ## End(Not run)
Function which calculates the numerical standard error with the kernel based variance estimator by Andrews (1991) using Hirukawa (2010) automatic bandwidth estimator.
nse.hiruk(x, type = c("bartlett", "parzen"), lag.prewhite = 0)
nse.hiruk(x, type = c("bartlett", "parzen"), lag.prewhite = 0)
x |
A numeric vector. |
type |
The type of kernel used among |
lag.prewhite |
Prewhite the series before analysis (integer or |
The NSE estimator.
nse.hiruk
is a wrapper around lrvar
from
the sandwich
package and uses Hirukawa (2010) bandwidth estimator.
See the documentation of sandwich
for details.
David Ardia and Keven Bluteau
Hirukawa, M. (2010). A two-stage plug-in bandwidth selection and its implementation for covariance estimation. Econometric Theory 26(3), 710-743.
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.hiruk(x = x, type = "parzen", lag.prewhite = 0) nse.hiruk(x = x, type = "bartlett", lag.prewhite = NULL) ## End(Not run)
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.hiruk(x = x, type = "parzen", lag.prewhite = 0) nse.hiruk(x = x, type = "bartlett", lag.prewhite = NULL) ## End(Not run)
Function which calculates the numerical standard error with the Newey West (1987, 1994) HAC estimator.
nse.nw(x, lag.prewhite = 0)
nse.nw(x, lag.prewhite = 0)
x |
A numeric vector |
lag.prewhite |
Prewhite the series before analysis (integer or |
The NSE estimator.
nse.nw
is a wrapper around lrvar
from
the sandwich
package. See the documentation of sandwich
for details.
David Ardia and Keven Bluteau
Newey, W.K., West, K.D. (1987). A simple, positive semi-definite, heteroskedasticity and autocorrelationconsistent covariance matrix. Econometrica 55(3), .703-708.
Newey, W.K., West, K.D. (1994) . Automatic lag selection in covariance matrix estimation. Review of Economic Studies 61(4), .631-653.
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.nw(x = x, lag.prewhite = 0) nse.nw(x = x, lag.prewhite = 1) nse.nw(x = x, lag.prewhite = NULL) ## End(Not run)
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.nw(x = x, lag.prewhite = 0) nse.nw(x = x, lag.prewhite = 1) nse.nw(x = x, lag.prewhite = NULL) ## End(Not run)
Function which calculates the numerical standard error with the spectrum at zero estimator.
nse.spec0( x, type = c("ar", "glm", "daniell", "modified.daniell", "tukey-hanning", "parzen", "triweight", "bartlett-priestley", "triangular", "qs"), lag.prewhite = 0, welch = FALSE, steep = FALSE )
nse.spec0( x, type = c("ar", "glm", "daniell", "modified.daniell", "tukey-hanning", "parzen", "triweight", "bartlett-priestley", "triangular", "qs"), lag.prewhite = 0, welch = FALSE, steep = FALSE )
x |
A numeric vector. |
type |
Method to use in estimating the spectral density function, among |
lag.prewhite |
Prewhite the series before analysis (integer or |
welch |
Use Welch's method (Welsh, 1967) to estimate the spectral density. |
steep |
Use steep or sharp version of the kernel (Phillips et al., 2006) (only available for type: |
Welsh's method use 50% overlap and 8 sub-samples.
The method "ar"
estimates the spectral density using an autoregressive model,
"glm"
using a generalized linear model Heidelberger & Welch (1981),
"daniell"
uses daniell window from the R kernel function,
"modified.daniell"
uses daniell window the R kernel function,
"tukey-hanning"
uses the tukey-hanning window,
"parzen"
uses the parzen window,
"triweight"
uses the triweight window,
"bartlett-priestley"
uses the Bartlett-Priestley window,
"triangular"
uses the triangular window, and
"qs"
uses the quadratic-spectral window,
This kernel based variance estimator apply weights to smooth out the spectral density using a kernel and takes the spectral density at frequency zero which is equivalent to the variance of the serie. Bandwidth for the kernel is automatically selected using cross-validatory methods (Hurvich, 1985).
The NSE estimator.
nse.spec0
relies on the packages coda
; see the documentation of this package for more details.
David Ardia and Keven Bluteau
Heidelberger, P., Welch, Peter D. (1981). A spectral method for confidence interval generation and run length control in simulations. Communications of the ACM 24(4), 233-245.
Phillips, P. C., Sun, Y., & Jin, S. (2006). Spectral density estimation and robust hypothesis testing using steep origin kernels without truncation. International Economic Review, 47(3), 837-894.
Welch, P. D. (1967), The use of Fast Fourier Transform for the estimation of power spectra: A method based on time averaging over short, modified periodograms. IEEE Transactions on Audio and Electroacoustics, AU-15(2): 70-73,
Hurvich, C. M. (1985). Data-driven choice of a spectrum estimate: extending the applicability of cross-validation methods. Journal of the American Statistical Association, 80(392), 933-940.
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.spec0(x = x, type = "parzen", lag.prewhite = 0, welch = TRUE, steep = TRUE) ## End(Not run)
## Not run: n = 1000 ar = 0.9 mean = 1 sd = 1 set.seed(1234) x = c(arima.sim(n = n, list(ar = ar), sd = sd) + mean) nse.spec0(x = x, type = "parzen", lag.prewhite = 0, welch = TRUE, steep = TRUE) ## End(Not run)