| Title: | Nonparametric Estimators for Covariance Functions |
|---|---|
| Description: | Several nonparametric estimators of autocovariance functions. Procedures for constructing their confidence regions by using bootstrap techniques. Methods to correct autocovariance estimators and several tools for analysing and comparing them. Supplementary functions, including kernel computations and discrete cosine Fourier transforms. For more details see Bilchouris and Olenko (2025) <doi:10.17713/ajs.v54i1.1975>. |
| Authors: | Adam Bilchouris [cre, aut] (ORCID: <https://orcid.org/0009-0002-4649-0247>), Andriy Olenko [aut] (ORCID: <https://orcid.org/0000-0002-0917-7000>) |
| Maintainer: | Adam Bilchouris <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.1.0 |
| Built: | 2026-05-19 09:57:03 UTC |
| Source: | https://github.com/adambilchouris/covests |
This function computes the kernel regression estimator of the autocovariance function.
adjusted_est( X, x, t, b, kernel_name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), kernel_params = c(), pd = TRUE, type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_kernel = FALSE, parallel = FALSE, ncores = parallel::detectCores() - 1, cl_export = NULL, cl = NULL )adjusted_est( X, x, t, b, kernel_name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), kernel_params = c(), pd = TRUE, type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_kernel = FALSE, parallel = FALSE, ncores = parallel::detectCores() - 1, cl_export = NULL, cl = NULL )
X |
A vector representing observed values of the time series. |
x |
A vector of lags. |
t |
The arguments at which the autocovariance function is calculated at. |
b |
Bandwidth parameter, greater than 0. |
kernel_name |
The name of the symmetric kernel (see kernel_symm_ec) function to be used. Possible values are: gaussian, wave, rational_quadratic, and bessel_j. Alternatively, a custom kernel function can be provided, see the examples. |
kernel_params |
A vector of parameters of the kernel function. See kernel_symm_ec for parameters. |
pd |
Whether a positive-definite estimate should be used. Defaults to |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
meanX |
The average value of |
custom_kernel |
If a custom kernel is to be used or not. Defaults to |
parallel |
Whether or not the computations should be done in parallel or not. Defaults to |
ncores |
The number of cores to be used in the parallel computations. Defaults to the number cores - 1 (threads if hyperthreading is available), calculated from |
cl_export |
A vector of any additional functions or variables to export for parallel computations. This may be required if |
cl |
An optional cluster object created by |
The kernel regression estimator of an autocovariance function is defined as
where
If pd is TRUE, the estimator will be made positive-definite through the following procedure
Take the discrete Fourier cosine transform,
, of the estimated autocovariance function
Compute a modified spectrum for all sample frequencies.
Perform the Fourier inversion to obtain a new estimator.
A CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the type parameter.
est_usedThe estimator function used, in this case, 'adjusted_est'.
Hall, P. & Patil, P. (1994). Properties of nonparametric estimators of autocovariance for stationary random fields. Probability Theory and Related Fields 99(3), 399-424. https://doi.org/10.1007/bf01199899
Hall, P., Fisher, N. I., & Hoffmann, B. (1994). On the nonparametric estimation of covariance functions. The Annals of Statistics 22(4), 2115-2134. https://doi.org/10.1214/aos/1176325774
X <- c(1, 2, 3, 4) adjusted_est(X, 1:4, 1:3, 0.1, "gaussian") my_kernel <- function(x, params) { stopifnot(params[1] > 0, length(x) >= 1) return(exp(-((abs(x) / params[1])^params[2])) * (2 * params[1] * gamma(1 + 1/params[2]))) } adjusted_est(X, 1:4, 1:3, 0.1, my_kernel, c(0.25), custom_kernel = TRUE) ## Not run: library(parallel) X <- c(1, 2, 3, 4) my_cl <- makePSOCKcluster(2) adjusted_est(X, 1:4, 1:3, 0.1, "gaussian", parallel = TRUE, cl = my_cl) stopCluster(my_cl) ## End(Not run)X <- c(1, 2, 3, 4) adjusted_est(X, 1:4, 1:3, 0.1, "gaussian") my_kernel <- function(x, params) { stopifnot(params[1] > 0, length(x) >= 1) return(exp(-((abs(x) / params[1])^params[2])) * (2 * params[1] * gamma(1 + 1/params[2]))) } adjusted_est(X, 1:4, 1:3, 0.1, my_kernel, c(0.25), custom_kernel = TRUE) ## Not run: library(parallel) X <- c(1, 2, 3, 4) my_cl <- makePSOCKcluster(2) adjusted_est(X, 1:4, 1:3, 0.1, "gaussian", parallel = TRUE, cl = my_cl) stopCluster(my_cl) ## End(Not run)
A helper function that is an implementation of the formula from Choi, Li & Wang (2013, p. 616),
where is the number of nonboundary knots, is the order of the spline, is the order of the adjusted spline (the function ) and
adjusted_spline(x, j, l, p, m, taus)adjusted_spline(x, j, l, p, m, taus)
x |
Argument of the function. |
j |
Index of basis function of order |
l |
Order of function. |
p |
The order of the splines. |
m |
The number of nonboundary knots. |
taus |
Vector of |
A numeric value of the adjusted spline
Choi, I., Li, B. & Wang, X. (2013). Nonparametric Estimation of Spatial and Space-Time Covariance Function. JABES 18, 611-630. https://doi.org/10.1007/s13253-013-0152-z
## Not run: taus <- get_taus(3, 2) adjusted_spline(1, 2, 1, 3, 2, taus) ## End(Not run)## Not run: taus <- get_taus(3, 2) adjusted_spline(1, 2, 1, 3, 2, taus) ## End(Not run)
This function estimates the area between two estimated autocovariance functions.
area_between(est1, est2, lags = c(), plot = FALSE) ## S3 method for class 'CovEsts' area_between(est1, est2, lags = c(), plot = FALSE) ## Default S3 method: area_between(est1, est2, lags = c(), plot = FALSE)area_between(est1, est2, lags = c(), plot = FALSE) ## S3 method for class 'CovEsts' area_between(est1, est2, lags = c(), plot = FALSE) ## Default S3 method: area_between(est1, est2, lags = c(), plot = FALSE)
est1 |
A numeric vector representing the first estimated autocovariance function. |
est2 |
A numeric vector of the same length as |
lags |
An optional vector of lags starting from 0 up until some other lag. If empty, a vector of lags is created starting from 0 until |
plot |
A boolean determining whether a plot should be created. By default, no plot is created. |
This function estimates the area between two estimated autocovariance functions over a set of lags, from 0 up to defined by
where and are estimated autocovariance functions.
To approximate this integral the trapezoidal rule is used.
If lags is empty, a uniform time grid with a step of 1 will be used which may result in a different area than if lags is specified.
A numeric value representing the estimated area between two estimated autocovariance functions.
area_between(CovEsts): Method for CovEsts objects.
area_between(default): Method for numeric vectors.
x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) area_between(estCov1, estCov2, lags=x) area_between(estCov1, estCov2, lags=x, plot = TRUE)x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) area_between(estCov1, estCov2, lags=x) area_between(estCov1, estCov2, lags=x, plot = TRUE)
This function provides a method for as.double for CovEsts objects, allowing for as.numeric to be called. It extracts the acf values from the object.
## S3 method for class 'CovEsts' as.double(x, ...)## S3 method for class 'CovEsts' as.double(x, ...)
x |
A CovEsts S3 object. |
... |
Refer to base::double. |
The acf values from the CovEsts object.
as.numeric(standard_est(c(1, 2, 3)))as.numeric(standard_est(c(1, 2, 3)))
This function performs block bootstrap (moving or circular) to obtain a confidence-interval for the autocovariance function. It will also compute average autocovariance function across all bootstrapped estimates.
block_bootstrap( X, maxLag, x = 0:length(X), n_bootstrap = 100, l = ceiling(length(X)^(1/3)), estimator = standard_est, type = c("autocovariance", "autocorrelation"), alpha = 0.05, boot_type = c("moving", "circular"), parallel = FALSE, ncores = parallel::detectCores() - 1, cl_export = NULL, boot_seed = NULL, cl = NULL, ... )block_bootstrap( X, maxLag, x = 0:length(X), n_bootstrap = 100, l = ceiling(length(X)^(1/3)), estimator = standard_est, type = c("autocovariance", "autocorrelation"), alpha = 0.05, boot_type = c("moving", "circular"), parallel = FALSE, ncores = parallel::detectCores() - 1, cl_export = NULL, boot_seed = NULL, cl = NULL, ... )
X |
A vector representing observed values of the time series. |
maxLag |
The maximum lag to compute the estimated autocovariance function at. |
x |
A vector of lag indices. Defaults to the sequence |
n_bootstrap |
The number of times to run moving block bootstrap. Defaults to 100. |
l |
The block length considered for bootstrap. Defaults to |
estimator |
The function name of the estimator to use. Defaults to |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
alpha |
The quantile used to compute the |
boot_type |
What type of block bootstrap should be used, either 'moving' for moving block bootstrap or 'circular' for circular block bootstrap. |
parallel |
Whether or not the bootstrap computations should be done in parallel or not. Defaults to |
ncores |
The number of cores to be used in the parallel bootstrap computations. Defaults to the number cores - 1 (threads if hyperthreading is available), calculated from |
cl_export |
A vector of any additional functions or variables to export for parallel computations. This may be required if |
boot_seed |
An integer seed for reproducibility. This is used for |
cl |
An optional cluster object created by |
... |
Optional named arguments to the chosen estimator. See the examples. |
This function performs block bootstrap to obtain a confidence-interval for the autocovariance function. It will also compute average autocovariance function across all bootstrapped estimates.
Moving block bootstrap can be described as follows.
For some times series construct overlapping blocks of the form
where is the block length.
Randomly sample, with replacement, from the discrete uniform distribution with on to obtain a set of random starting locations
Construct a bootstrapped time series where
The bootstrapped time series is truncated to have length and will be of the form
The autocovariance function is then computed for the bootstrapped time series.
An alternative to moving block bootstrap is circular block bootstrap.
Circular block bootstrap uses the time series like a circle, that is, the observation at is the same as the observation at location
For example, for the block , we obtain is the same as
When performing random sampling to obtain starting locations, the set is now considered.
The procedure for constructing the bootstrap time series after constructing the blocks and selecting the starting indices is the same as moving block bootstrap.
This process is repeated n_bootstrap times to obtain n_boostrap estimates of the autocovariance function using the bootstrapped time series, for which the average autocovariance function
and the confidence intervals are constructed pointwise for each lag.
The choice of the block length, depends on the degree of dependence present in the time series. If the time series has a high degree of dependence, a larger block size should be chosen to ensure the dependency structure is maintained within the block.
Any estimator of the autocovariance function can be used in this function, including a custom estimator not in the package, see the examples.
When parallel = TRUE, L'Ecuyer-CMRG is used to ensure independent random numbers across workers. The serial version uses the Mersenne-Twister algorithm.
A BootEsts S3 object (list) with the following values
acf_avgA numeric vector containing the average autocovariance/autocorrelation bootstrap estimate.
lagsA numeric vector containing the lag indices used to compute the estimates on.
acf_origA numeric vector containing the nonbootstrapped autocovariance/autocorrelation estimate.
acf_matA numeric matrix of the a matrix of all of the bootstrap estimates.
conf_lowerA numeric vector containing the lower bounds for the estimated pointwise confidence interval.
conf_upperA numeric vector containing the upper bounds for the estimated pointwise confidence interval.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the argument type.
est_usedThe estimator function used, this depends on the argument estimator.
boot_typeThe type of estimate, namely 'moving' or 'circular', this depends on the argument boot_type.
alphaA numeric value, which is the value used to compute the confidence intervals, this depends on the argument alpha.
Chapters 2.5 and 2.7 in Lahiri, S. N. (2003). Resampling Methods for Dependent Data. Springer. https://doi.org/10.1007/978-1-4757-3803-2
Künsch, H. R. (1989). The Jackknife and the Bootstrap for General Stationary Observations. The Annals of Statistics 17(3), 1217-1241. https://doi.org/10.1214/aos/1176347265
Politis, D. N. & Romano, J. P. (1991). A Circular Block-Resampling Procedure for Stationary Data. In R. LePage & L. Billard, eds, Exploring the Limits of Bootstrap, Wiley, 263-270.
X <- c(1, 2, 3, 3, 2, 1) block_bootstrap(X, 4, n_bootstrap = 3, l = 2, type = 'autocorrelation') block_bootstrap(X, 4, n_bootstrap = 3, l = 2, type = 'autocovariance') block_bootstrap(X, 4, n_bootstrap = 3, l = 2, estimator=tapered_est, rho = 0.5, window_name = 'blackman', window_params = c(0.16), type='autocorrelation') my_cov_est <- function(X, maxLag) { n <- length(X) covVals <- rep(0, maxLag + 1) for(h in 0:maxLag) { covVals_t <- (X[1:(n-h)] - mean(X)) * (X[(1+h):n] - mean(X)) covVals[h] <- sum(covVals_t) / (n - h) } return(covVals) } block_bootstrap(X, 4, n_bootstrap = 3, l = 2, estimator=my_cov_est) plot(LakeHuron, main="Lake Huron Levels", ylab="Feet") X <- as.vector(LakeHuron) block_bootstrap(X, 20, n_bootstrap = 100, l = 40, type = 'autocorrelation') block_bootstrap(X, 20, n_bootstrap = 100, l = 40, type = 'autocorrelation') block_bootstrap(X, 20, n_bootstrap = 100, l = 40, estimator=tapered_est, rho = 0.5, window_name = 'blackman', window_params = c(0.16), type='autocorrelation') my_cov_est <- function(X, maxLag) { n <- length(X) covVals <- rep(0, maxLag + 1) for(h in 0:maxLag) { covVals_t <- (X[1:(n-h)] - mean(X)) * (X[(1+h):n] - mean(X)) covVals[h] <- sum(covVals_t) / (n - h) } return(covVals) } block_bootstrap(X, 20, n_bootstrap = 100, l = 40, estimator = my_cov_est, type = 'autocorrelation') ## Not run: library(parallel) X <- c(1, 2, 3, 3, 2, 1) my_cl <- makePSOCKcluster(2) block_bootstrap(X, 4, n_bootstrap = 1000, l = 3, parallel = TRUE, cl = my_cl) stopCluster(my_cl) ## End(Not run)X <- c(1, 2, 3, 3, 2, 1) block_bootstrap(X, 4, n_bootstrap = 3, l = 2, type = 'autocorrelation') block_bootstrap(X, 4, n_bootstrap = 3, l = 2, type = 'autocovariance') block_bootstrap(X, 4, n_bootstrap = 3, l = 2, estimator=tapered_est, rho = 0.5, window_name = 'blackman', window_params = c(0.16), type='autocorrelation') my_cov_est <- function(X, maxLag) { n <- length(X) covVals <- rep(0, maxLag + 1) for(h in 0:maxLag) { covVals_t <- (X[1:(n-h)] - mean(X)) * (X[(1+h):n] - mean(X)) covVals[h] <- sum(covVals_t) / (n - h) } return(covVals) } block_bootstrap(X, 4, n_bootstrap = 3, l = 2, estimator=my_cov_est) plot(LakeHuron, main="Lake Huron Levels", ylab="Feet") X <- as.vector(LakeHuron) block_bootstrap(X, 20, n_bootstrap = 100, l = 40, type = 'autocorrelation') block_bootstrap(X, 20, n_bootstrap = 100, l = 40, type = 'autocorrelation') block_bootstrap(X, 20, n_bootstrap = 100, l = 40, estimator=tapered_est, rho = 0.5, window_name = 'blackman', window_params = c(0.16), type='autocorrelation') my_cov_est <- function(X, maxLag) { n <- length(X) covVals <- rep(0, maxLag + 1) for(h in 0:maxLag) { covVals_t <- (X[1:(n-h)] - mean(X)) * (X[(1+h):n] - mean(X)) covVals[h] <- sum(covVals_t) / (n - h) } return(covVals) } block_bootstrap(X, 20, n_bootstrap = 100, l = 40, estimator = my_cov_est, type = 'autocorrelation') ## Not run: library(parallel) X <- c(1, 2, 3, 3, 2, 1) my_cl <- makePSOCKcluster(2) block_bootstrap(X, 4, n_bootstrap = 1000, l = 3, parallel = TRUE, cl = my_cl) stopCluster(my_cl) ## End(Not run)
This function generates block bootstrap samples for either moving block bootstrap or circular bootstrap.
bootstrap_sample(X, l, k, boot_type = c("moving", "circular"))bootstrap_sample(X, l, k, boot_type = c("moving", "circular"))
X |
A vector representing observed values of the time series. |
l |
The block length considered for bootstrap. |
k |
The number of blocks considered for bootstrap. |
boot_type |
What type of block bootstrap should be used, either 'moving' for moving block bootstrap or 'circular' for circular block bootstrap. |
This function generates a block bootstrap sample for a time series
For the moving block bootstrap and circular bootstrap procedures see block_bootstrap and the included references.
A vector of length length(X) whose values are a bootstrapped time series.
Chapters 2.5 and 2.7 in Lahiri, S. N. (2003). Resampling Methods for Dependent Data. Springer. https://doi.org/10.1007/978-1-4757-3803-2
Künsch, H. R. (1989). The Jackknife and the Bootstrap for General Stationary Observations. The Annals of Statistics 17(3), 1217-1241. https://doi.org/10.1214/aos/1176347265
Politis, D. N. & Romano, J. P. (1991). A Circular Block-Resampling Procedure for Stationary Data. In R. LePage & L. Billard, eds, Exploring the Limits of Bootstrap, Wiley, 263-270.
X <- c(1, 2, 3, 3, 2, 1) bootstrap_sample(X, 2, 3)X <- c(1, 2, 3, 3, 2, 1) bootstrap_sample(X, 2, 3)
This function checks if an autocovariance function estimate is positive-definite or not by determining if the eigenvalues of the corresponding matrix (see the Details section) are all positive.
check_pd(est) ## S3 method for class 'CovEsts' check_pd(est) ## Default S3 method: check_pd(est)check_pd(est) ## S3 method for class 'CovEsts' check_pd(est) ## Default S3 method: check_pd(est)
est |
A numeric vector, corresponding cyclic matrix representing an estimated autocovariance function, or a |
For an autocovariance function estimate over a set of lags separated by a constant difference
construct the symmetric matrix
The eigendecomposition of this matrix is computed to determine if all eigenvalues are positive. If so, the estimated autocovariance function is assumed to be positive-definite.
A boolean where TRUE denotes a positive-definite autocovariance function estimate and FALSE for an estimate that is not positive-definite.
check_pd(CovEsts): Method for CovEsts objects.
check_pd(default): Method for numeric vectors.
x <- seq(0, 5, by=0.1) estCov <- exp(-x^2) check_pd(estCov)x <- seq(0, 5, by=0.1) estCov <- exp(-x^2) check_pd(estCov)
This function computes the standard autocovariance estimator and applies kernel correction to it,
where
It uses a kernel which decays or vanishes to zero (depending on the type of kernel) where
The rate or value at which the kernel vanishes is , which is recommended to be of order , where is the length of the observation window, however, one may need to play with this value.
corrected_est( X, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(X), pd = TRUE, maxLag = length(X) - 1, x = 0:length(X), type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_kernel = FALSE )corrected_est( X, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(X), pd = TRUE, maxLag = length(X) - 1, x = 0:length(X), type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_kernel = FALSE )
X |
A vector representing observed values of the time series. |
kernel_name |
The name of the kernel_ec function to be used. Possible values are: gaussian, exponential, wave, rational_quadratic, spherical, circular, bessel_j, matern, cauchy. |
kernel_params |
A vector of parameters of the kernel function. See kernel_ec for parameters.
In the case of gaussian, wave, rational_quadratic, spherical and circular, |
N_T |
The range at which the kernel function vanishes at. Recommended to be |
pd |
Whether a positive-definite estimate should be used. Defaults to |
maxLag |
An optional parameter that determines the maximum lag to compute the estimated autocovariance function at. Defaults to |
x |
A vector of lag indices. Defaults to the sequence |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
meanX |
The average value of |
custom_kernel |
If a custom kernel is to be used or not. Defaults to |
The aim of this estimator is gradually bring the estimated values to zero through the use of a kernel multiplier. This can be useful when estimating an
autocovariance function that is short-range dependent as estimators can have large fluctuations as the lag increases, or to deal with the wave artefacts for large lags, see Bilchouris and Olenko (2025).
This estimator can be positive-definite depending on whether the choice of and are chosen to be positive-definite or not.
A CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the type parameter.
est_usedThe estimator function used, in this case, 'corrected_est'.
Yaglom, AM (1987). Correlation Theory of Stationary and Related Random Functions. Volume I: Basic Results. Springer New York. https://doi.org/10.1007/978-1-4612-4628-2
Bilchouris, A. & Olenko, A (2025). On Nonparametric Estimation of Covariogram. Austrian Statistical Society (Vol. 54, Issue 1). https://doi.org/10.17713/ajs.v54i1.1975
X <- c(1, 2, 3) corrected_est(X, "gaussian") X <- rnorm(1000) Y <- c(X[1], X[2]) for(i in 3:length(X)) { Y[i] <- X[i] - 0.3*X[i - 1] - 0.6*X[i - 2] } plot(Y) plot(corrected_est(Y, "bessel_j", kernel_params=c(0, 1), N_T=0.2*length(Y))) # Custom kernel my_kernel <- function(x, theta, params) { stopifnot(theta > 0, length(x) >= 1, all(x >= 0)) return(sapply(x, function(t) ifelse(t == 0, 1, ifelse(t == Inf, 0, (sin((t^params[1]) / theta) / ((t^params[1]) / theta)) * cos((t^params[2]) / theta))))) } plot(corrected_est(Y, my_kernel, kernel_params=c(2, 0.25), custom_kernel = TRUE))X <- c(1, 2, 3) corrected_est(X, "gaussian") X <- rnorm(1000) Y <- c(X[1], X[2]) for(i in 3:length(X)) { Y[i] <- X[i] - 0.3*X[i - 1] - 0.6*X[i - 2] } plot(Y) plot(corrected_est(Y, "bessel_j", kernel_params=c(0, 1), N_T=0.2*length(Y))) # Custom kernel my_kernel <- function(x, theta, params) { stopifnot(theta > 0, length(x) >= 1, all(x >= 0)) return(sapply(x, function(t) ifelse(t == 0, 1, ifelse(t == Inf, 0, (sin((t^params[1]) / theta) / ((t^params[1]) / theta)) * cos((t^params[2]) / theta))))) } plot(corrected_est(Y, my_kernel, kernel_params=c(2, 0.25), custom_kernel = TRUE))
This helper function creates a symmetric matrix from a given vector .
cyclic_matrix(v)cyclic_matrix(v)
v |
A numeric vector. |
This function creates a symmetric matrix for a given vector .
If then the symmetric matrix will has the form
A symmetric matrix.
## Not run: v <- c(1, 2, 3) cyclic_matrix(v) ## End(Not run)## Not run: v <- c(1, 2, 3) cyclic_matrix(v) ## End(Not run)
This function computes the Type-II discrete cosine transform.
dct_1d(X)dct_1d(X)
X |
A vector of values for which the discrete cosine transform is being computed. |
The Type-II discrete cosine transform is obtained using stats::fft.
If is of length N, construct a new signal of length , with values for ,
and for
After this, the Type-II discrete cosine transform is computed by 0.5 * Re(stats::fft(Y))[1:(length(Y) / 4)].
A vector of discrete cosine transform values.
Ochoa-Dominguez, H. & Rao, K.R. (2019). Discrete Cosine Transform, Second Edition. CRC Press. https://doi.org/10.1201/9780203729854
Makhoul, J. (1980). A Fast Cosine Transform in One and Two Dimensions. IEEE Transactions on Acoustics, Speech, and Signal Processing 28(1), 27-34. https://doi.org/10.1109/TASSP.1980.1163351
Stasiński, R. (2002). DCT Computation Using Real-Valued DFT Algorithms. Proceedings of the 11th European Signal Processing Conference.
X <- c(1, 2, 3) dct_1d(X)X <- c(1, 2, 3) dct_1d(X)
A helper function that generates spline knots of the form:
The knots are equally spaced with boundary knots and
generate_knots(m)generate_knots(m)
m |
The number of nonboundary knots. |
A numeric vector representing the knots, including the boundary knots.
Choi, I., Li, B. & Wang, X. (2013). Nonparametric Estimation of Spatial and Space-Time Covariance Function. JABES 18, 611-630. https://doi.org/10.1007/s13253-013-0152-z
## Not run: generate_knots(3) ## End(Not run)## Not run: generate_knots(3) ## End(Not run)
.A helper function to obtain all where each is as follows.
For it is equal to , and for it is
See Choi, Li & Wang (2013, p. 615) for details.
get_taus(p, m)get_taus(p, m)
p |
The order of the splines. |
m |
The number of nonboundary knots. |
A numeric vector of all
Choi, I., Li, B. & Wang, X. (2013). Nonparametric Estimation of Spatial and Space-Time Covariance Function. JABES 18, 611-630. https://doi.org/10.1007/s13253-013-0152-z
## Not run: get_taus(3, 2) ## End(Not run)## Not run: get_taus(3, 2) ## End(Not run)
This helper function is used in the computation of the normalisation factor the function tapered_est,
where is a window function.
H2n( n, rho, window_name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), window_params = c(1), custom_window = FALSE )H2n( n, rho, window_name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), window_params = c(1), custom_window = FALSE )
n |
The sample size. |
rho |
A scale parameter in |
window_name |
The name of the window_ec function to be used. Possible values are: tukey, triangular, power_sine, blackman_window, hann_poisson, welch. Alternatively, a custom window function can be provided, see the example for taper. |
window_params |
A vector of parameters of the window function. |
custom_window |
If a custom window is to be used or not. Defaults to |
A single value being .
## Not run: H2n(3, 0.6, "tukey") ## End(Not run)## Not run: H2n(3, 0.6, "tukey") ## End(Not run)
This function computes the Hilbert-Schidmt norm between two estimated autocovariance functions.
hilbert_schmidt(est1, est2) ## S3 method for class 'CovEsts' hilbert_schmidt(est1, est2) ## Default S3 method: hilbert_schmidt(est1, est2)hilbert_schmidt(est1, est2) ## S3 method for class 'CovEsts' hilbert_schmidt(est1, est2) ## Default S3 method: hilbert_schmidt(est1, est2)
est1 |
A numeric vector representing the first estimated autocovariance function. |
est2 |
A numeric vector of the same length as |
This function computes the Hilbert-Schidmt norm between two estimated autocovariance functions. The Hilbert-Schmidt norm of a matrix
over a set of lags where
is defined as
A numeric value representing the estimated Hilbert-Schmidt norm between two estimated autocovariance functions.
hilbert_schmidt(CovEsts): Method for CovEsts objects.
hilbert_schmidt(default): Method for numeric vectors.
x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) hilbert_schmidt(estCov1, estCov2)x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) hilbert_schmidt(estCov1, estCov2)
This function computes the inverse of the Type-II discrete cosine transform.
idct_1d(X)idct_1d(X)
X |
A vector of values for which the discrete cosine transform is being computed. |
The Type-II inverse discrete cosine transform is computed using stats::fft.
For autocovariance function estimation, the spectrum is given in the input X and then an inverse FFT is applied.
The original spectrum, dct_full, from X is obtained as follows.
First, the original sample Fourier spectrum is reconstructed using dct_full <- c(X, 0, -X[-1], 0, rev(X[-1])). After this, an inverse FFT is applied,
idct <- Re(stats::fft(dct_full, inverse = TRUE)) * (2 / length(dct_full)), which gives the original function with additional zero-values at even indices.
The zeroes are dropped, which gives the untransformed X.
A vector with the inverse transform values.
Ochoa-Dominguez, H. & Rao, K.R. (2019). Discrete Cosine Transform, Second Edition. CRC Press. https://doi.org/10.1201/9780203729854
endolith (2013). Fast Cosine Transform via FFT. Signal Processing Stack Exchange. https://dsp.stackexchange.com/a/10606
X <- dct_1d(c(1, 2, 3)) idct_1d(X)X <- dct_1d(c(1, 2, 3)) idct_1d(X)
This function computes one of the isotropic kernels listed below. Note that kernel() is deprecated, please use kernel_ec() instead.
Unlike kernel_symm_ec, these kernels are only defined when They are used as
kernel multipliers in estimators corrected_est and kernel_est.
kernel_ec( x, name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), params = c(1) )kernel_ec( x, name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), params = c(1) )
x |
A vector or matrix of arguments of at least length 1 for which the kernel is computed at. |
name |
The name of the kernel. Options are: gaussian, exponential, wave, rational_quadratic, spherical, circular, bessel_j, matern, and cauchy. |
params |
A vector of parameters for the kernel. See the documentation below for the position of the parameters. All kernels have a scale parameter as the first value in the vector. |
Gaussian Kernel.
The isotropic Gaussian kernel, which is positive-definite for is defined as
The params argument is of the form c().
Exponential Kernel.
The isotropic exponential kernel, which is positive-definite for is defined as
The params argument is of the form c().
Isotropic Wave (Cardinal Sine) Kernel.
The isotropic wave (cardinal sine) kernel, which is positive-definite for is given by
where
The params argument is of the form c().
Isotropic Rational Quadratic Kernel.
The isotropic rational quadratic kernel, which is positive-definite for is defined as
The params argument is of the form c().
Isotropic Spherical Kernel.
The isotropic spherical kernel, which is positive-definite for is given by
where
The params argument is of the form c().
Isotropic Circular Kernel.
The isotropic circular kernel, which is positive-definite for is given by
where
The params argument is of the form c().
Isotropic Matérn Kernel.
The isotropic Matérn kernel, which is positive-definite for and when is defined as
where and is the modified Bessel function of the second kind.
The params argument is of the form c().
Isotropic Bessel Kernel.
The isotropic Bessel kernel, which is positive-definite for and when is given by
where and is the Bessel function of the first kind.
The params argument is of the form c( ).
Isotropic Cauchy Kernel.
The isotropic Cauchy kernel, which is positive-definite for and when and is defined by
The params argument is of the form c( ).
A vector or matrix of kernel values.
Genton, M. (2001). Classes of Kernels for Machine Learning: A Statistics Perspective. Journal of Machine Learning Research. 2, 299-312. https://doi.org/10.1162/15324430260185646
Table 4.2 in Hristopulos, D. T. (2020). Random Fields for Spatial Data Modeling: A Primer for Scientists and Engineers. Springer. https://doi.org/10.1007/978-94-024-1918-4
x <- c(0.2, 0.4, 0.6) theta <- 0.9 kernel_ec(x, "gaussian", c(theta)) kernel_ec(x, "exponential", c(theta)) kernel_ec(x, "wave", c(theta)) kernel_ec(x, "rational_quadratic", c(theta)) kernel_ec(x, "spherical", c(theta)) kernel_ec(x, "circular", c(theta)) nu <- 1 kernel_ec(x, "matern", c(theta, nu)) dim <- 1 kernel_ec(x, "bessel_j", c(theta, nu, dim)) alpha <- 1 beta <- 2 kernel_ec(x, "cauchy", c(theta, alpha, beta)) curve(kernel_ec(x, "gaussian", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "exponential", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "wave", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "rational_quadratic", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "spherical", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "circular", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "matern", c(theta, nu)), from = 0, to = 5) curve(kernel_ec(x, "bessel_j", c(theta, nu, dim)), from = 0, to = 5) curve(kernel_ec(x, "cauchy", c(theta, alpha, beta)), from = 0, to = 5)x <- c(0.2, 0.4, 0.6) theta <- 0.9 kernel_ec(x, "gaussian", c(theta)) kernel_ec(x, "exponential", c(theta)) kernel_ec(x, "wave", c(theta)) kernel_ec(x, "rational_quadratic", c(theta)) kernel_ec(x, "spherical", c(theta)) kernel_ec(x, "circular", c(theta)) nu <- 1 kernel_ec(x, "matern", c(theta, nu)) dim <- 1 kernel_ec(x, "bessel_j", c(theta, nu, dim)) alpha <- 1 beta <- 2 kernel_ec(x, "cauchy", c(theta, alpha, beta)) curve(kernel_ec(x, "gaussian", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "exponential", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "wave", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "rational_quadratic", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "spherical", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "circular", c(theta)), from = 0, to = 5) curve(kernel_ec(x, "matern", c(theta, nu)), from = 0, to = 5) curve(kernel_ec(x, "bessel_j", c(theta, nu, dim)), from = 0, to = 5) curve(kernel_ec(x, "cauchy", c(theta, alpha, beta)), from = 0, to = 5)
This function applies kernel correction to an estimated autocovariance function,
where
It uses a kernel which decays or vanishes to zero (depending on the type of kernel) where
The rate or value at which the kernel vanishes is , which is recommended to be of order , where is the length of the observation window, however, one may need to play with this value.
kernel_est( estCov, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(estCov), maxLag = length(estCov) - 1, x = 0:length(estCov), type = c("autocovariance", "autocorrelation"), custom_kernel = FALSE ) ## S3 method for class 'CovEsts' kernel_est( estCov, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(estCov$acf), maxLag = length(estCov$acf) - 1, x = estCov$lags, type = c("autocovariance", "autocorrelation"), custom_kernel = FALSE ) ## Default S3 method: kernel_est( estCov, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(estCov), maxLag = length(estCov) - 1, x = 0:length(estCov), type = c("autocovariance", "autocorrelation"), custom_kernel = FALSE )kernel_est( estCov, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(estCov), maxLag = length(estCov) - 1, x = 0:length(estCov), type = c("autocovariance", "autocorrelation"), custom_kernel = FALSE ) ## S3 method for class 'CovEsts' kernel_est( estCov, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(estCov$acf), maxLag = length(estCov$acf) - 1, x = estCov$lags, type = c("autocovariance", "autocorrelation"), custom_kernel = FALSE ) ## Default S3 method: kernel_est( estCov, kernel_name = c("gaussian", "exponential", "wave", "rational_quadratic", "spherical", "circular", "bessel_j", "matern", "cauchy"), kernel_params = c(), N_T = 0.1 * length(estCov), maxLag = length(estCov) - 1, x = 0:length(estCov), type = c("autocovariance", "autocorrelation"), custom_kernel = FALSE )
estCov |
A vector whose values are an estimate autocovariance function. |
kernel_name |
The name of the kernel_ec function to be used. Possible values are: gaussian, exponential, wave, rational_quadratic, spherical, circular, bessel_j, matern, cauchy. |
kernel_params |
A vector of parameters of the kernel function. See kernel_ec for parameters.
In the case of gaussian, wave, rational_quadratic, spherical and circular, |
N_T |
The range at which the kernel function vanishes at. Recommended to be |
maxLag |
An optional parameter that determines the maximum lag to compute the estimated autocovariance function at. Defaults to |
x |
A vector of lag indices. Defaults to the sequence |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
custom_kernel |
If a custom kernel is to be used or not. Defaults to |
A vector whose values are the kernel corrected autocovariance estimates or CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on, inherited from the argument estCov.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the argument type.
est_usedThe estimator function used, in this case, 'kernel_est'.
If a numeric vector is given for the argument estCov, then a numeric vector output is given, and if a CovEsts S3 object is given, a CovEsts object is given as output.
kernel_est(CovEsts): Method for CovEsts objects.
kernel_est(default): Method for numeric vectors.
X <- rnorm(1000) Y <- c(X[1], X[2]) for(i in 3:length(X)) { Y[i] <- X[i] - 0.3*X[i - 1] - 0.6*X[i - 2] } cov_est <- standard_est(Y) plot(cov_est) plot(kernel_est(cov_est, "bessel_j", kernel_params=c(0, 1), N_T=0.2*length(Y)))X <- rnorm(1000) Y <- c(X[1], X[2]) for(i in 3:length(X)) { Y[i] <- X[i] - 0.3*X[i - 1] - 0.6*X[i - 2] } cov_est <- standard_est(Y) plot(cov_est) plot(kernel_est(cov_est, "bessel_j", kernel_params=c(0, 1), N_T=0.2*length(Y)))
These functions computes values of kernels that have the properties of symmetric probability distributions. Note that kernel_symm() is deprecated, please use kernel_symm_ec() instead.
For a kernel , the standardised version is , so that the integral is 1.
The symmetric kernels are different to kernel and are used in the functions adjusted_est and truncated_est.
kernel_symm_ec( x, name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), params = c(1) )kernel_symm_ec( x, name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), params = c(1) )
x |
A vector or matrix of arguments of at least length 1 for which the kernel is computed at. Each value can be negative as well as positive. |
name |
The name of the kernel. Options are: gaussian, wave, rational_quadratic, bessel_j. |
params |
A vector of parameters for the kernel. See the documentation below for the position of the parameters. All kernels will have a scale parameter as the first value in the vector. |
Symmetric Gaussian Kernel. The symmetric Gaussian kernel is defined as
The params argument is of the form c().
Symmetric Wave Kernel. The wave (cardinal sine) kernel is given by
where
The params argument is of the form c()
Symmetric Rational Quadratic Kernel. The symmetric rational quadratic kernel is given by
The params argument is of the form c()
Symmetric Besesel Kernel.
The symmetric Bessel kernel, which is valid when is given by
where is the Bessel function of the first kind and is the dimension.
The params argument is of the form c().
A vector or matrix of values.
x <- c(-2, -1, 0, 1, 2) theta <- 1 kernel_symm_ec(x, "gaussian", c(theta)) kernel_symm_ec(x, "wave", c(theta)) kernel_symm_ec(x, "rational_quadratic", c(theta)) dim <- 1 nu <- 1 kernel_symm_ec(x, "bessel_j", c(theta, nu, dim)) curve(kernel_symm_ec(x, "gaussian", c(theta)), from = -5, to = 5) curve(kernel_symm_ec(x, "wave", c(theta)), from = -5, to = 5) curve(kernel_symm_ec(x, "rational_quadratic", c(theta)), from = -5, to = 5) curve(kernel_symm_ec(x, "bessel_j", c(theta, nu, dim)), from = -5, to = 5)x <- c(-2, -1, 0, 1, 2) theta <- 1 kernel_symm_ec(x, "gaussian", c(theta)) kernel_symm_ec(x, "wave", c(theta)) kernel_symm_ec(x, "rational_quadratic", c(theta)) dim <- 1 nu <- 1 kernel_symm_ec(x, "bessel_j", c(theta, nu, dim)) curve(kernel_symm_ec(x, "gaussian", c(theta)), from = -5, to = 5) curve(kernel_symm_ec(x, "wave", c(theta)), from = -5, to = 5) curve(kernel_symm_ec(x, "rational_quadratic", c(theta)), from = -5, to = 5) curve(kernel_symm_ec(x, "bessel_j", c(theta, nu, dim)), from = -5, to = 5)
This function plots a BootEsts object as a line onto another plot.
## S3 method for class 'BootEsts' lines(x, type = "l", ...)## S3 method for class 'BootEsts' lines(x, type = "l", ...)
x |
A BootEsts S3 object. |
type |
Defaults to |
... |
Additional plotting arguments, refer to graphics::par. |
A line of a BootEsts S3 object.
plot(block_bootstrap(c(1, 2, 3), 2)) lines(block_bootstrap(c(1, 2, 3), 2, pd = FALSE), lwd = 2, lty = 3, col = 'blue')plot(block_bootstrap(c(1, 2, 3), 2)) lines(block_bootstrap(c(1, 2, 3), 2, pd = FALSE), lwd = 2, lty = 3, col = 'blue')
This function plots a CovEsts object as a line onto another plot.
## S3 method for class 'CovEsts' lines(x, type = "l", ...)## S3 method for class 'CovEsts' lines(x, type = "l", ...)
x |
A CovEst S3 object. |
type |
Defaults to |
... |
Additional plotting arguments, refer to graphics::par. |
A line of a CovEsts S3 object.
plot(standard_est(c(1, 2, 3))) lines(standard_est(c(1, 2, 3), pd = FALSE))plot(standard_est(c(1, 2, 3))) lines(standard_est(c(1, 2, 3), pd = FALSE))
This function plots a VarioEsts object as a line onto another plot.
## S3 method for class 'VarioEsts' lines(x, type = "l", ...)## S3 method for class 'VarioEsts' lines(x, type = "l", ...)
x |
A VarioEsts S3 object. |
type |
Defaults to |
... |
Additional plotting arguments, refer to graphics::par. |
A line of a VarioEsts S3 object.
plot(to_vario(standard_est(c(1, 2, 3)))) lines(to_vario(standard_est(c(1, 2, 3), pd = FALSE)))plot(to_vario(standard_est(c(1, 2, 3)))) lines(to_vario(standard_est(c(1, 2, 3), pd = FALSE)))
This function can make a function positive-definite using the methods proposed by P. Hall and his coauthors.
make_pd(x, method.1 = TRUE) ## S3 method for class 'CovEsts' make_pd(x, method.1 = TRUE) ## Default S3 method: make_pd(x, method.1 = TRUE)make_pd(x, method.1 = TRUE) ## S3 method for class 'CovEsts' make_pd(x, method.1 = TRUE) ## Default S3 method: make_pd(x, method.1 = TRUE)
x |
A vector of numeric values of an estimated autocovariance function. |
method.1 |
Should method 1 be used (TRUE) or method 2 (FALSE). |
This function perform positive-definite adjustments proposed by P. Hall and his coauthors.
Method 1 is as follows:
Take the discrete Fourier cosine transform,
.
Compute a modified spectrum for all sample frequencies.
Perform the Fourier inversion to obtain a new estimator.
Method 2 is as follows:
Take the discrete Fourier cosine transform .
Find the smallest frequency where its associated value in the spectral domain is negative
Compute a modified spectrum
where is the indicator function over the set
Perform the Fourier inversion.
A vector that is the adjusted function or a CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on, inherited from the argument x.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', inherited from the argument x.
est_usedThe estimator function used, inherited from the argument x.
correction_methodEither 'method.1' or 'method.2' depending on the argument method.1
If a numeric vector is given for the argument x, then a numeric vector output is given, and if a CovEsts S3 object is given, a CovEsts object is given as output.
make_pd(CovEsts): Method for CovEsts objects.
make_pd(default): Method for numeric vectors.
Hall, P. & Patil, P. (1994). Properties of nonparametric estimators of autocovariance for stationary random fields. Probability Theory and Related Fields 99(3), 399-424. https://doi.org/10.1007/bf01199899
Hall, P., Fisher, N. I., & Hoffmann, B. (1994). On the nonparametric estimation of covariance functions. The Annals of Statistics 22(4), 2115-2134. https://doi.org/10.1214/aos/1176325774
Bilchouris, A. & Olenko, A (2025). On Nonparametric Estimation of Covariogram. Austrian Statistical Society 54(1), 112-137. https://doi.org/10.17713/ajs.v54i1.1975
X <- c(1, 2, 3, 4) make_pd(X) check_pd(make_pd(X)) check_pd(make_pd(X, method.1 = FALSE))X <- c(1, 2, 3, 4) make_pd(X) check_pd(make_pd(X)) check_pd(make_pd(X, method.1 = FALSE))
This function computes the maximum vertical distance between functions.
max_distance(est1, est2, lags = c(), plot = FALSE) ## S3 method for class 'CovEsts' max_distance(est1, est2, lags = c(), plot = FALSE) ## Default S3 method: max_distance(est1, est2, lags = c(), plot = FALSE)max_distance(est1, est2, lags = c(), plot = FALSE) ## S3 method for class 'CovEsts' max_distance(est1, est2, lags = c(), plot = FALSE) ## Default S3 method: max_distance(est1, est2, lags = c(), plot = FALSE)
est1 |
A numeric vector representing the first estimated autocovariance function. |
est2 |
A numeric vector of the same length as |
lags |
An optional vector of lags starting from 0 up until some other lag. If empty, a vector of lags is created starting from 0 until |
plot |
A boolean as to whether a plot should be created. By default, no plot is created. |
This function computes the maximum vertical distance between functions:
where and are estimated autocovariance functions.
It assumes that the estimated values are given for the same set of lags.
The vectors of the function values must be of the same length.
A numeric value representing the maximum vertical distance between the two estimated functions.
max_distance(CovEsts): Method for CovEsts objects.
max_distance(default): Method for numeric vectors.
x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) max_distance(estCov1, estCov2, lags=x) max_distance(estCov1, estCov2, lags=x, plot = TRUE)x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) max_distance(estCov1, estCov2, lags=x) max_distance(estCov1, estCov2, lags=x, plot = TRUE)
This function computes the mean-square difference/error between two autocovariance functions (estimated or theoretical).
mse(est1, est2) ## S3 method for class 'CovEsts' mse(est1, est2) ## Default S3 method: mse(est1, est2)mse(est1, est2) ## S3 method for class 'CovEsts' mse(est1, est2) ## Default S3 method: mse(est1, est2)
est1 |
A numeric vector representing the first estimated autocovariance function. |
est2 |
A numeric vector of the same length as |
This function computes the mean-square difference/error (MSE) between two estimated autocovariance functions (estimated or theoretical). The MSE is defined as
over a set of lags
A numeric value representing the MSE between two autocovariance functions (estimated or theoretical).
mse(CovEsts): Method for CovEsts object.
mse(default): Method for numeric vectors.
x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) mse(estCov1, estCov2)x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) mse(estCov1, estCov2)
This function computes the nearest positive-definite matrix to some matrix .
nearest_pd(X) ## S3 method for class 'CovEsts' nearest_pd(X) ## Default S3 method: nearest_pd(X)nearest_pd(X) ## S3 method for class 'CovEsts' nearest_pd(X) ## Default S3 method: nearest_pd(X)
X |
Either a numeric square matrix. If a vector is provided, a matrix will be created of the form found in cyclic_matrix. |
This function computes the nearest positive-definite matrix to some matrix .
The procedure to do so is as follows
For a matrix , compute the symmetric matrix
Let be the polar decomposition of B.
The nearest positive-definite matrix to is
Unlike shrinking, only an autocorrelation matrix can be returned, not an autocovariance function.
The implementation is a translation of https://au.mathworks.com/matlabcentral/fileexchange/42885-nearestspd#functions_tab .
The closest positive-definite autocorrelation matrix.
nearest_pd(CovEsts): Method for CovEsts objects.
nearest_pd(default): Method for numeric vectors.
Higham, N. J. (1988). Computing a nearest symmetric positive semidefinite matrix. Linear Algebra and its Applications, 103, 103-118. https://doi.org/10.1016/0024-3795(88)90223-6
D'Errico, J. (2025). nearestSPD (https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd), MATLAB Central File Exchange. Retrieved August 2, 2025.
X <- c(1, 0, -1.1) nearest_pd(X) check_pd(nearest_pd(X))X <- c(1, 0, -1.1) nearest_pd(X) check_pd(nearest_pd(X))
This function normalises a CovEsts S3 object, that is, turning an autocovariance function into an autocorrelation function. This procedure is a one-way transformation. This function does not support any other type of argument.
normalise_acf(estCov) ## Default S3 method: normalise_acf(estCov) ## S3 method for class 'CovEsts' normalise_acf(estCov)normalise_acf(estCov) ## Default S3 method: normalise_acf(estCov) ## S3 method for class 'CovEsts' normalise_acf(estCov)
estCov |
A CovEst S3 object. |
A CovEsts S3 object with a normalised acf attribute.
normalise_acf(default): Method for other objects.
normalise_acf(CovEsts): Method for 'CovEsts' objects.
normalise_acf(standard_est(c(1, 2, 3)))normalise_acf(standard_est(c(1, 2, 3)))
This function plots a BootEsts object. It plots the confidence region, average bootstrap estimate, and the original nonbootstrapped estimate.
## S3 method for class 'BootEsts' plot(x, type = "l", xlab = "Lag (h)", ylab = "ACF", ...)## S3 method for class 'BootEsts' plot(x, type = "l", xlab = "Lag (h)", ylab = "ACF", ...)
x |
A BootEsts S3 object. |
type |
Defaults to |
xlab |
Defaults to |
ylab |
Defaults to |
... |
Additional plotting arguments, refer to graphics::par. |
A plot of a BootEsts S3 object.
plot(block_bootstrap(c(1, 2, 3), 2))plot(block_bootstrap(c(1, 2, 3), 2))
This function plots a CovEsts object, over the lags used to estimate the autocovariance values.
## S3 method for class 'CovEsts' plot(x, type = "l", xlab = "Lag (h)", ylab = "ACF", ...)## S3 method for class 'CovEsts' plot(x, type = "l", xlab = "Lag (h)", ylab = "ACF", ...)
x |
A CovEst S3 object. |
type |
Defaults to |
xlab |
Defaults to |
ylab |
Defaults to |
... |
Additional plotting arguments, refer to graphics::par. |
A plot of a CovEsts S3 object.
plot(standard_est(c(1, 2, 3)))plot(standard_est(c(1, 2, 3)))
This function plots a VarioEsts object, over the lags used to estimate the variogram values.
## S3 method for class 'VarioEsts' plot(x, type = "l", xlab = "Lag (h)", ylab = expression(gamma(h)), ...)## S3 method for class 'VarioEsts' plot(x, type = "l", xlab = "Lag (h)", ylab = expression(gamma(h)), ...)
x |
A VarioEsts S3 object. |
type |
Defaults to |
xlab |
Defaults to |
ylab |
Defaults to |
... |
Additional plotting arguments, refer to graphics::par. |
A plot of a VarioEsts S3 object.
plot(to_vario(standard_est(c(1, 2, 3))))plot(to_vario(standard_est(c(1, 2, 3))))
This function plots a BootEsts object, printing estimtor type, bootstrap type, estimator used, the bootstrap average estimate, the original estimate, and the pointwise confidence interval.
## S3 method for class 'BootEsts' print(x, n_head = 5, n_tail = 5, digits = NULL, ...)## S3 method for class 'BootEsts' print(x, n_head = 5, n_tail = 5, digits = NULL, ...)
x |
A BootEsts S3 object. |
n_head |
The number of 'head' values to print, defaults to 5. |
n_tail |
The number of 'tail' values to print, defaults to 5. |
digits |
The number of digits to print. Defaults to |
... |
Addition printing parameters, see base::print. |
Prints a BootEsts object.
print(block_bootstrap(c(1, 2, 3), 2))print(block_bootstrap(c(1, 2, 3), 2))
This function plots a CovEsts object, printing the estimator type, estimator used, lags and values.
## S3 method for class 'CovEsts' print(x, n_head = 5, n_tail = 5, digits = NULL, ...)## S3 method for class 'CovEsts' print(x, n_head = 5, n_tail = 5, digits = NULL, ...)
x |
A CovEst S3 object. |
n_head |
The number of 'head' values to print, defaults to 5. |
n_tail |
The number of 'tail' values to print, defaults to 5. |
digits |
The number of digits to print. Defaults to |
... |
Addition printing parameters, see base::print. |
Prints a CovEsts object.
print(standard_est(c(1, 2, 3)))print(standard_est(c(1, 2, 3)))
This function plots a VarioEsts object, printing the lags and values.
## S3 method for class 'VarioEsts' print(x, n_head = 5, n_tail = 5, digits = NULL, ...)## S3 method for class 'VarioEsts' print(x, n_head = 5, n_tail = 5, digits = NULL, ...)
x |
A VarioEsts S3 object. |
n_head |
The number of 'head' values to print, defaults to 5. |
n_tail |
The number of 'tail' values to print, defaults to 5. |
digits |
The number of digits to print. Defaults to |
... |
Addition printing parameters, see base::print. |
Prints a VarioEsts object.
print(to_vario(standard_est(c(1, 2, 3))))print(to_vario(standard_est(c(1, 2, 3))))
used in the Truncated Kernel Regression Estimator.This helper function computes used in the truncated kernel regression estimator, truncated_est.
rho_T1( x, meanX, T1, b, xij_mat, kernel_name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), kernel_params = c(), custom_kernel = FALSE )rho_T1( x, meanX, T1, b, xij_mat, kernel_name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), kernel_params = c(), custom_kernel = FALSE )
x |
A vector of lags. |
meanX |
The average value of |
T1 |
The first trunctation point. |
b |
Bandwidth parameter, greater than 0. |
xij_mat |
The matrix of pairwise covariance values. |
kernel_name |
The name of the symmetric kernel (see kernel_symm_ec) function to be used. Possible values are: gaussian, wave, rational_quadratic, and bessel_j. Alternatively, a custom kernel function can be provided, see the examples. |
kernel_params |
A vector of parameters of the kernel function. See kernel_symm_ec for parameters. |
custom_kernel |
If a custom kernel is to be used or not. Defaults to |
This function computes the following value,
where
which is then used in truncated_est,
The estimated autocovariance function at .
Hall, P. & Patil, P. (1994). Properties of nonparametric estimators of autocovariance for stationary random fields. Probability Theory and Related Fields 99(3), 399-424. https://doi.org/10.1007/bf01199899
Hall, P., Fisher, N. I., & Hoffmann, B. (1994). On the nonparametric estimation of covariance functions. The Annals of Statistics 22(4), 2115-2134. https://doi.org/10.1214/aos/1176325774
## Not run: X <- c(1, 2, 3, 4) rho_T1(1:4, mean(X), 1, 0.1, Xij_mat(X, mean(X)), "gaussian", c(), FALSE) my_kernel <- function(x, params) { stopifnot(params[1] > 0, length(x) >= 1) return(exp(-((abs(x) / params[1])^params[2])) * (2 * params[1] * gamma(1 + 1/params[2]))) } rho_T1(1:4, mean(X), 1, 0.1, Xij_mat(X, mean(X)), my_kernel, c(0.25), TRUE) ## End(Not run)## Not run: X <- c(1, 2, 3, 4) rho_T1(1:4, mean(X), 1, 0.1, Xij_mat(X, mean(X)), "gaussian", c(), FALSE) my_kernel <- function(x, params) { stopifnot(params[1] > 0, length(x) >= 1) return(exp(-((abs(x) / params[1])^params[2])) * (2 * params[1] * gamma(1 + 1/params[2]))) } rho_T1(1:4, mean(X), 1, 0.1, Xij_mat(X, mean(X)), my_kernel, c(0.25), TRUE) ## End(Not run)
This function corrects an autocovariance/autocorrelation function estimate via linear shrinking of the autocorrelation matrix.
shrinking(estCov, return_matrix = FALSE, target = NULL) ## S3 method for class 'CovEsts' shrinking(estCov, return_matrix = FALSE, target = NULL) ## Default S3 method: shrinking(estCov, return_matrix = FALSE, target = NULL)shrinking(estCov, return_matrix = FALSE, target = NULL) ## S3 method for class 'CovEsts' shrinking(estCov, return_matrix = FALSE, target = NULL) ## Default S3 method: shrinking(estCov, return_matrix = FALSE, target = NULL)
estCov |
A vector whose values are an estimate autocovariance/autocorrelation function. |
return_matrix |
A boolean determining whether the shrunken matrix or the corresponding vector is returned. If |
target |
A shrinkage target matrix used in the shrinking process. This should only be used if you wish to use a specific matrix as the target. |
This function corrects an autocovariance/autocorrelation function estimate via linear shrinking of the autocorrelation matrix. The shrunken autocorrelation matrix is computed as follows
where is the shrunken autocorrelation matrix, is the original autocorrelation matrix, and is the identity matrix.
is chosen in such a away that largest value which still results in a positive-definite matrix.
The shrunken matrix will be positive-definite.
A vector with values of the shrunken autocorrelation function, the corresponding matrix (depending on return_matrix), or CovEsts S3 object (list) with the following values
acfA numeric vector containing the shrunken autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on, inherited from the argument estCov.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the argument type.
est_usedThe estimator function used, in this case, inherited from the argument estCov.
correction_methodThis value is 'shrinking'.
lambdaThe value obtained during the shrinking process.
If a numeric vector is given for the argument estCov, then a numeric vector output is given, and if a CovEsts S3 object is given, a CovEsts object is given as output.
shrinking(CovEsts): Method for CovEsts objects.
shrinking(default): Method for numeric vectors
Devlin, S. J., Gnanadesikan R. & Kettenring, J. R. (1975). Robust Estimation and Outlier Detection with Correlation Coefficients. Biometrika, 62(3), 531-545. 10.1093/biomet/62.3.531
Rousseeuw, P. J. & Molenberghs, G. (1993). Transformation of Non Positive Semidefinite Correlation Matrices. Communications in Statistics - Theory and Methods, 22(4), 965-984. 10.1080/03610928308831068
estCorr <- c(1, 0.8, 0.5, -1.2) shrinking(estCorr) target <- diag(length(estCorr)) shrinking(estCorr, TRUE, target)estCorr <- c(1, 0.8, 0.5, -1.2) shrinking(estCorr) target <- diag(length(estCorr)) shrinking(estCorr, TRUE, target)
This is an objective function used to select in linear shrinking, see shrinking.
solve_shrinking(par, corr_mat, target)solve_shrinking(par, corr_mat, target)
par |
The initial parameter used in the maximisation process. |
corr_mat |
The autocorrelation matrix of the considered time series. |
target |
A shrinkage target matrix used in the shrinking process. This should only be used if you wish to use a specific matrix as the target. |
A numeric value that is either equal to par or 1.
Devlin, S. J., Gnanadesikan R. & Kettenring, J. R. (1975). Robust Estimation and Outlier Detection with Correlation Coefficients. Biometrika, 62(3), 531-545. 10.1093/biomet/62.3.531
Rousseeuw, P. J. & Molenberghs, G. (1993). Transformation of Non Positive Semidefinite Correlation Matrices. Communications in Statistics - Theory and Methods, 22(4), 965-984. 10.1080/03610928308831068
## Not run: estCorr <- c(1, 0.5, 0) corr_mat <- cyclic_matrix(estCorr) solve_shrinking(0.5, corr_mat, diag(length(estCorr))) ## End(Not run)## Not run: estCorr <- c(1, 0.5, 0) corr_mat <- cyclic_matrix(estCorr) solve_shrinking(0.5, corr_mat, diag(length(estCorr))) ## End(Not run)
This is the objective function to find the weights for each basis function in the minimising spline, see Choi, Li & Wang (2013, p. 617).
The parameters must be nonnegative, so a penalty of is given if any parameters are negative.
The weights are chosen as per Choi, Li & Wang (2013, p. 617).
solve_spline(par, splines_df, weights)solve_spline(par, splines_df, weights)
par |
A vector of initial parameters to used in the minimisation process. |
splines_df |
A data frame whose structure is defined in splines_df. |
weights |
A vector of weights, see the description. |
Let be a vector of model coefficients,
be a set of completely monotone basis functions, and be an estimated covariance function.
As per Choi, Li & Wang (2013, p. 617), can be estimated via weighted-least squares,
where is a set of lags and is a set of weights.
The set of weights is calculated in splines_est, and they are of the form
The value of the objective function at those parameters.
Choi, I., Li, B. & Wang, X. (2013). Nonparametric Estimation of Spatial and Space-Time Covariance Function. JABES 18, 611-630. https://doi.org/10.1007/s13253-013-0152-z
## Not run: taus <- get_taus(3, 2) x <- seq(0, 2, by=0.25) maxLag <- 4 splines_df <- splines_df(x[1:maxLag], 3, 2, taus) splines_df$estCov <- exp(-splines_df$lags^2) + 0.001 # pars are the initial parameters used in the minimisation process. pars <- c(0.5, 0.5, 0.5, 0.5, 0.5) weights <- c() X <- rnorm(50) for(i in 0:(maxLag - 1)) { weights <- c(weights, (length(X) - i) / ( (1 - splines_df$estCov[i + 1])^2 )) } solve_spline(pars, splines_df, weights) ## End(Not run)## Not run: taus <- get_taus(3, 2) x <- seq(0, 2, by=0.25) maxLag <- 4 splines_df <- splines_df(x[1:maxLag], 3, 2, taus) splines_df$estCov <- exp(-splines_df$lags^2) + 0.001 # pars are the initial parameters used in the minimisation process. pars <- c(0.5, 0.5, 0.5, 0.5, 0.5) weights <- c() X <- rnorm(50) for(i in 0:(maxLag - 1)) { weights <- c(weights, (length(X) - i) / ( (1 - splines_df$estCov[i + 1])^2 )) } solve_spline(pars, splines_df, weights) ## End(Not run)
This function computes the spectral norm of the difference of two estimated autocovariance functions. This function is intended for estimates over lags with a constant difference.
spectral_norm(est1, est2) ## S3 method for class 'CovEsts' spectral_norm(est1, est2) ## Default S3 method: spectral_norm(est1, est2)spectral_norm(est1, est2) ## S3 method for class 'CovEsts' spectral_norm(est1, est2) ## Default S3 method: spectral_norm(est1, est2)
est1 |
A numeric vector representing the first estimated autocovariance function. |
est2 |
A numeric vector of the same length as |
This function computes the spectral norm of the difference of two estimated autocovariance functions.
Let
where and are estimated autocovariance functions.
A matrix is created from ,
over a set of lags
This matrix is created by cyclic_matrix.
The spectral norm is defined as the largest eigenvalue of
The spectral norm of the differences between the two functions.
spectral_norm(CovEsts): Method for CovEsts objects.
spectral_norm(default): Method for numeric vectors.
x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) spectral_norm(estCov1, estCov2)x <- seq(0, 5, by=0.1) estCov1 <- exp(-x^2) estCov2 <- exp(-x^2.1) spectral_norm(estCov1, estCov2)
This helper function constructs a data frame with the following structure:
One column for the x-values
m + p columns values of squared basis functions evaluated at the corresponding x.
splines_df(x, p, m, taus)splines_df(x, p, m, taus)
x |
A vector of lags. |
p |
The order of the splines. |
m |
The number of nonboundary knots. |
taus |
Vector of |
A data frame of the above structure.
## Not run: taus <- get_taus(3, 2) splines_df(seq(0, 2, by=0.25), 3, 2, taus) ## End(Not run)## Not run: taus <- get_taus(3, 2) splines_df(seq(0, 2, by=0.25), 3, 2, taus) ## End(Not run)
Compute the estimated covariance function by using the method from Choi, Li & Wang (2013, pp. 614-617).
where is the number of nonboundary knots, is the order of the splines, is the isotropic distance, are nonnegative weights and are basis functions of order
For optimisation, the Nelder-Mead and L-BFGS-B methods are used, the one which selects parameters which minimises the objective function is chosen.
splines_est( X, x, estCov, p, m, maxLag = length(X) - 1, type = c("autocovariance", "autocorrelation"), initial_pars = c(), control = list(maxit = 1000) ) ## S3 method for class 'CovEsts' splines_est( X, x, estCov, p, m, maxLag = length(X) - 1, type = c("autocovariance", "autocorrelation"), initial_pars = c(), control = list(maxit = 1000) ) ## Default S3 method: splines_est( X, x, estCov, p, m, maxLag = length(X) - 1, type = c("autocovariance", "autocorrelation"), initial_pars = c(), control = list(maxit = 1000) )splines_est( X, x, estCov, p, m, maxLag = length(X) - 1, type = c("autocovariance", "autocorrelation"), initial_pars = c(), control = list(maxit = 1000) ) ## S3 method for class 'CovEsts' splines_est( X, x, estCov, p, m, maxLag = length(X) - 1, type = c("autocovariance", "autocorrelation"), initial_pars = c(), control = list(maxit = 1000) ) ## Default S3 method: splines_est( X, x, estCov, p, m, maxLag = length(X) - 1, type = c("autocovariance", "autocorrelation"), initial_pars = c(), control = list(maxit = 1000) )
X |
A vector representing observed values of the time series. |
x |
A vector of lag indices. |
estCov |
An estimated autocovariance function to fit to (a vector). |
p |
The order of the splines. |
m |
The number of nonboundary knots. |
maxLag |
An optional parameter that determines the maximum lag to compute the estimated autocovariance function at. Defaults to |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
initial_pars |
An optional vector of parameters - can be used to fine tune the fit. By default, it is a vector of 0.5 whose length is |
control |
An optional list of optimisation parameters used in the optimisation process, see |
Due to the weighting scheme, the autocovariance at lag zero cannot be 1,
A vector whose values are the spline autocovariance estimates or a CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the type parameter.
est_usedThe estimator function used, in this case, 'splines_est'.
If a numeric vector is given for the argument estCov, then a numeric vector output is given, and if a CovEsts S3 object is given, a CovEsts object is given as output.
splines_est(CovEsts): Method for 'CovEsts' objects.
splines_est(default): Method for numeric vectors.
Choi, I., Li, B. & Wang, X. (2013). Nonparametric Estimation of Spatial and Space-Time Covariance Function. JABES 18, 611-630. https://doi.org/10.1007/s13253-013-0152-z
X <- rnorm(100) x <- seq(0, 5, by = 0.25) maxLag <- 5 estCov <- standard_est(X, maxLag = maxLag) estimated <- splines_est(X, x, estCov, 3, 2, maxLag = maxLag) estimatedX <- rnorm(100) x <- seq(0, 5, by = 0.25) maxLag <- 5 estCov <- standard_est(X, maxLag = maxLag) estimated <- splines_est(X, x, estCov, 3, 2, maxLag = maxLag) estimated
This function computes the following two estimates of the autocovariance function depending on
the parameter pd, see the Details section.
standard_est( X, pd = TRUE, maxLag = length(X) - 1, x = 0:length(X), type = c("autocovariance", "autocorrelation"), meanX = mean(X) )standard_est( X, pd = TRUE, maxLag = length(X) - 1, x = 0:length(X), type = c("autocovariance", "autocorrelation"), meanX = mean(X) )
X |
A vector representing observed values of the time series. |
pd |
Whether a positive-definite estimate should be used. Defaults to |
maxLag |
An optional parameter that determines the maximum lag to compute the estimated autocovariance function at. Defaults to |
x |
A vector of lag indices. Defaults to the sequence |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
meanX |
The average value of |
For pd = TRUE:
For pd = FALSE:
This function will generate autocovariance values for lags from the set
The positive-definite estimator must be used cautiously when estimating over all lags as the sum of all values of the autocorrelation function equals to .
For the nonpositive-definite estimator a similar constant summation property holds.
A CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the type parameter.
est_usedThe estimator function used, in this case, 'standard_est'.
Bilchouris, A. & Olenko, A (2025). On Nonparametric Estimation of Covariogram. Austrian Statistical Society 54(1), 112-137. https://doi.org/10.17713/ajs.v54i1.1975
X <- c(1, 2, 3) standard_est(X, pd = FALSE, maxLag = 2, meanX = mean(X))X <- c(1, 2, 3) standard_est(X, pd = FALSE, maxLag = 2, meanX = mean(X))
This function performs random sampling to obtain random starting locations for block bootstrap.
starting_locs(N, l, k, boot_type = c("moving", "circular"))starting_locs(N, l, k, boot_type = c("moving", "circular"))
N |
The length of the observation window. |
l |
The block length considered for bootstrap. |
k |
The number of blocks considered for bootstrap. |
boot_type |
What type of block bootstrap should be used, either 'moving' for moving block bootstrap or 'circular' for circular block bootstrap. |
This function performs random sampling to obtain random starting locations for block bootstrap.
If type = 'moving', the set is randomly sampled, with replacement, times to obtain random block locations for moving block bootstrap.
If type = 'circular', the set is randomly sampled, with replacement, times to obtain random block locations for moving block bootstrap.
A vector of length k whose values are random block locations.
Chapters 2.5 and 2.7 in Lahiri, S. N. (2003). Resampling Methods for Dependent Data. Springer. https://doi.org/10.1007/978-1-4757-3803-2
Künsch, H. R. (1989). The Jackknife and the Bootstrap for General Stationary Observations. The Annals of Statistics 17(3), 1217-1241. https://doi.org/10.1214/aos/1176347265
Politis, D. N. & Romano, J. P. (1991). A Circular Block-Resampling Procedure for Stationary Data. In R. LePage & L. Billard, eds, Exploring the Limits of Bootstrap, Wiley, 263-270.
starting_locs(4, 2, 2)starting_locs(4, 2, 2)
This helper function computes the taper function for a given window function as
where is a continuous increasing function with
and The possible window function choices are found in window_ec.
taper( x, rho, window_name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), window_params = c(1), custom_window = FALSE )taper( x, rho, window_name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), window_params = c(1), custom_window = FALSE )
x |
A vector of numbers between 0 and 1 (inclusive). |
rho |
A scale parameter in |
window_name |
The name of the window_ec function to be used. Possible values are: tukey, triangular, power_sine, blackman_window, hann_poisson, welch. Alternatively, a custom window function can be provided, see the example. |
window_params |
A vector of parameters of the window function. |
custom_window |
If a custom window is to be used or not. Defaults to |
A vector of taper values.
X <- c(0.1, 0.2, 0.3) taper(X, 0.5, "tukey") curve(taper(x, 1, "tukey"), from = 0, to = 1) curve(taper(x, 1, "power_sine", c(4)), from = 0, to = 1) my_taper <- function(x, ...) { return(x) } taper(X, 0.5, my_taper, custom_window = TRUE)X <- c(0.1, 0.2, 0.3) taper(X, 0.5, "tukey") curve(taper(x, 1, "tukey"), from = 0, to = 1) curve(taper(x, 1, "power_sine", c(4)), from = 0, to = 1) my_taper <- function(x, ...) { return(x) } taper(X, 0.5, my_taper, custom_window = TRUE)
This function computes the tapered autocovariance over a set of lags.
tapered_est( X, rho, window_name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), window_params = c(1), maxLag = length(X) - 1, x = 0:length(X), type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_window = FALSE )tapered_est( X, rho, window_name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), window_params = c(1), maxLag = length(X) - 1, x = 0:length(X), type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_window = FALSE )
X |
A vector representing observed values of the time series. |
rho |
A scale parameter in |
window_name |
The name of the window_ec function to be used. Possible values are: tukey, triangular, sine, power_sine, blackman_window, hann_poisson, welch. Alternatively, a custom window_ec function can be provided, see the example in taper. |
window_params |
A vector of parameters of the window function. |
maxLag |
An optional parameter that determines the maximum lag to compute the estimated autocovariance function at. Defaults to |
x |
A vector of lag indices. Defaults to the sequence |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
meanX |
The average value of |
custom_window |
If a custom window is to be used or not. Defaults to |
This function computes the estimated tapered autocovariance over a set of lags,
where is a window function, is a scale parameter.
This estimator takes into account the edge effect during estimation, assigning a lower weight to values closer to the boundaries and higher weights for observations closer to the middle.
This estimator is positive-definite and asymptotically unbiased.
A CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the type parameter.
est_usedThe estimator function used, in this case, 'tapered_est'.
Dahlhaus R. & Künsch, H. (1987). Edge Effects and Efficient Parameter Estimation for Stationary Random Fields. Biometrika 74(4), 877-882. 10.1093/biomet/74.4.877
X <- c(1, 2, 3) tapered_est(X, 0.5, "tukey", maxLag = 2)X <- c(1, 2, 3) tapered_est(X, 0.5, "tukey", maxLag = 2)
This function computes the partial autocorrelation function from an estimated autocovariance or autocorrelation function.
to_pacf(estCov) ## S3 method for class 'CovEsts' to_pacf(estCov) ## Default S3 method: to_pacf(estCov)to_pacf(estCov) ## S3 method for class 'CovEsts' to_pacf(estCov) ## Default S3 method: to_pacf(estCov)
estCov |
A numeric vector representing an estimated autocovariance or autocorrelation function. |
This function is a translation of the 'uni_pacf' function in src/library/stats/src/pacf.c of the R source code which is an implementation of the Durbin-Levinson algorithm.
A vector whose values are an estimate partial autocorrelation function or a CovEsts S3 object (list) with the following values
acfA numeric vector containing the partial autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on.
est_typeThe type of estimate, namely 'partial'.
est_usedThe estimator function used, in this case, 'to_pacf'.
If a numeric vector is given for the argument estCov, then a numeric vector output is given, and if a CovEsts S3 object is given, a CovEsts object is given as output.
to_pacf(CovEsts): Method for CovEsts objects.
to_pacf(default): Method for numeric vectors.
X <- c(1, 2, 3) to_pacf(standard_est(X, pd = FALSE, maxLag = 2, meanX = mean(X)))X <- c(1, 2, 3) to_pacf(standard_est(X, pd = FALSE, maxLag = 2, meanX = mean(X)))
This function computes an estimated semivariogram using an estimated autocovariance function.
to_vario(estCov) ## Default S3 method: to_vario(estCov) ## S3 method for class 'CovEsts' to_vario(estCov)to_vario(estCov) ## Default S3 method: to_vario(estCov) ## S3 method for class 'CovEsts' to_vario(estCov)
estCov |
A vector whose values are an estimate autocovariance function or a |
The semivariogram, and autocovariance function, , under the assumption of weak stationarity are related as follows:
When an empirical autocovariance function is considered instead, this relation does not necessarily hold, however, it can be used to obtain a function that is close to a semivariogram, see Bilchouris and Olenko (2025).
A numeric vector whose values are an estimate of the semivariogram or an VarioEsts S3 object (list) with the following values
varioA numeric vector whose values are an estimate of the semivariogram.
lagsA numeric vector containing the lag indices used to compute the estimates on, inherited from the argument estCov.
est_usedThe estimator function used, in this case, 'to_vario'.
If a numeric vector is given for the argument estCov, then a numeric vector output is given, and if a CovEsts S3 object is given, a VarioEsts object is given as output.
to_vario(default): Method for numeric vectors.
to_vario(CovEsts): Method for CovEsts objects.
Bilchouris, A. & Olenko, A (2025). On Nonparametric Estimation of Covariogram. Austrian Statistical Society 54(1), 112-137. 10.17713/ajs.v54i1.1975
X <- c(1, 2, 3) estCov <- standard_est(X, meanX=mean(X), maxLag = 2, pd=FALSE) to_vario(estCov)X <- c(1, 2, 3) estCov <- standard_est(X, meanX=mean(X), maxLag = 2, pd=FALSE) to_vario(estCov)
This function computes the truncated kernel regression estimator, based on the kernel regression estimator , see adjusted_est.
truncated_est( X, x, t, T1, T2, b, kernel_name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), kernel_params = c(), pd = TRUE, type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_kernel = FALSE, parallel = FALSE, ncores = parallel::detectCores() - 1, cl_export = NULL, cl = NULL )truncated_est( X, x, t, T1, T2, b, kernel_name = c("gaussian", "wave", "rational_quadratic", "bessel_j"), kernel_params = c(), pd = TRUE, type = c("autocovariance", "autocorrelation"), meanX = mean(X), custom_kernel = FALSE, parallel = FALSE, ncores = parallel::detectCores() - 1, cl_export = NULL, cl = NULL )
X |
A vector representing observed values of the time series. |
x |
A vector of lags. |
t |
The arguments at which the autocovariance function is calculated at. |
T1 |
The first truncation point, |
T2 |
The second truncation point, |
b |
Bandwidth parameter, greater than 0. |
kernel_name |
The name of the symmetric kernel (see kernel_symm_ec) function to be used. Possible values are: gaussian, wave, rational_quadratic, and bessel_j. Alternatively, a custom kernel function can be provided, see the examples. |
kernel_params |
A vector of parameters of the kernel function. See kernel_symm_ec for parameters. |
pd |
Whether a positive-definite estimate should be used. Defaults to |
type |
Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'. |
meanX |
The average value of |
custom_kernel |
If a custom kernel is to be used or not. Defaults to |
parallel |
Whether or not the computations should be done in parallel or not. Defaults to |
ncores |
The number of cores to be used in the parallel computations. Defaults to the number cores - 1 (threads if hyperthreading is available), calculated from |
cl_export |
A vector of any additional functions or variables to export for parallel computations. This may be required if |
cl |
An optional cluster object created by |
This function computes the truncated kernel regression estimator,
where is the kernel regression estimator, see adjusted_est.
Compared to adjusted_est, this function brings down the estimate to zero linearly between and .
In the case of short-range dependence, this may be beneficial as it can remove estimation artefacts at large lags.
To make this estimator positive-definite, the following procedure is used:
Take the discrete Fourier cosine transform
.
Find the smallest frequency where its associated value in the spectral domain is negative
Set all values starting at the frequency to zero.
Perform the Fourier inversion.
If is a small frequency, most of the spectrum equals zero, resulting in an inaccurate estimate of the autocovariance function, see Bilchouris and Olenko (2025).
A CovEsts S3 object (list) with the following values
acfA numeric vector containing the autocovariance/autocorrelation estimates.
lagsA numeric vector containing the lag indices used to compute the estimates on.
est_typeThe type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the type parameter.
est_usedThe estimator function used, in this case, 'truncated_est'.
Hall, P. & Patil, P. (1994). Properties of nonparametric estimators of autocovariance for stationary random fields. Probability Theory and Related Fields 99(3), 399-424. https://doi.org/10.1007/bf01199899
Hall, P., Fisher, N. I., & Hoffmann, B. (1994). On the nonparametric estimation of covariance functions. The Annals of Statistics 22(4), 2115-2134. https://doi.org/10.1214/aos/1176325774
Bilchouris, A. & Olenko, A (2025). On Nonparametric Estimation of Covariogram. Austrian Statistical Society 54(1), 112-137. https://doi.org/10.17713/ajs.v54i1.1975
X <- c(1, 2, 3, 4) truncated_est(X, 1:4, 1:3, 1, 2, 0.1, "gaussian") my_kernel <- function(x, params) { stopifnot(params[1] > 0, length(x) >= 1) return(exp(-((abs(x) / params[1])^params[2])) * (2 * params[1] * gamma(1 + 1/params[2]))) } truncated_est(X, 1:4, 1:3, 1, 2, 0.1, my_kernel, c(0.25), custom_kernel = TRUE) ## Not run: library(parallel) X <- c(1, 2, 3, 4) my_cl <- makePSOCKcluster(2) truncated_est(X, 1:4, 1:3, 1, 2, 0.1, "gaussian", parallel = TRUE, cl = my_cl) stopCluster(my_cl) ## End(Not run)X <- c(1, 2, 3, 4) truncated_est(X, 1:4, 1:3, 1, 2, 0.1, "gaussian") my_kernel <- function(x, params) { stopifnot(params[1] > 0, length(x) >= 1) return(exp(-((abs(x) / params[1])^params[2])) * (2 * params[1] * gamma(1 + 1/params[2]))) } truncated_est(X, 1:4, 1:3, 1, 2, 0.1, my_kernel, c(0.25), custom_kernel = TRUE) ## Not run: library(parallel) X <- c(1, 2, 3, 4) my_cl <- makePSOCKcluster(2) truncated_est(X, 1:4, 1:3, 1, 2, 0.1, "gaussian", parallel = TRUE, cl = my_cl) stopCluster(my_cl) ## End(Not run)
A window function in this context is a continuous nondecreasing function such that at 0 it is 0, and at 1, it is 1.
Note that window() is deprecated, please use window_ec() instead.
This computes one of the window functions listed below.
window_ec( x, name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), params = c(1) )window_ec( x, name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), params = c(1) )
x |
A vector or matrix of arguments of at least length 1. Each value must be between 0 and 1, inclusive. |
name |
The name of the window. Options are: tukey, triangular, sine, power_sine, blackman, hann_poisson, welch. |
params |
A vector of parameters for the windows. See the documentation below for the position of the parameters. |
Tukey Window. The Tukey window is defined as
The params argument is empty.
Triangular Window. The triangular window is given by
The params argument is empty.
Sine Window. The sine window is given by
The params argument is empty.
Power Sine Window. The power sine window is given by
The params argument is of the form c().
Blackman Window. The Blackman window is defined as
The params argument is of the form c().
It is recommended that to ensure that the window is nondecreasi#'ng on
Hann-Poisson Window. The Hann-Poisson window is defined as
The params argument is of the form c().
Welch Window. The Welch window is given by
The params argument is empty.
See the function call examples below.
A vector or matrix of values.
x <- c(0.2, 0.4, 0.6) window_ec(x, "tukey") window_ec(x, "triangular") window_ec(x, "sine") window_ec(x, "power_sine", c(0.7)) window_ec(x, "blackman", c(0.16)) window_ec(x, "hann_poisson", c(0.7)) window_ec(x, "welch") curve(window_ec(x, "tukey"), from = 0, to = 1) curve(window_ec(x, "triangular"), from = 0, to = 1) curve(window_ec(x, "sine"), from = 0, to = 1) curve(window_ec(x, "power_sine", c(0.7)), from = 0, to = 1) curve(window_ec(x, "blackman", c(0.16)), from = 0, to = 1) curve(window_ec(x, "hann_poisson", c(0.7)), from = 0, to = 1) curve(window_ec(x, "welch"), from = 0, to = 1)x <- c(0.2, 0.4, 0.6) window_ec(x, "tukey") window_ec(x, "triangular") window_ec(x, "sine") window_ec(x, "power_sine", c(0.7)) window_ec(x, "blackman", c(0.16)) window_ec(x, "hann_poisson", c(0.7)) window_ec(x, "welch") curve(window_ec(x, "tukey"), from = 0, to = 1) curve(window_ec(x, "triangular"), from = 0, to = 1) curve(window_ec(x, "sine"), from = 0, to = 1) curve(window_ec(x, "power_sine", c(0.7)), from = 0, to = 1) curve(window_ec(x, "blackman", c(0.16)), from = 0, to = 1) curve(window_ec(x, "hann_poisson", c(0.7)), from = 0, to = 1) curve(window_ec(x, "welch"), from = 0, to = 1)
A symmetric window function in this context are traditional window functions, unlike the window functions.
Note that window_symm() is deprecated, please use window_symm_ec() instead.
This computes one of the symmetric window functions listed below, all of which are defined for and are 0 otherwise.
window_symm_ec( x, name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), params = c(1) )window_symm_ec( x, name = c("tukey", "triangular", "sine", "power_sine", "blackman", "hann_poisson", "welch"), params = c(1) )
x |
A vector or matrix of arguments of at least length 1. Each value must be between 0 and 1, inclusive. |
name |
The name of the window. Options are: tukey, triangular, sine, power_sine, blackman, hann_poisson, welch. |
params |
A vector of parameters for the windows. See the documentation below for the position of the parameters. |
Tukey Window. The Tukey window is defined as
The params argument is empty, see the example.
Triangular Window. The triangular window is given by
The params argument is empty, see the example.
Sine Window. The sine window is given by
The params argument is empty, see the example.
Power Sine Window. The power sine window is given by
The params argument is of the form c()
Blackman Window. The Blackman window is defined as
The params argument is of the form c().
The standard value of for this window is
Hann-Poisson Window. The Hann-Poisson window is defined as
The params argument is of the form c()
Welch Window. The Welch window is given by
The params argument is empty, see the example.
A vector or matrix of values.
x <- c(-0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6) window_symm_ec(x, "tukey") window_symm_ec(x, "triangular") window_symm_ec(x, "sine") window_symm_ec(x, "power_sine", c(0.7)) window_symm_ec(x, "blackman", c(0.16)) window_symm_ec(x, "hann_poisson", c(0.7)) window_symm_ec(x, "welch") curve(window_symm_ec(x, "tukey"), from = -1, to = 1) curve(window_symm_ec(x, "triangular"), from = -1, to = 1) curve(window_symm_ec(x, "sine"), from = -1, to = 1) curve(window_symm_ec(x, "power_sine", c(0.7)), from = -1, to = 1) curve(window_symm_ec(x, "blackman", c(0.16)), from = -1, to = 1) curve(window_symm_ec(x, "hann_poisson", c(0.7)), from = -1, to = 1) curve(window_symm_ec(x, "welch"), from = -1, to = 1)x <- c(-0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6) window_symm_ec(x, "tukey") window_symm_ec(x, "triangular") window_symm_ec(x, "sine") window_symm_ec(x, "power_sine", c(0.7)) window_symm_ec(x, "blackman", c(0.16)) window_symm_ec(x, "hann_poisson", c(0.7)) window_symm_ec(x, "welch") curve(window_symm_ec(x, "tukey"), from = -1, to = 1) curve(window_symm_ec(x, "triangular"), from = -1, to = 1) curve(window_symm_ec(x, "sine"), from = -1, to = 1) curve(window_symm_ec(x, "power_sine", c(0.7)), from = -1, to = 1) curve(window_symm_ec(x, "blackman", c(0.16)), from = -1, to = 1) curve(window_symm_ec(x, "hann_poisson", c(0.7)), from = -1, to = 1) curve(window_symm_ec(x, "welch"), from = -1, to = 1)
MatrixThis helper function computes the matrix of pairwise values, for the kernel regression estimator,
Xij_mat(X, meanX = mean(X))Xij_mat(X, meanX = mean(X))
X |
A vector of values. |
meanX |
The average value of |
A matrix of size , where is the length of the vector X.
Hall, P. & Patil, P. (1994). Properties of nonparametric estimators of autocovariance for stationary random fields. Probability Theory and Related Fields 99(3), 399-424. https://doi.org/10.1007/bf01199899
Hall, P., Fisher, N. I., & Hoffmann, B. (1994). On the nonparametric estimation of covariance functions. The Annals of Statistics 22(4), 2115-2134. https://doi.org/10.1214/aos/1176325774
## Not run: X <- c(1, 2, 3, 4) Xij_mat(X, mean(X)) ## End(Not run)## Not run: X <- c(1, 2, 3, 4) Xij_mat(X, mean(X)) ## End(Not run)