| Title: | Quantile-Frequency Analysis (QFA) of Time Series and Spline Quantile Regression (SQR) |
|---|---|
| Description: | Implementation of quantile frequency analysis (QFA) for time series based on trigonometric quantile regression and of spline quantile regression (SQR) for estimating the coefficients in linear quantile regression models as smooth functions of the quantile level. References: [1] Li, T.-H. (2012). ''Quantile periodograms,'' J. of the American Statistical Association, 107, 765–776. <doi:10.1080/01621459.2012.682815> [2] Li, T.-H. (2014). Time Series with Mixed Spectra, CRC Press. <doi:10.1201/b15154> [3] Li, T.-H. (2025). ''Quantile Fourier transform, quantile series, and nonparametric estimation of quantile spectra,'' Communications in Statistics: Simulation and Computation, 1–22. <doi:10.1080/03610918.2025.2509820> [4] Li, T.-H. (2025). ''Quantile-crossing spectrum and spline autoregression estimation,'' Statistical Inference for Stochastic Processes, 28, 20. <doi:10.1007/s11203-025-09336-7> [5] Li, T.-H. (2025). ''Spline autoregression method for estimation of quantile spectrum,'' J. of Computational and Graphical Statistics, 1-15. <doi:10.1080/10618600.2025.2549452> [6] Li, T.-H., and Megiddo, N. (2026). ''Spline quantile regression,'' J. of Statistical Theory and Practice, 20, 30. <doi:10.1007/s42519-026-00545-8> [7] Li, T.-H. (2026). ''Spline quantile regression with cubic and linear smoothing splines,'' <doi:10.48550/arXiv.2603.22408>. |
| Authors: | Ta-Hsin Li [cre, aut] |
| Maintainer: | Ta-Hsin Li <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 5.0 |
| Built: | 2026-05-29 09:21:57 UTC |
| Source: | https://github.com/cran/qfa |
A random sample of US birth data in 2022 (birth weight and covariates). Precare and Education should be treated as factors.
data(birthweight)data(birthweight)
An object of class data.frame with 50000 rows and 12 columns.
Data file https://data.nber.org/nvss/natality/csv/2022/natality2022us.csv from NBER https://www.nber.org/research/data/vital-statistics-natality-birth-data. Original source from the National Center for Health Statistics https://www.cdc.gov/nchs/nvss/births.htm.
Koenker, R. (2005). Quantile Regression. Cambridge University Press.
This function generates bootstrap samples for the SQR coefficients and their derivatives
boot.sqr( fit, nsim = 1000, blocklength = 1, n.cores = 1, mthreads = FALSE, seed = 1234567 )boot.sqr( fit, nsim = 1000, blocklength = 1, n.cores = 1, mthreads = FALSE, seed = 1234567 )
fit |
output from |
nsim |
number of bootstrap samples (default = 1000) |
blocklength |
blocklength for block sampling scheme (default = 1) |
n.cores |
number of cores for parallel computing (default = 1) |
mthreads |
if |
seed |
seed of random number generator (default = 1234567) |
A list with the following elements:
coefficients |
array of bootstrap regression coefficients |
derivatives |
array of boostrap derivatives of regression coefficient |
info |
sequence convergence status |
Engel's food expenditure data from the R package 'quantreg'.
data(engel)data(engel)
An object of class data.frame with 235 rows and 2 columns.
Koenker, R. (2005). Quantile Regression. Cambridge University Press.
Daily closing values of DJIA and FTSE 100 on trading days from 2001-11-27 to 2010-03-10.
data(finIndex)data(finIndex)
An object of class data.frame with 2048 rows and 3 columns.
https://www.wsj.com/market-data/quotes/index/DJIA/historical-prices and https://www.wsj.com/market-data/quotes/index/UK/UKX/historical-prices
This function computes the periodogram or periodogram matrix for univariate or multivariate time series.
per(y)per(y)
y |
vector or matrix of time series s (if matrix, nrow(y) = length of time series) |
vector or array of periodogram
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y.per <- per(y) plot(y.per)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y.per <- per(y) plot(y.per)
This function computes quantile autocovariance function (QACF) from time series or quantile discrete Fourier transform (QDFT).
qacf(y, tau, y.qdft = NULL, n.cores = 1, cl = NULL)qacf(y, tau, y.qdft = NULL, n.cores = 1, cl = NULL)
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels in (0,1) |
y.qdft |
matrix or array of pre-calculated QDFT (default = |
n.cores |
number of cores for parallel computing of QDFT if |
cl |
pre-existing cluster for repeated parallel computing of QDFT (default = |
matrix or array of quantile autocovariance function
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) # compute from time series y.qacf <- qacf(y,tau) # compute from QDFT y.qdft <- qdft(y,tau) y.qacf <- qacf(y.qdft=y.qdft)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) # compute from time series y.qacf <- qacf(y,tau) # compute from QDFT y.qdft <- qdft(y,tau) y.qacf <- qacf(y.qdft=y.qdft)
This function creates the quantile-crossing series (QCSER) for univariate or multivariate time series.
qcser(y, tau, normalize = FALSE)qcser(y, tau, normalize = FALSE)
y |
vector or matrix of time series |
tau |
sequence of quantile levels in (0,1) |
normalize |
|
A matrix or array of quantile-crossing series
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qser <- qcser(y,tau) dim(y.qser)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qser <- qcser(y,tau) dim(y.qser)
This function computes quantile discrete Fourier transform (QDFT) for univariate or multivariate time series.
qdft(y, tau, n.cores = 1, cl = NULL)qdft(y, tau, n.cores = 1, cl = NULL)
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels in (0,1) |
n.cores |
number of cores for parallel computing (default = 1) |
cl |
pre-existing cluster for repeated parallel computing (default = |
matrix or array of quantile discrete Fourier transform of y
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y,tau) # Make a cluster for repeated use n.cores <- 2 cl <- parallel::makeCluster(n.cores) parallel::clusterExport(cl, c("tqr.fit")) doParallel::registerDoParallel(cl) y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y.qdft <- qdft(y1,tau,n.cores=n.cores,cl=cl) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y.qdft <- qdft(y2,tau,n.cores=n.cores,cl=cl) parallel::stopCluster(cl)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y,tau) # Make a cluster for repeated use n.cores <- 2 cl <- parallel::makeCluster(n.cores) parallel::clusterExport(cl, c("tqr.fit")) doParallel::registerDoParallel(cl) y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y.qdft <- qdft(y1,tau,n.cores=n.cores,cl=cl) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y.qdft <- qdft(y2,tau,n.cores=n.cores,cl=cl) parallel::stopCluster(cl)
This function computes quantile autocovariance function (QACF) from QDFT.
qdft2qacf(y.qdft, return.qser = FALSE)qdft2qacf(y.qdft, return.qser = FALSE)
y.qdft |
matrix or array of QDFT from |
return.qser |
if |
matrix or array of quantile autocovariance function if return.sqer = FALSE (default), else a list with the following elements:
qacf |
matirx or array of quantile autocovariance function |
qser |
matrix or array of quantile series |
# single time series y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y1,tau) y.qacf <- qdft2qacf(y.qdft) plot(c(0:9),y.qacf[c(1:10),1],type='h',xlab="LAG",ylab="QACF") y.qser <- qdft2qacf(y.qdft,return.qser=TRUE)$qser plot(y.qser[,1],type='l',xlab="TIME",ylab="QSER") # multiple time series y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y.qdft <- qdft(cbind(y1,y2),tau) y.qacf <- qdft2qacf(y.qdft) plot(c(0:9),y.qacf[1,2,c(1:10),1],type='h',xlab="LAG",ylab="QACF")# single time series y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y1,tau) y.qacf <- qdft2qacf(y.qdft) plot(c(0:9),y.qacf[c(1:10),1],type='h',xlab="LAG",ylab="QACF") y.qser <- qdft2qacf(y.qdft,return.qser=TRUE)$qser plot(y.qser[,1],type='l',xlab="TIME",ylab="QSER") # multiple time series y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y.qdft <- qdft(cbind(y1,y2),tau) y.qacf <- qdft2qacf(y.qdft) plot(c(0:9),y.qacf[1,2,c(1:10),1],type='h',xlab="LAG",ylab="QACF")
This function computes quantile periodogram (QPER) from QDFT.
qdft2qper(y.qdft)qdft2qper(y.qdft)
y.qdft |
matrix or array of QDFT from |
matrix or array of quantile periodogram
# single time series y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y1,tau) y.qper <- qdft2qper(y.qdft) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) qfa.plot(ff[sel.f],tau,Re(y.qper[sel.f,])) # multiple time series y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y.qdft <- qdft(cbind(y1,y2),tau) y.qper <- qdft2qper(y.qdft) qfa.plot(ff[sel.f],tau,Re(y.qper[1,1,sel.f,])) qfa.plot(ff[sel.f],tau,Re(y.qper[1,2,sel.f,]))# single time series y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y1,tau) y.qper <- qdft2qper(y.qdft) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) qfa.plot(ff[sel.f],tau,Re(y.qper[sel.f,])) # multiple time series y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y.qdft <- qdft(cbind(y1,y2),tau) y.qper <- qdft2qper(y.qdft) qfa.plot(ff[sel.f],tau,Re(y.qper[1,1,sel.f,])) qfa.plot(ff[sel.f],tau,Re(y.qper[1,2,sel.f,]))
This function computes quantile series (QSER) from QDFT.
qdft2qser(y.qdft)qdft2qser(y.qdft)
y.qdft |
matrix or array of QDFT from |
matrix or array of quantile series
# single time series y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y1,tau) y.qser <- qdft2qser(y.qdft) plot(y.qser[,1],type='l',xlab="TIME",ylab="QSER") # multiple time series y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y.qdft <- qdft(cbind(y1,y2),tau) y.qser <- qdft2qser(y.qdft) plot(y.qser[1,,1],type='l',xlab="TIME",ylab="QSER")# single time series y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qdft <- qdft(y1,tau) y.qser <- qdft2qser(y.qdft) plot(y.qser[,1],type='l',xlab="TIME",ylab="QSER") # multiple time series y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y.qdft <- qdft(cbind(y1,y2),tau) y.qser <- qdft2qser(y.qdft) plot(y.qser[1,,1],type='l',xlab="TIME",ylab="QSER")
This function creates an image plot of quantile spectrum.
qfa.plot( freq, tau, rqper, rg.qper = range(rqper), rg.tau = range(tau), rg.freq = c(0, 0.5), color = colorRamps::matlab.like2(1024), ylab = "QUANTILE LEVEL", xlab = "FREQUENCY", tlab = NULL, set.par = TRUE, legend.plot = TRUE, line = 0.5 )qfa.plot( freq, tau, rqper, rg.qper = range(rqper), rg.tau = range(tau), rg.freq = c(0, 0.5), color = colorRamps::matlab.like2(1024), ylab = "QUANTILE LEVEL", xlab = "FREQUENCY", tlab = NULL, set.par = TRUE, legend.plot = TRUE, line = 0.5 )
freq |
sequence of frequencies in (0,0.5) at which quantile spectrum is evaluated |
tau |
sequence of quantile levels in (0,1) at which quantile spectrum is evaluated |
rqper |
real-valued matrix of quantile spectrum evaluated on the |
rg.qper |
|
rg.tau |
|
rg.freq |
|
color |
colors (default = |
ylab |
label of y-axis (default = |
xlab |
label of x-axis (default = |
tlab |
title of plot (default = |
set.par |
if |
legend.plot |
if |
line |
distance between the image and the axis (default = 0.5) |
no return value
This function computes Kullback-Leibler divergence (KLD) of quantile spectral estimate.
qkl.divergence(y.qper, qspec, sel.f = NULL, sel.tau = NULL)qkl.divergence(y.qper, qspec, sel.f = NULL, sel.tau = NULL)
y.qper |
matrix or array of quantile spectral estimate from, e.g., |
qspec |
matrix of array of true quantile spectrum (same dimension as |
sel.f |
index of selected frequencies for computation (default = |
sel.tau |
index of selected quantile levels for computation (default = |
real number of Kullback-Leibler divergence
This function computes quantile periodogram (QPER) from time series or quantile discrete Fourier transform (QDFT).
qper(y, tau, y.qdft = NULL, n.cores = 1, cl = NULL)qper(y, tau, y.qdft = NULL, n.cores = 1, cl = NULL)
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels in (0,1) |
y.qdft |
matrix or array of pre-calculated QDFT (default = |
n.cores |
number of cores for parallel computing of QDFT if |
cl |
pre-existing cluster for repeated parallel computing of QDFT (default = |
matrix or array of quantile periodogram
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) # compute from time series y.qper <- qper(y,tau) # compute from QDFT y.qdft <- qdft(y,tau) y.qper <- qper(y.qdft=y.qdft)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) # compute from time series y.qper <- qper(y,tau) # compute from QDFT y.qdft <- qdft(y,tau) y.qper <- qper(y.qdft=y.qdft)
This function computes type-II quantile periodogram for univariate time series.
qper2(y, freq, tau, weights = NULL, n.cores = 1, cl = NULL)qper2(y, freq, tau, weights = NULL, n.cores = 1, cl = NULL)
y |
univariate time series |
freq |
sequence of frequencies in [0,1) |
tau |
sequence of quantile levels in (0,1) |
weights |
sequence of weights in quantile regression (default = |
n.cores |
number of cores for parallel computing (default = 1) |
cl |
pre-existing cluster for repeated parallel computing (default = |
matrix of quantile periodogram evaluated on freq * tau grid
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qper2 <- qper2(y,ff,tau) qfa.plot(ff[sel.f],tau,Re(y.qper2[sel.f,]))y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qper2 <- qper2(y,ff,tau) qfa.plot(ff[sel.f],tau,Re(y.qper2[sel.f,]))
This function computes quantile series (QSER) from time series or quantile discrete Fourier transform (QDFT).
qser(y, tau, y.qdft = NULL, n.cores = 1, cl = NULL)qser(y, tau, y.qdft = NULL, n.cores = 1, cl = NULL)
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels in (0,1) |
y.qdft |
matrix or array of pre-calculated QDFT (default = |
n.cores |
number of cores for parallel computing of QDFT if |
cl |
pre-existing cluster for repeated parallel computing of QDFT (default = |
matrix or array of quantile series
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) # compute from time series y.qser <- qser(y,tau) # compute from QDFT y.qdft <- qdft(y,tau) y.qser <- qser(y.qdft=y.qdft)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) # compute from time series y.qser <- qser(y,tau) # compute from QDFT y.qdft <- qdft(y,tau) y.qser <- qser(y.qdft=y.qdft)
This function fits an autoregression (AR) model to quantile series (QSER) separately for each quantile level using stats::ar().
qser2ar( y.qser, p = NULL, order.max = NULL, method = c("none", "gamm", "sp"), spar = NULL, type = c(1, 2) )qser2ar( y.qser, p = NULL, order.max = NULL, method = c("none", "gamm", "sp"), spar = NULL, type = c(1, 2) )
y.qser |
matrix or array of pre-calculated QSER, e.g., using |
p |
order of AR model (default = |
order.max |
maximum order for AIC if |
method |
quantile smoothing method: |
spar |
smoothing parameter for |
type |
type of smoothing for covariance matrix: 1 (direct, default) or 2 (square root) |
a list with the following elements:
A |
matrix or array of AR coefficients |
V |
vector or matrix of residual covariance |
p |
order of AR model |
n |
length of time series |
residuals |
matrix or array of residuals |
This function creates the ACF of quantile series or quantile-crossing series
qser2qacf(y.qser)qser2qacf(y.qser)
y.qser |
matrix or array of quantile-crossing series |
A matrix or array of ACF
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qser <- qcser(y,tau) y.qacf <- qser2qacf(y.qser) dim(y.qacf)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.qser <- qcser(y,tau) y.qacf <- qser2qacf(y.qser) dim(y.qacf)
This function fits spline autoregression (SAR) model to quantile series (QSER).
qser2sar( y.qser, tau0, tau = tau0, p = NULL, order.max = NULL, spar = NULL, method = c("GCV", "AIC", "BIC"), type = c(1, 2), weights = rep(1, length(tau0)), interval = c(-1.5, 1.5) )qser2sar( y.qser, tau0, tau = tau0, p = NULL, order.max = NULL, spar = NULL, method = c("GCV", "AIC", "BIC"), type = c(1, 2), weights = rep(1, length(tau0)), interval = c(-1.5, 1.5) )
y.qser |
matrix or array of pre-calculated QSER at |
tau0 |
quantile levels used to compute |
tau |
quantile levels for evaluation ( |
p |
order of SAR model (default = |
order.max |
maximum order for AIC if |
spar |
penalty parameter alla |
method |
criterion for penalty parameter selection: |
type |
type of quantile smoothing for residual variance: 1 = direct (default) or 2 = square root |
weights |
sequence of weights (default = |
interval |
interval for |
a list with the following elements:
A |
matrix or array of SAR coefficients |
V |
vector or matrix of SAR residual covariance |
p |
order of SAR model |
spar |
penalty parameter |
n |
length of time series |
tau |
quantile levels for evaluation |
tau0 |
quantile levels for fitting |
weights |
weights in penalty function |
sdm |
spline design matrices |
fit |
object containing details of SAR fit |
This function computes autoregression (AR) estimate of quantile spectrum from time series or quantile series (QSER).
qspec.ar( y, tau, y.qser = NULL, p = NULL, order.max = NULL, freq = NULL, method = c("none", "gamm", "sp"), spar = NULL, type = c(1, 2), n.cores = 1, cl = NULL )qspec.ar( y, tau, y.qser = NULL, p = NULL, order.max = NULL, freq = NULL, method = c("none", "gamm", "sp"), spar = NULL, type = c(1, 2), n.cores = 1, cl = NULL )
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels in (0,1) |
y.qser |
matrix or array of pre-calculated QSER (default = |
p |
order of AR model (default = |
order.max |
maximum order for AIC if |
freq |
sequence of frequencies in [0,1) (default = |
method |
method of quantile smoothing: |
spar |
smoothing parameter for |
type |
type of smoothing for covariance matrix: 1 (direct, default) or 2 (square root) |
n.cores |
number of cores for parallel computing of QDFT if |
cl |
pre-existing cluster for repeated parallel computing of QDFT (default = |
a list with the following elements:
spec |
matrix or array of AR quantile spectrum |
freq |
sequence of frequencies |
fit |
object of AR model |
qser |
matrix or array of quantile series if |
y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y <- cbind(y1,y2) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qspec.ar <- qspec.ar(y,tau,p=1)$spec qfa.plot(ff[sel.f],tau,Re(y.qspec.ar[1,1,sel.f,])) y.qser <- qcser(y1,tau) y.qspec.ar <- qspec.ar(y.qser=y.qser,p=1)$spec qfa.plot(ff[sel.f],tau,Re(y.qspec.ar[sel.f,])) y.qspec.arqs <- qspec.ar(y.qser=y.qser,p=1,method="sp")$spec qfa.plot(ff[sel.f],tau,Re(y.qspec.arqs[sel.f,]))y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y <- cbind(y1,y2) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qspec.ar <- qspec.ar(y,tau,p=1)$spec qfa.plot(ff[sel.f],tau,Re(y.qspec.ar[1,1,sel.f,])) y.qser <- qcser(y1,tau) y.qspec.ar <- qspec.ar(y.qser=y.qser,p=1)$spec qfa.plot(ff[sel.f],tau,Re(y.qspec.ar[sel.f,])) y.qspec.arqs <- qspec.ar(y.qser=y.qser,p=1,method="sp")$spec qfa.plot(ff[sel.f],tau,Re(y.qspec.arqs[sel.f,]))
This function computes lag-window (LW) estimate of quantile spectrum with or without quantile smoothing from time series or quantile autocovariance function (QACF).
qspec.lw( y, tau, y.qacf = NULL, M = NULL, method = c("none", "gamm", "sp"), spar = "GCV", n.cores = 1, cl = NULL )qspec.lw( y, tau, y.qacf = NULL, M = NULL, method = c("none", "gamm", "sp"), spar = "GCV", n.cores = 1, cl = NULL )
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels in (0,1) |
y.qacf |
matrix or array of pre-calculated QACF (default = |
M |
bandwidth parameter of lag window (default = |
method |
quantile smoothing method: |
spar |
smoothing parameter in |
n.cores |
number of cores for parallel computing (default = 1) |
cl |
pre-existing cluster for repeated parallel computing (default = |
A list with the following elements:
spec |
matrix or array of spectral estimate |
spec.lw |
matrix or array of spectral estimate without quantile smoothing |
lw |
lag-window sequence |
qacf |
matrix or array of quantile autocovariance function if |
y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qacf <- qacf(cbind(y1,y2),tau) y.qper.lw <- qspec.lw(y.qacf=y.qacf,M=5)$spec qfa.plot(ff[sel.f],tau,Re(y.qper.lw[1,1,sel.f,])) y.qper.lwqs <- qspec.lw(y.qacf=y.qacf,M=5,method="sp",spar=0.9)$spec qfa.plot(ff[sel.f],tau,Re(y.qper.lwqs[1,1,sel.f,]))y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qacf <- qacf(cbind(y1,y2),tau) y.qper.lw <- qspec.lw(y.qacf=y.qacf,M=5)$spec qfa.plot(ff[sel.f],tau,Re(y.qper.lw[1,1,sel.f,])) y.qper.lwqs <- qspec.lw(y.qacf=y.qacf,M=5,method="sp",spar=0.9)$spec qfa.plot(ff[sel.f],tau,Re(y.qper.lwqs[1,1,sel.f,]))
This function computes spline autoregression (SAR) estimate of quantile spectrum.
qspec.sar( y, y.qser = NULL, tau0, tau = tau0, p = NULL, order.max = NULL, spar = NULL, method = c("GCV", "AIC", "BIC"), type = c(1, 2), weights = rep(1, length(tau0)), interval = c(-1.5, 1.5), freq = NULL, n.cores = 1, cl = NULL )qspec.sar( y, y.qser = NULL, tau0, tau = tau0, p = NULL, order.max = NULL, spar = NULL, method = c("GCV", "AIC", "BIC"), type = c(1, 2), weights = rep(1, length(tau0)), interval = c(-1.5, 1.5), freq = NULL, n.cores = 1, cl = NULL )
y |
vector or matrix of time series (if matrix, |
y.qser |
matrix or array of pre-calculated QSER at |
tau0 |
quantile levels used to computer QSER (must be supplied with or without |
tau |
quantile levels for evaluation ( |
p |
order of SAR model (default = |
order.max |
maximum order for AIC if |
spar |
penalty parameter alla |
method |
criterion for penalty parameter selection: |
type |
type of quantile smoothing for residual variance: 1 = direct (default) or 2 = square root |
weights |
sequence of weights ( |
interval |
interval for spar optimization (default: |
freq |
sequence of frequencies in [0,1) (default = |
n.cores |
number of cores for parallel computing of QDFT if |
cl |
pre-existing cluster for repeated parallel computing of QDFT (default = |
a list with the following elements:
spec |
matrix or array of SAR quantile spectrum |
freq |
sequence of frequencies |
fit |
object of SAR model |
qser |
matrix or array of quantile series if |
y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) # compute from time series y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) qfa.plot(ff[sel.f],tau,Re(y.sar$spec[1,1,sel.f,])) # compute from quantile series y.qser <- qser(cbind(y1,y2),tau) y.sar <- qspec.sar(y.qser=y.qser,tau0=tau,p=1) qfa.plot(ff[sel.f],tau,Re(y.sar$spec[1,1,sel.f,]))y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) # compute from time series y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) qfa.plot(ff[sel.f],tau,Re(y.sar$spec[1,1,sel.f,])) # compute from quantile series y.qser <- qser(cbind(y1,y2),tau) y.sar <- qspec.sar(y.qser=y.qser,tau0=tau,p=1) qfa.plot(ff[sel.f],tau,Re(y.sar$spec[1,1,sel.f,]))
This function computes quantile coherence spectrum (QCOH) from quantile spectrum of multiple time series.
qspec2qcoh(qspec, k = 1, kk = 2)qspec2qcoh(qspec, k = 1, kk = 2)
qspec |
array of quantile spectrum |
k |
index of first series (default = 1) |
kk |
index of second series (default = 2) |
matrix of quantile coherence evaluated at Fourier frequencies in (0,0.5)
y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qacf <- qacf(cbind(y1,y2),tau) y.qper.lw <- qspec.lw(y.qacf=y.qacf,M=5)$spec y.qcoh <- qspec2qcoh(y.qper.lw,k=1,kk=2) qfa.plot(ff[sel.f],tau,y.qcoh)y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) n <- length(y1) ff <- c(0:(n-1))/n sel.f <- which(ff > 0 & ff < 0.5) y.qacf <- qacf(cbind(y1,y2),tau) y.qper.lw <- qspec.lw(y.qacf=y.qacf,M=5)$spec y.qcoh <- qspec2qcoh(y.qper.lw,k=1,kk=2) qfa.plot(ff[sel.f],tau,y.qcoh)
This function simulates bootstrap samples of selected spline autoregression (SAR) coefficients for testing equality of Granger-causality in two samples based on their SAR models under H0: effect in each sample equals the average effect.
sar.eq.bootstrap( y.qser, fit, fit2, index = c(1, 2), nsim = 1000, method = c("ar", "sar"), refit = FALSE, n.cores = 1, mthreads = FALSE, seed = 1234567 )sar.eq.bootstrap( y.qser, fit, fit2, index = c(1, 2), nsim = 1000, method = c("ar", "sar"), refit = FALSE, n.cores = 1, mthreads = FALSE, seed = 1234567 )
y.qser |
matrix or array of QSER from |
fit |
object of SAR model from |
fit2 |
object of SAR model for the other sample |
index |
a pair of component indices for multiple time series
or a sequence of lags for single time series (default = |
nsim |
number of bootstrap samples (default = 1000) |
method |
method of residual calculation: |
refit |
if |
n.cores |
number of cores for parallel computing (default = 1) |
mthreads |
if |
seed |
seed for random sampling (default = |
array of simulated bootstrap samples of selected SAR coefficients
y11 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y21 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y12 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y22 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y1.sar <- qspec.sar(cbind(y11,y21),tau0=tau,p=1) y2.sar <- qspec.sar(cbind(y12,y22),tau0=tau,p=1) A1.sim <- sar.eq.bootstrap(y1.sar$qser,y1.sar$fit,y2.sar$fit,index=c(1,2),nsim=5) A2.sim <- sar.eq.bootstrap(y2.sar$qser,y2.sar$fit,y1.sar$fit,index=c(1,2),nsim=5)y11 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y21 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y12 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y22 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y1.sar <- qspec.sar(cbind(y11,y21),tau0=tau,p=1) y2.sar <- qspec.sar(cbind(y12,y22),tau0=tau,p=1) A1.sim <- sar.eq.bootstrap(y1.sar$qser,y1.sar$fit,y2.sar$fit,index=c(1,2),nsim=5) A2.sim <- sar.eq.bootstrap(y2.sar$qser,y2.sar$fit,y1.sar$fit,index=c(1,2),nsim=5)
This function computes Wald test and confidence band for equality of Granger-causality in two samples
using bootstrap samples generated by sar.eq.bootstrap() based on the spline autoregression (SAR) models
of quantile series (QSER).
sar.eq.test(A1, A1.sim, A2, A2.sim, sel.lag = NULL, sel.tau = NULL)sar.eq.test(A1, A1.sim, A2, A2.sim, sel.lag = NULL, sel.tau = NULL)
A1 |
matrix of selected SAR coefficients for sample 1 |
A1.sim |
simulated bootstrap samples from |
A2 |
matrix of selected SAR coefficients for sample 2 |
A2.sim |
simulated bootstrap samples from |
sel.lag |
indices of time lags for Wald test (default = |
sel.tau |
indices of quantile levels for Wald test (default = |
a list with the following elements:
test |
list of Wald test result containing |
D.u |
matrix of upper limits of 95% confidence band for |
D.l |
matrix of lower limits of 95% confidence band for |
y11 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y21 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y12 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y22 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y1.sar <- qspec.sar(cbind(y11,y21),tau0=tau,p=1) y2.sar <- qspec.sar(cbind(y12,y22),tau0=tau,p=1) A1.sim <- sar.eq.bootstrap(y1.sar$qser,y1.sar$fit,y2.sar$fit,index=c(1,2),nsim=5) A2.sim <- sar.eq.bootstrap(y2.sar$qser,y2.sar$fit,y1.sar$fit,index=c(1,2),nsim=5) A1 <- sar.gc.coef(y1.sar$fit,index=c(1,2)) A2 <- sar.gc.coef(y2.sar$fit,index=c(1,2)) test <- sar.eq.test(A1,A1.sim,A2,A2.sim,sel.lag=NULL,sel.tau=NULL)y11 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y21 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) y12 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y22 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y1.sar <- qspec.sar(cbind(y11,y21),tau0=tau,p=1) y2.sar <- qspec.sar(cbind(y12,y22),tau0=tau,p=1) A1.sim <- sar.eq.bootstrap(y1.sar$qser,y1.sar$fit,y2.sar$fit,index=c(1,2),nsim=5) A2.sim <- sar.eq.bootstrap(y2.sar$qser,y2.sar$fit,y1.sar$fit,index=c(1,2),nsim=5) A1 <- sar.gc.coef(y1.sar$fit,index=c(1,2)) A2 <- sar.gc.coef(y2.sar$fit,index=c(1,2)) test <- sar.eq.test(A1,A1.sim,A2,A2.sim,sel.lag=NULL,sel.tau=NULL)
This function simulates bootstrap samples of selected spline autoregression (SAR) coefficients
for Granger-causality analysis based on the SAR model of quantile series (QSER) under H0:
(a) for multiple time series, the second series specified in index is not causal
for the first series specified in index;
(b) for single time series, the series is not causal at the lags specified in index.
sar.gc.bootstrap( y.qser, fit, index = c(1, 2), nsim = 1000, method = c("ar", "sar"), refit = FALSE, n.cores = 1, mthreads = FALSE, seed = 1234567 )sar.gc.bootstrap( y.qser, fit, index = c(1, 2), nsim = 1000, method = c("ar", "sar"), refit = FALSE, n.cores = 1, mthreads = FALSE, seed = 1234567 )
y.qser |
matrix or array of QSER from |
fit |
object of SAR model from |
index |
a pair of component indices for multiple time series
or a sequence of lags for single time series (default = |
nsim |
number of bootstrap samples (default = 1000) |
method |
method of residual calculation: |
refit |
if |
n.cores |
number of cores for parallel computing (default = 1) |
mthreads |
if |
seed |
seed for random sampling (default = |
array of simulated bootstrap samples of selected SAR coefficients
y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) A.sim <- sar.gc.bootstrap(y.sar$qser,y.sar$fit,index=c(1,2),nsim=5)y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) A.sim <- sar.gc.bootstrap(y.sar$qser,y.sar$fit,index=c(1,2),nsim=5)
This function extracts the spline autoregression (SAR) coefficients from an SAR model for Granger-causality analysis.
See sar.gc.bootstrap for more details regarding the use of index.
sar.gc.coef(fit, index = c(1, 2))sar.gc.coef(fit, index = c(1, 2))
fit |
object of SAR model from |
index |
a pair of component indices for multiple time series
or a sequence of lags for single time series (default = |
matrix of selected SAR coefficients (number of lags by number of quantiles)
y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) A <- sar.gc.coef(y.sar$fit,index=c(1,2))y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) A <- sar.gc.coef(y.sar$fit,index=c(1,2))
This function computes Wald test and confidence band for Granger-causality
using bootstrap samples generated by sar.gc.bootstrap()
based the spline autoregression (SAR) model of quantile series (QSER).
sar.gc.test(A, A.sim, sel.lag = NULL, sel.tau = NULL)sar.gc.test(A, A.sim, sel.lag = NULL, sel.tau = NULL)
A |
matrix of selected SAR coefficients |
A.sim |
simulated bootstrap samples from |
sel.lag |
indices of time lags for Wald test (default = |
sel.tau |
indices of quantile levels for Wald test (default = |
a list with the following elements:
test |
list of Wald test result containing |
A.u |
matrix of upper limits of 95% confidence band of |
A.l |
matrix of lower limits of 95% confidence band of |
y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) A <- sar.gc.coef(y.sar$fit,index=c(1,2)) A.sim <- sar.gc.bootstrap(y.sar$qser,y.sar$fit,index=c(1,2),nsim=5) y.gc <- sar.gc.test(A,A.sim)y1 <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) y2 <- stats::arima.sim(list(order=c(1,0,0), ar=-0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sar <- qspec.sar(cbind(y1,y2),tau0=tau,p=1) A <- sar.gc.coef(y.sar$fit,index=c(1,2)) A.sim <- sar.gc.bootstrap(y.sar$qser,y.sar$fit,index=c(1,2),nsim=5) y.gc <- sar.gc.test(A,A.sim)
This function computes spline quantile discrete Fourier transform (SQDFT) for univariate or multivariate time series through trigonometric spline quantile regression.
sqdft( y, tau, tau0 = tau, spar = NULL, w = rep(1, length(tau0)), criterion = c("AIC", "BIC", "GIC"), method = c("sqr", "sqr1", "sqr3"), ztol = NULL, solver = NULL, interval = NULL, all.knots = FALSE, control = list(), n.cores = 1, cl = NULL )sqdft( y, tau, tau0 = tau, spar = NULL, w = rep(1, length(tau0)), criterion = c("AIC", "BIC", "GIC"), method = c("sqr", "sqr1", "sqr3"), ztol = NULL, solver = NULL, interval = NULL, all.knots = FALSE, control = list(), n.cores = 1, cl = NULL )
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels for evaluation |
tau0 |
sequence of quantile levels for fitting ( |
spar |
smoothing parameter, selected automatically by |
w |
weight sequence in penalty (default = |
criterion |
criterion for smoothing parameter selection: |
method |
|
ztol |
zero-tolerance parameter to determine the model complexity
(default = |
solver |
|
interval |
interval for |
all.knots |
|
control |
list of control parameters for QP solvers |
n.cores |
number of cores for parallel computing (default = 1) |
cl |
pre-existing cluster for repeated parallel computing (default = |
A list with the following elements:
coefficients |
matrix of regression coefficients |
qdft |
matrix or array of the spline quantile discrete Fourier transform of |
crit |
criteria for smoothing parameter selection: (AIC,BIC,GIC) |
nit |
maximum number of iterations |
spar |
optimal value of smoothing parameter |
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sqdft <- sqdft(y,tau,spar=0.2,method="sqr1")$qdft plot(y.sqdft[,2])y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) y.sqdft <- sqdft(y,tau,spar=0.2,method="sqr1")$qdft plot(y.sqdft[,2])
This function computes spline quantile discrete Fourier transform (SQDFT) for univariate or multivariate time series through trigonometric spline quantile regression with user-supplied spar.
sqdft.fit( y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), method = c("sqr", "sqr1", "sqr3"), ztol = NULL, solver = NULL, all.knots = FALSE, control = list(), n.cores = 1, cl = NULL )sqdft.fit( y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), method = c("sqr", "sqr1", "sqr3"), ztol = NULL, solver = NULL, all.knots = FALSE, control = list(), n.cores = 1, cl = NULL )
y |
vector or matrix of time series (if matrix, |
tau |
sequence of quantile levels for evaluation |
tau0 |
sequence of quantile levels for fitting ( |
spar |
smoothing parameter (default = 1) |
w |
weight sequence in penalty (default = |
method |
|
ztol |
zero-tolerance parameter to determine the model complexity
(default = |
solver |
|
all.knots |
|
control |
list of control parameters for QP solvers |
n.cores |
number of cores for parallel computing (default = 1) |
cl |
pre-existing cluster for repeated parallel computing (default = |
A list with the following elements:
coefficients |
matrix of regression coefficients |
qdft |
matrix or array of the spline quantile discrete Fourier transform of |
crit |
criteria for smoothing parameter selection: (AIC,BIC,GIC) |
nit |
maximum number of iterations |
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) tau0 <- seq(0.1,0.9,0.2) y.sqdft <- sqdft.fit(y,tau,tau0=tau0,spar=0.2,method="sqr1")$qdfty <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) tau0 <- seq(0.1,0.9,0.2) y.sqdft <- sqdft.fit(y,tau,tau0=tau0,spar=0.2,method="sqr1")$qdft
This function computes the spline quantile regression solution SQR, SQR1, or SAR3
on a given set of quantile levels from a regression formula with or without user-supplied smoothing parameter.
SQR represents the regression coefficients as cubic spline functions of the quantile level and employs the L1-norm of their second derivative as roughness penalty.
SQR1 represents the regression coefficients as linear spline functions and employs the total variation of their first derivatives
as roughness penalty. SQR3 also represents the regression coefficients as cubic spline functions but employs the L2-norm of their second
derivatives as roughness penalty. SQR and SQR1 are solved as linear program (LP) using sqr.fit() and
sqr1.fit(), respectively. SQR3 is solved as quadratic program (QP) using sqr3.fit().
sqr( formula, tau = seq(0.1, 0.9, 0.2), tau0 = tau, spar = NULL, w = rep(1, length(tau0)), mthreads = FALSE, criterion = c("AIC", "BIC", "GIC"), method = c("sqr", "sqr1", "sqr3"), type = c("dual", "primal"), ztol = NULL, solver = NULL, interval = NULL, npar = c(1, 2), all.knots = FALSE, control = list(), data, subset, na.action, model = TRUE )sqr( formula, tau = seq(0.1, 0.9, 0.2), tau0 = tau, spar = NULL, w = rep(1, length(tau0)), mthreads = FALSE, criterion = c("AIC", "BIC", "GIC"), method = c("sqr", "sqr1", "sqr3"), type = c("dual", "primal"), ztol = NULL, solver = NULL, interval = NULL, npar = c(1, 2), all.knots = FALSE, control = list(), data, subset, na.action, model = TRUE )
formula |
formula object, with the response on the left of a ~ operator, and the terms, separated by + operators, on the right. |
tau |
sequence of quantile levels for evaluation |
tau0 |
sequence of quantile levels for fitting ( |
spar |
smoothing parameter, selected automatically by |
w |
weight sequence in penalty (default = |
mthreads |
if |
criterion |
criterion for smoothing parameter selection ( |
method |
|
type |
type of QP formulation for SQR3: |
ztol |
zero-tolerance parameter to determine the model complexity
(default = |
solver |
|
interval |
interval for |
npar |
experimental parameter (default = 1) |
all.knots |
|
control |
list of control parameters for QP solvers |
data |
data.frame object containing the observations |
subset |
an optional vector specifying a subset of observations to be used |
na.action |
a function to filter missing data (see |
model |
if |
object of sqr.fit(), sqr1.fit(), or sqr3.fit()
library(quantreg) data(engel) engel$income <- (engel$income - mean(engel$income))/1000 tau <- seq(0.1,0.9,0.05) fit <- rq(foodexp ~ income,tau=tau,data=engel) fit.sqr1 <- sqr(foodexp ~ income,tau=tau,spar=0.5,method="sqr1",data=engel) fit.sqr3 <- sqr(foodexp ~ income,tau=tau,spar=0.5,method="sqr3",data=engel) par(mfrow=c(1,1),pty="m",lab=c(10,10,2),mar=c(4,4,2,1)+0.1,las=1) plot(tau,fit$coef[2,],xlab="Quantile Level",ylab="Coeff1") lines(tau,fit.sqr1$coef[2,]) lines(tau,fit.sqr3$coef[2,],col=2)library(quantreg) data(engel) engel$income <- (engel$income - mean(engel$income))/1000 tau <- seq(0.1,0.9,0.05) fit <- rq(foodexp ~ income,tau=tau,data=engel) fit.sqr1 <- sqr(foodexp ~ income,tau=tau,spar=0.5,method="sqr1",data=engel) fit.sqr3 <- sqr(foodexp ~ income,tau=tau,spar=0.5,method="sqr3",data=engel) par(mfrow=c(1,1),pty="m",lab=c(10,10,2),mar=c(4,4,2,1)+0.1,las=1) plot(tau,fit$coef[2,],xlab="Quantile Level",ylab="Coeff1") lines(tau,fit.sqr1$coef[2,]) lines(tau,fit.sqr3$coef[2,],col=2)
This function plots the derivative of one or all coefficients from spline quantile regression (SQR) together with the corresponding first difference from quantile regression (QR) on a given sequence of quantiles against the quantile level.
sqr_deriv.plot( fit, fit.sqr, fit.sqrb = NULL, deriv.sim = NULL, type = "l", typeb = "s", var.names = NULL, lty = c(1, 2), lwd = c(1.5, 1), cex = 0.25, pch = 1, col = c(2, 1), idx = NULL, Ylim = NULL, xlim = NULL, plot.zero = TRUE, plot.ci = TRUE, set.par = TRUE, mfrow = NULL, lab = c(10, 7, 7), mar = c(2, 3, 2, 1) + 0.1, las = 1 )sqr_deriv.plot( fit, fit.sqr, fit.sqrb = NULL, deriv.sim = NULL, type = "l", typeb = "s", var.names = NULL, lty = c(1, 2), lwd = c(1.5, 1), cex = 0.25, pch = 1, col = c(2, 1), idx = NULL, Ylim = NULL, xlim = NULL, plot.zero = TRUE, plot.ci = TRUE, set.par = TRUE, mfrow = NULL, lab = c(10, 7, 7), mar = c(2, 3, 2, 1) + 0.1, las = 1 )
fit |
output of |
fit.sqr |
output of |
fit.sqrb |
output of |
deriv.sim |
output |
type |
as |
typeb |
as |
var.names |
user-supplied names of regression coefficients (including the intercept) |
lty |
line types for the primary and secondary SQR (default = |
lwd |
line widths for the primary and secondary SQR (default = |
cex |
as |
pch |
as |
col |
line colors for the primary and secondary SQR (default = |
idx |
index of individual coefficient to be plotted (default = |
Ylim |
user-supplied matrix of |
xlim |
user-supplied |
plot.zero |
|
plot.ci |
|
set.par |
|
mfrow |
parameter for resetting |
lab |
parameter for resetting |
mar |
parameter for resetting |
las |
parameter for resetting |
Ylim (invisible)
This function computes spline quantile regression solution with cubic splines and L1-norm roughness penalty (SQR)
from the response vector and the design matrix on a given set of quantile levels.
It uses the FORTRAN code rqfnb.f in the "quantreg" package with the kind permission of Dr. R. Koenker
or the R function rq.fit.sfn() in the same package as a sparse-matrix alternative. Both solve
the SQR problem as a linear program (LP).
sqr.fit( X, y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), mthreads = TRUE, ztol = 1e-05, solver = c("fnb", "sfn"), all.knots = FALSE )sqr.fit( X, y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), mthreads = TRUE, ztol = 1e-05, solver = c("fnb", "sfn"), all.knots = FALSE )
X |
design matrix (requirement: |
y |
response vector |
tau |
sequence of quantile levels for evaluation |
tau0 |
sequence of quantile levels for fitting ( |
spar |
smoothing parameter (default = 1) |
w |
weight sequence in penalty (default = |
mthreads |
if |
ztol |
zero-tolerance parameter to determine the model complexity (default = |
solver |
LP solver: |
all.knots |
|
A list with the following elements:
coefficients |
matrix of regression coefficients |
derivatives |
matrix of derivatives of regression coefficients |
crit |
criteria values for spar selection: (AIC,BIC,GIC) |
np |
sequence of complexity measure as the number of effective parameters |
fid |
sequence of fidelity measure as the quasi-likelihood |
info |
convergence status |
nit |
number of iterations |
K |
number of spline basis functions |
This function computes spline quantile regression with cubic splines and L1-norm roughness penalty by a gradient algorithm BFGS, ADAM, or GRAD.
sqr.fit.optim( X, y, tau, spar = 0, d = 1, weighted = FALSE, method = c("BFGS", "ADAM", "GRAD"), beta.rq = NULL, theta0 = NULL, spar0 = NULL, sg.rate = c(1, 1), mthreads = TRUE, control = list(trace = 0) )sqr.fit.optim( X, y, tau, spar = 0, d = 1, weighted = FALSE, method = c("BFGS", "ADAM", "GRAD"), beta.rq = NULL, theta0 = NULL, spar0 = NULL, sg.rate = c(1, 1), mthreads = TRUE, control = list(trace = 0) )
X |
vecor or matrix of explanatory variables (including intercept) |
y |
vector of dependent variable |
tau |
sequence of quantile levels in (0,1) |
spar |
smoothing parameter |
d |
subsampling rate of quantile levels (default = 1) |
weighted |
if |
method |
optimization method: |
beta.rq |
matrix of regression coefficients from |
theta0 |
initial value of spline coefficients (default = |
spar0 |
smoothing parameter for |
sg.rate |
vector of sampling rates for quantiles and observations in stochastic gradient version of GRAD and ADAM |
mthreads |
if |
control |
list of control parameters
|
A list with the following elements:
beta |
matrix of regression coefficients |
all.beta |
coefficients from all iterations for GRAD and ADAM |
spars |
smoothing parameters from |
fit |
object from the optimization algorithm |
data(engel) y <- engel$foodexp X <- cbind(rep(1,length(y)),engel$income-mean(engel$income)) tau <- seq(0.1,0.9,0.05) fit.rq <- quantreg::rq(y ~ X[,2],tau) fit.sqr <- sqr(y ~ X[,2],tau,spar=0.2) fit <- sqr.fit.optim(X,y,tau,spar=0.2,d=2,method="BFSG",beta.rq=fit.rq$coef) fit <- sqr.fit.optim(X,y,tau,spar=0.2,d=2,method="BFSG",beta.rq=fit.rq$coef) par(mfrow=c(1,2),pty="m",lab=c(10,10,2),mar=c(4,4,2,1)+0.1,las=1) for(j in c(1:2)) { plot(tau,fit.rq$coef[j,],type="n",xlab="QUANTILE LEVEL",ylab=paste0("COEFF",j)) points(tau,fit.rq$coef[j,],pch=1,cex=0.5) lines(tau,fit.sqr$coef[j,],lty=1); lines(tau,fit$beta[j,],lty=2,col=2) }data(engel) y <- engel$foodexp X <- cbind(rep(1,length(y)),engel$income-mean(engel$income)) tau <- seq(0.1,0.9,0.05) fit.rq <- quantreg::rq(y ~ X[,2],tau) fit.sqr <- sqr(y ~ X[,2],tau,spar=0.2) fit <- sqr.fit.optim(X,y,tau,spar=0.2,d=2,method="BFSG",beta.rq=fit.rq$coef) fit <- sqr.fit.optim(X,y,tau,spar=0.2,d=2,method="BFSG",beta.rq=fit.rq$coef) par(mfrow=c(1,2),pty="m",lab=c(10,10,2),mar=c(4,4,2,1)+0.1,las=1) for(j in c(1:2)) { plot(tau,fit.rq$coef[j,],type="n",xlab="QUANTILE LEVEL",ylab=paste0("COEFF",j)) points(tau,fit.rq$coef[j,],pch=1,cex=0.5) lines(tau,fit.sqr$coef[j,],lty=1); lines(tau,fit$beta[j,],lty=2,col=2) }
This function plots one or all regression coefficients from quantile regression (QR) and spline quantile regression (SQR) on a given sequence of quantiles against the quantile level.
sqr.plot( summary.rq, summary.sqr = NULL, summary.sqrb = NULL, coef.sim = NULL, type = "l", lty = c(1, 2), lwd = c(1.5, 1), cex = 0.25, pch = 1, col = c(2, 1), idx = NULL, plot.rq = TRUE, plot.rq.line = FALSE, plot.zero = FALSE, plot.ls = TRUE, plot.ci = TRUE, var.names = NULL, Ylim = NULL, xlim = NULL, set.par = TRUE, mfrow = NULL, lab = c(10, 7, 7), mar = c(2, 3, 2, 1) + 0.1, las = 1 )sqr.plot( summary.rq, summary.sqr = NULL, summary.sqrb = NULL, coef.sim = NULL, type = "l", lty = c(1, 2), lwd = c(1.5, 1), cex = 0.25, pch = 1, col = c(2, 1), idx = NULL, plot.rq = TRUE, plot.rq.line = FALSE, plot.zero = FALSE, plot.ls = TRUE, plot.ci = TRUE, var.names = NULL, Ylim = NULL, xlim = NULL, set.par = TRUE, mfrow = NULL, lab = c(10, 7, 7), mar = c(2, 3, 2, 1) + 0.1, las = 1 )
summary.rq |
output of |
summary.sqr |
output of |
summary.sqrb |
output of |
coef.sim |
output |
type |
as |
lty |
line types for the primary and secondary SQR (default = |
lwd |
line widths for the primary and secondary SQR (default = |
cex |
as |
pch |
as |
col |
line colors for the primary and secondary SQR (default = |
idx |
index of individual coefficient to be plotted (default = |
plot.rq |
|
plot.rq.line |
|
plot.zero |
|
plot.ls |
|
plot.ci |
|
var.names |
user-supplied names of regression coefficients (including the intercept) |
Ylim |
user-supplied matrix of |
xlim |
user-supplied |
set.par |
|
mfrow |
parameter for resetting |
lab |
parameter for resetting |
mar |
parameter for resetting |
las |
parameter for resetting |
Ylim (invisible)
This function computes spline quantile regression with linear splines and total-variation roughness penalty
(SQR1 or linear SQR) from the response vector and the design matrix on a given set of quantile levels.
It uses the FORTRAN code rqfnb.f in the "quantreg" package with the kind permission of Dr. R. Koenker
or the R function rq.fit.sfn() in the same package as a sparse-matrix alternative. Both solve the SQR1 problem as a linear program (LP).
sqr1.fit( X, y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0) - 1), mthreads = FALSE, ztol = 1e-05, solver = c("fnb", "sfn"), npar = c(1, 2), all.knots = FALSE )sqr1.fit( X, y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0) - 1), mthreads = FALSE, ztol = 1e-05, solver = c("fnb", "sfn"), npar = c(1, 2), all.knots = FALSE )
X |
design matrix ( |
y |
response vector |
tau |
sequence of quantile levels for evaluation |
tau0 |
sequence of quantile levels for fitting ( |
spar |
smoothing parameter (default = 1) |
w |
weight sequence in penalty (default = |
mthreads |
if |
ztol |
zero-tolerance parameter to determine the model complexity (default = |
solver |
LP solver: |
npar |
experimental parameter (default = 1) |
all.knots |
|
A list with the following elements:
coefficients |
matrix of regression coefficients |
derivatives |
matrix of derivatives of regression coefficients |
crit |
sequence critera for smoothing parameter select: (AIC,BIC,GIC) |
np |
sequence of complexity measure as the number of effective parameters |
fid |
sequence of fidelity measure as the quasi-likelihood |
nit |
number of iterations |
info |
convergence status |
K |
number of spline basis functions |
This function computes spline quantile regression with cubic splines and L2-norm roughness penalty
(SQR3 or cubic SQR) from the response vector and the design matrix on a given set of quantile levels.
It uses solve_osqp() in the "osqp" package or solve_piqp() in the "piqp" package.
Both are general-purpose quadratic program (QP) solvers in the sparse-matrix form.
sqr3.fit( X, y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), mthreads = FALSE, ztol = 1e-04, type = c("dual", "primal"), solver = c("piqp", "osqp"), npar = c(1, 2), all.knots = FALSE, control = list() )sqr3.fit( X, y, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), mthreads = FALSE, ztol = 1e-04, type = c("dual", "primal"), solver = c("piqp", "osqp"), npar = c(1, 2), all.knots = FALSE, control = list() )
X |
design matrix (requirement: |
y |
response vector |
tau |
sequence of quantile levels for evaluation |
tau0 |
sequence of quantile levels for fitting ( |
spar |
smoothing parameter (default = 1) |
w |
weight sequence in penalty (default = |
mthreads |
if |
ztol |
zero-tolerance parameter to determine the model complexity (default = |
type |
type of QP formulation: |
solver |
QP solver: |
npar |
experimental parameter (default = 1) |
all.knots |
|
control |
list of control parameters for the QP solver (default = |
A list with the following elements:
coefficients |
matrix of regression coefficients |
derivatives |
matrix of derivatives of regression coefficients |
crit |
sequence critera for smoothing parameter select: (AIC,BIC,GIC) |
np |
sequence of complexity measure as the number of effective parameters |
fid |
sequence of fidelity measure as the quasi-likelihood |
info |
convergence status |
nit |
number of iterations |
K |
number of spline basis functions |
This function computes ordinary trigonometric quantile regression (TQR) for univariate time series at a single frequency.
tqr.fit(y, f0, tau, prepared = TRUE)tqr.fit(y, f0, tau, prepared = TRUE)
y |
vector of time series |
f0 |
frequency in [0,1) |
tau |
sequence of quantile levels in (0,1) |
prepared |
if |
object of quantreg::rq()
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) fit <- tqr.fit(y,f0=0.1,tau=tau) plot(tau,fit$coef[1,],type='o',pch=0.75,xlab='QUANTILE LEVEL',ylab='TQR COEF')y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) fit <- tqr.fit(y,f0=0.1,tau=tau) plot(tau,fit$coef[1,],type='o',pch=0.75,xlab='QUANTILE LEVEL',ylab='TQR COEF')
This function computes trigonometric spline quantile regression (TSQR) for
univariate time series at a single frequency using sqr.fit(), sqr1.fit(), or sqr3.fit().
tsqr.fit( y, f0, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), mthreads = FALSE, prepared = TRUE, method = c("sqr", "sqr1", "sqr3"), ztol = NULL, solver = NULL, all.knots = FALSE, control = list() )tsqr.fit( y, f0, tau, tau0 = tau, spar = 1, w = rep(1, length(tau0)), mthreads = FALSE, prepared = TRUE, method = c("sqr", "sqr1", "sqr3"), ztol = NULL, solver = NULL, all.knots = FALSE, control = list() )
y |
time series |
f0 |
frequency in [0,1) |
tau |
sequence of quantile levels for evaluation |
tau0 |
sequence of quantile levels for fitting ( |
spar |
smoothing parameter (default = 1) |
w |
weight sequence in penalty (default = |
mthreads |
if |
prepared |
if |
method |
|
ztol |
a zero tolerance paramete to determine the model complexity
(default = |
solver |
|
all.knots |
|
control |
list of control parameters for QP solvers |
object of sqr.fit(), sqr1.fit(), or sqr3.fit()
y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) tau0 <- seq(0.1,0.9,0.2) fit <- tqr.fit(y,f0=0.1,tau=tau) fit.sqr1 <- tsqr.fit(y,f0=0.1,tau=tau,tau0=tau0,spar=0.2,method='sqr1') fit.sqr3 <- tsqr.fit(y,f0=0.1,tau=tau,tau0=tau0,spar=1,method='sqr3') plot(tau,fit$coef[1,],type='p',xlab='QUANTILE LEVEL',ylab='TQR COEF') lines(tau,fit.sqr1$coef[1,]) lines(tau,fit.sqr3$coef[1,],col=2)y <- stats::arima.sim(list(order=c(1,0,0), ar=0.5), n=64) tau <- seq(0.1,0.9,0.05) tau0 <- seq(0.1,0.9,0.2) fit <- tqr.fit(y,f0=0.1,tau=tau) fit.sqr1 <- tsqr.fit(y,f0=0.1,tau=tau,tau0=tau0,spar=0.2,method='sqr1') fit.sqr3 <- tsqr.fit(y,f0=0.1,tau=tau,tau0=tau0,spar=1,method='sqr3') plot(tau,fit$coef[1,],type='p',xlab='QUANTILE LEVEL',ylab='TQR COEF') lines(tau,fit.sqr1$coef[1,]) lines(tau,fit.sqr3$coef[1,],col=2)
Yearly mean total sunspot numbers from 1700 to 2007.
data(yearssn)data(yearssn)
An object of class data.frame with 308 rows and 2 columns.
Original data https://www.sidc.be/SILSO/versionarchive from WDC-SILSO, Royal Observatory of Belgium, Brussels.
WDC-SILSO, Royal Observatory of Belgium, Brussels. doi:10.24414/stcz-kc45
Yearly mean total sunspot numbers from 1700 to 2024. A revised version replacing v1.0.
data(yearssn2024)data(yearssn2024)
An object of class data.frame with 325 rows and 2 columns.
Original data https://www.sidc.be/SILSO/datafiles from WDC-SILSO, Royal Observatory of Belgium, Brussels.
WDC-SILSO, Royal Observatory of Belgium, Brussels. doi:10.24414/qnza-ac80