Title: | Sieve Methods for Non-Stationary Time Series |
---|---|
Description: | We provide functions for estimation and inference of locally-stationary time series using the sieve methods and bootstrapping procedure. In addition, it also contains functions to generate Daubechies and Coiflet wavelet by Cascade algorithm and to process data visualization. |
Authors: | Xiucai Ding [aut, cre, cph], Chen Qian [aut, cph] |
Maintainer: | Xiucai Ding <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-06 04:26:39 UTC |
Source: | https://github.com/cran/Sie2nts |
auto.pacf.test() generates a test of lag of AR model by choosing tuning parameter automatically.
auto.pacf.test( ts, lag = 3, b = 8, or = 4, type, alpha = 0.05, method = "LOOCV", threshold = 0, B.s = 1000 )
auto.pacf.test( ts, lag = 3, b = 8, or = 4, type, alpha = 0.05, method = "LOOCV", threshold = 0, B.s = 1000 )
ts |
ts is the data set which is a time series data typically |
lag |
the lag for auto-regressive model, the default value is 3 |
b |
the largest lag for auto-regressive model, the default value is 8, this parameter must be larger than lag |
or |
or indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
type |
type indicates which type of basis is used. There are 31 types in this package |
alpha |
level of the test |
method |
method indicates which method used to choose optimal parameters, 3 methods in this package can be used. |
threshold |
threshold determines the bound for Elbow method |
B.s |
the number of statistics used in multiplier bootstrap, the default value is 1000 |
In the parameter type, this package provides 32 types of basis including options "Legen" for Legendre polynomials, "Cheby" for first kind Chebyshev polynomials, "tri" for trigonometric polynomials, "cos" for cosine polynomials, "sin" for sine polynomials, "Cspli" for splines means Class of splines functions, in this option, the first input "c" is knots plus 2 that represent 0 and 1. "or" indicates the order of splines, so the number of basis is number of knots + 2 - 2 plus the number of order.When functions automatically choose the number of basis for splines, the number is not less than the order of spline. "db1" to "db20" for Daubechies1 wavelet basis to Daubechies20 wavelet basis and "cf1" to "cf5" for Coiflet1 wavelet basis to Coiflet5 wavelet basis. The package provides the wavelet tables are generated by Cascade algorithm using low-pass filter. If the exact values of wavelet are required, Recursion algorithm should be used. In the parameter method, it contains 3 options, the default option is "LOOCV", it uses Leave-One-Out Cross-Validation to choose the best tuning parameters. The second choice is "CV" which uses the Cross-Validation method, it takes 3*log2(n) size as validation set where n is the number of total observations. The third choice is "Elbow".This method similar as "lOOCV", however, it set the threshold manually. The function will choose the smallest tuning parameters once the value of LOOCV is less than threshold.
p value of the test
[1] Ding, Xiucai, and Zhou, Zhou. “Estimation and inference for precision matrices of nonstationary time series.” The Annals of Statistics 48(4) (2020): 2455-2477.
[2] Ding, Xiucai, and Zhou, Zhou. “Auto-regressive approximations to non-stationary time series, with inference and applications.” Available online, 2021.
auto.test() generates a test of Stability for AR Approximations by choosing tuning parameter automatically.
auto.test( ts, or = 4, type, alpha = 0.05, method = "LOOCV", threshold = 0, B.s = 1000 )
auto.test( ts, or = 4, type, alpha = 0.05, method = "LOOCV", threshold = 0, B.s = 1000 )
ts |
ts is the data set which is a time series data typically |
or |
indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
type |
type indicates which type of basis is used. There are 31 types in this package |
alpha |
level of the test |
method |
method indicates which method used to choose optimal parameters, 3 methods in this package can be used |
threshold |
threshold determines the bound for Elbow method |
B.s |
the number of statistics used in multiplier bootstrap, the default value is 1000 |
p value of the test
bs.gene() generates the value of k-th basis function. (The wavelet basis options return the full table)
bs.gene(type, k, point = 200, c = 10, or = 4, ops = "auto")
bs.gene(type, k, point = 200, c = 10, or = 4, ops = "auto")
type |
type indicates which type of basis is used. There are 31 types in this package |
k |
k-th basis function |
point |
the number of values got from k-th basis function |
c |
c only used in Cspli which indicates the total number of knots to generate, the default is 10, c should not be less than k.(for splines, the true number of basis is c-2+or) |
or |
indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
ops |
ops indicates the function uses existing table or theoretical way to generate, the default option is "auto" |
A data frame which contains the value of k-th basis function
[3] Chen, Xiaohong. “Large Sample Sieve Estimation of Semi-Nonparametric Models.” Handbook of Econometrics, 6(B): 5549–5632,2007.
bs.gene("Legen", 2) bs.gene("tri", 2, 300)
bs.gene("Legen", 2) bs.gene("tri", 2, 300)
bs.plot() generates the plot of first k basis function.
bs.plot(type, k, or = 4, title = "")
bs.plot(type, k, or = 4, title = "")
type |
type indicates which type of basis is used (There are 31 types in this package) |
k |
The k is the number of basis functions represented (If wavelet are chosen, the real number of basis is 2^k. If Cspli is chosen, the real number of basis is k-2+or) |
or |
indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
title |
give the title for the basis plot |
The plot of 1 to k basis functions
bs.plot("Legen", 2) bs.plot("tri", 3)
bs.plot("Legen", 2) bs.plot("tri", 3)
fix.fit() estimates the coefficients of AR model by sieve methods with user specifying.
fix.fit(ts, c, b, type, or = 4, m = 500)
fix.fit(ts, c, b, type, or = 4, m = 500)
ts |
ts is the data set which is a time series data typically |
c |
c indicates the number of basis used to estimate (For wavelet, the real number of basis is 2^c. For Cubic Spline, the real number of basis is c-2+or) |
b |
b is the lag for auto-regressive model |
type |
type indicates which type of basis is used. There are 31 types in this package |
or |
indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
m |
m indicates the number of points of coefficients to estimate |
A list contains 3 objects, the first is a matrix which contains estimates for each basis used in OLS, the second is a list contains estimates for coefficients in AR model and the last is a vector contains residuals
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } res = fix.fit(time.series, c=5, b=1, type = "Legen") cat(res$ols.coef) plot.ts(res$ts.coef[[1]]) plot.ts(res$Residuals)
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } res = fix.fit(time.series, c=5, b=1, type = "Legen") cat(res$ols.coef) plot.ts(res$ts.coef[[1]]) plot.ts(res$Residuals)
fix.pacf() generates the PACF with fixed tuning parameters.
fix.pacf(ts, c, lag, type, or = 4, m = 500)
fix.pacf(ts, c, lag, type, or = 4, m = 500)
ts |
ts is the data set which is a time series data typically |
c |
c indicates the number of basis used to Estimate (For wavelet, the number of basis is 2^c. If Cspli is chosen, the real number of basis is c-2+or) |
lag |
lag b is the lag for auto-regressive model |
type |
type indicates which type of basis is used (There are 31 types in this package) |
or |
or indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
m |
m indicates the number of points of coefficients to Estimate |
A vector which contains the PACF with specific lag
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } fix.pacf(time.series, c=5, lag = 1, type = "Legen")
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } fix.pacf(time.series, c=5, lag = 1, type = "Legen")
fix.pacf.test() generates a test of lags for AR Approximations.
fix.pacf.test(ts, c, type, or = 4, lag = 3, b = 8, B.s = 1000, m = 0)
fix.pacf.test(ts, c, type, or = 4, lag = 3, b = 8, B.s = 1000, m = 0)
ts |
ts is the data set which is a time series data typically |
c |
c indicates the number of basis used to estimate (For wavelet, the number of basis is 2^c. If Cspli is chosen, the real number of basis is c-2+or) |
type |
type indicates which type of basis is used. There are 31 types in this package |
or |
or indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
lag |
lag determine the lag of AR Approximations.The default is 3 |
b |
the largest lag for auto-regressive model, the default value is 8, this parameter must be larger than lag |
B.s |
the number of statistics used in multiplier bootstrap, the default value is 1000 |
m |
the number of window size used in multiplier bootstrap, the default value is 0 which uses the minimum volatility method to determine the number |
It returns a list contains p value for each lag
fix.plot() visualizes the estimation of coefficient.
fix.plot(res.fix.fit, type, title = "")
fix.plot(res.fix.fit, type, title = "")
res.fix.fit |
the output from fix.fit() function |
type |
type indicates which type of basis is used (There are 31 types in this package) |
title |
give the title for the fixed estimate plot |
A list which contains 3 plot related to the estimation of coefficient, Elbow point and cross validation in order
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } res1 = fix.fit(time.series, 5, 1, type = "Legen") fix.plot(res1, "Legen")
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } res1 = fix.fit(time.series, 5, 1, type = "Legen") fix.plot(res1, "Legen")
fix.test() generates a test of Stability for AR Approximations with fixed parameters.
fix.test(ts, c, b, type, or = 4, B.s = 1000, m = 0)
fix.test(ts, c, b, type, or = 4, B.s = 1000, m = 0)
ts |
ts is the data set which is a time series data typically |
c |
c indicates the number of basis used to estimate (For wavelet, the number of basis is 2^c. If Cspli is chosen, the real number of basis is c-2+or) |
b |
b is the lag for auto-regressive model |
type |
type indicates which type of basis is used. There are 31 types in this package |
or |
indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
B.s |
the number of statistics used in multiplier bootstrap, the default value is 1000 |
m |
the number of window size used in multiplier bootstrap, the default value is 0 which uses the minimum volatility method to determine the number |
p value of the test
sie.auto.fit() estimates the coefficients of AR model by sieve methods with 2 cross validation methods and elbow method.
sie.auto.fit(ts, type, or = 4, method = "LOOCV", m = 500, threshold = 0)
sie.auto.fit(ts, type, or = 4, method = "LOOCV", m = 500, threshold = 0)
ts |
ts is the data set which is a time series data typically |
type |
type indicates which type of basis is used. There are 31 types in this package |
or |
indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
method |
method indicates which method used to choose optimal parameters, 3 methods in this package can be used |
m |
m indicates the number of points of coefficients to estimate |
threshold |
threshold determines the bound for Elbow method |
A list contains 4 objects, the first is estimates for coefficients in AR model, the second is cross validation table, the third is estimates for each basis used in OLS and the last is optimal parameters
sie.auto.pacf() generates the PACF from 1 to lag automatically.
sie.auto.pacf(ts, c, lag, type, or = 4, m = 500)
sie.auto.pacf(ts, c, lag, type, or = 4, m = 500)
ts |
ts is the data set which is a time series data typically |
c |
c indicates the number of basis used to estimate (For wavelet, the number of basis is 2^c.If Cspli is chosen, the real number of basis is c-2+or) |
lag |
lag b is the lag for auto-regressive model |
type |
type indicates which type of basis is used (There are 31 types in this package) |
or |
indicates the order of spline and only used in Cspli type, default is 4 which indicates cubic spline |
m |
m indicates the number of points of coefficients to estimate |
A list contains the PACF in each lag
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } sie.auto.pacf(time.series, 5, 1, "Legen")
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } sie.auto.pacf(time.series, 5, 1, "Legen")
sie.auto.plot() visualizes the estimation of coefficient, gives the elbow plot and represents the cross validation result.
sie.auto.plot(res.auto.fit, type, title = "")
sie.auto.plot(res.auto.fit, type, title = "")
res.auto.fit |
the output from sie.auto.fit() function |
type |
type indicates which type of basis is used (There are 31 types in this package) |
title |
give the title for the auto estimate plot |
A list which contains 3 plot related to the estimation of coefficient, Elbow point and cross validation in order
sie.plot.pacf() shows the PACF with different lag.
sie.plot.pacf(ts, c, lag, type, ops = "2d", title = "", m = 500, or = 4)
sie.plot.pacf(ts, c, lag, type, ops = "2d", title = "", m = 500, or = 4)
ts |
ts is the data set which is a time series data typically |
c |
c indicates the number of basis used to estimate (For wavelet, the number of basis is 2^c. If Cspli is chosen, the real number of basis is c-2+or) |
lag |
lag b is the lag for auto-regressive model |
type |
type indicates which type of basis is used (There are 32 types in this package) |
ops |
choose 2D plot or 3D plot ("2d" inicates 2D plot and "3d" indicates 3D plot) |
title |
give the title for the pacf plot |
m |
m indicates the number of points of coefficients to estimate |
or |
or indicates the order of spline, default is 4 which indicates cubic spline |
The plot of pacf basis on the time series data
predict.nts() predicts the time series data basis on the estimation.
sie.predict(ts, esti.li, h)
sie.predict(ts, esti.li, h)
ts |
The data set which is a time series data typically |
esti.li |
The output from fix.fit() or sie.auto.fit() function |
h |
h indicates the number of forecasting points |
A vector which contains h forecasting points
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } res1.2 = fix.fit(time.series, 5, 1, "Legen") sie.predict(time.series, res1.2, 5)
set.seed(137) time.series = c() n = 1024 v = 25 w = rnorm(n, 0, 1) / v x_ini = runif(1,0,1) for(i in 1:n){ if(i == 1){ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*x_ini + w[i] # } else{ time.series[i] = 0.2 + 0.6*cos(2*pi*(i/n))*time.series[i-1] + w[i] } } res1.2 = fix.fit(time.series, 5, 1, "Legen") sie.predict(time.series, res1.2, 5)