Title: | Functions for Smoothing with Infinite Order Flat-Top Kernels |
---|---|
Description: | Density, spectral density, and regression estimation using infinite order flat-top kernels. |
Authors: | Timothy L. McMurry, Dimitris N. Politis |
Maintainer: | Timothy L. McMurry <[email protected]> |
License: | GPL |
Version: | 0.94 |
Built: | 2024-12-16 06:33:54 UTC |
Source: | CRAN |
Generic function for adaptive bandwidth choice.
bwadap(x, ...)
bwadap(x, ...)
x |
If |
... |
Further arguments passed to the methods. |
Timothy L. McMurry
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
Adaptive bandwidth choice for infinite order flat-top kernel density estimates.
## S3 method for class 'numeric' bwadap(x, smax = 13.49/IQR(x), n.points = 1000, Kn = 1.349 * 5/IQR(x), c.thresh = 2, ...)
## S3 method for class 'numeric' bwadap(x, smax = 13.49/IQR(x), n.points = 1000, Kn = 1.349 * 5/IQR(x), c.thresh = 2, ...)
x |
A univariate data set. |
smax |
The algorithm searches for smoothing parameters on the interval |
n.points |
The number of points in |
Kn |
Tuning parameter |
c.thresh |
The bandwidth is chosen by looking for the first time the sample characteristic function drops below |
... |
Currently unimplemented. |
Returns a bandwidth, h
, for use with infinite order flat-top kernel density estimates. All frequencies higher than 1/h
are downweighted by the kernel. All kernels in this package are scaled to use roughly the same bandwidth. We recommend using this algorithm in conjunction with bwplot.numeric
to double check the automated selection.
Returns the estimated kernel bandwidth h.
Timothy L. McMurry
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
bwadap
, bwadap.ts
, bwplot.numeric
, bwplot
x <- rnorm(100) bwplot(x) h <- bwadap(x) plot(iodensity(x, h, kernel="Trap"), type="l") rug(x) # Add the truth in red xs <- seq(-3, 3, len=1000) lines(xs, dnorm(xs), col="red")
x <- rnorm(100) bwplot(x) h <- bwadap(x) plot(iodensity(x, h, kernel="Trap"), type="l") rug(x) # Add the truth in red xs <- seq(-3, 3, len=1000) lines(xs, dnorm(xs), col="red")
Adaptive bandwidth choice for spectral density estimation with infinite order flat-top kernels.
## S3 method for class 'ts' bwadap(x, Kn = 5, c.thresh = 2, ...)
## S3 method for class 'ts' bwadap(x, Kn = 5, c.thresh = 2, ...)
x |
A univariate time-series. |
Kn |
Tuning parameter Kn discussed in Politis (2003). Roughly, the number of lags the autocorrelation function must stay below the threshold determined by |
c.thresh |
The bandwidth is chosen by looking for the first time the autocorrelation function drops below |
... |
Currently unimplemented. |
Returns a smoothing parameter l
; all lags after lag l
will be down-weighted by the kernel's taper. All kernels in this package are scaled to use roughly the same smoothing parameter.
Smoothing parameter l
.
Timothy L. McMurry
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
bwadap
, bwadap
, bwplot
, bwplot.ts
x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) l <- bwadap(x) plot(iospecden(x, l), type="l")
x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) l <- bwadap(x) plot(iospecden(x, l), type="l")
Generic function plotting either the absolute autocorrelation or characteristic function along with the threshold used for bandwidth choice.
bwplot(x, ...)
bwplot(x, ...)
x |
If |
... |
Further arguments passed to the methods. |
Timothy L. McMurry
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
bwadap
, bwplot.numeric
, bwplot.ts
Plots the magnitude of the empirical characteristic function at frequencies 0 to smax
.
## S3 method for class 'numeric' bwplot(x, y, smax = 13.49/IQR(x), normalize = FALSE, n.points = 1000, c.thresh = 2, ...)
## S3 method for class 'numeric' bwplot(x, y, smax = 13.49/IQR(x), normalize = FALSE, n.points = 1000, c.thresh = 2, ...)
x |
A univariate data set. |
y |
A vector of responses, for regression only. |
smax |
The algorithm searches for smoothing parameters on the interval |
normalize |
Rescale the sample characteristic function so that it is 1 at frequency 0. Does not affect plots for density estimation. For regression it is often better to leave this as |
n.points |
The number of points in |
c.thresh |
For regression, this is not meaningful. For density estimation, the bandwidth is chosen by looking for the first time the sample characteristic function drops below |
... |
Currently unimplemented. |
Produces a plot that is helpful in choosing the bandwidth for infinite order flat-top kernel smoothers. Roughly, the bandwidth should be chosen to let the large low frequency component pass unpreturbed while damping out smaller high frequency components. This can be accomplished by choosing h = 1/l
where l
is a frequency threshold above which the sample characteristic function is negligible. For regression, this is done heuristically. For density estimation there is a formal recommendation, implemented in bwplot.numeric
.
Timothy L. McMurry
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
McMurry, T. L. and Politis, D. N. Minimally biased nonparametric regression and autoregression. RevStat - Statistical Journal, 6(2):123-150, 2008
bwadap
, bwadap.ts
, bwplot.numeric
, bwplot
### Density Estimation set.seed(123) x <- rnorm(100) bwplot(x, smax=8) #Choose bandwidth roughly h=1/2 plot(iodensity(x, bw=1/2), type="l") rug(x) #### Nadaraya-Watson kernel regression y <- sin(x) + .1 *rnorm(100) bwplot(x,y, smax=12) # Choose bandwidth roughly h = 1/2.5 plot(x, y) lines(ioksmooth(x, y, bw = 1/2.5, kernel="SupSm"), type="l")
### Density Estimation set.seed(123) x <- rnorm(100) bwplot(x, smax=8) #Choose bandwidth roughly h=1/2 plot(iodensity(x, bw=1/2), type="l") rug(x) #### Nadaraya-Watson kernel regression y <- sin(x) + .1 *rnorm(100) bwplot(x,y, smax=12) # Choose bandwidth roughly h = 1/2.5 plot(x, y) lines(ioksmooth(x, y, bw = 1/2.5, kernel="SupSm"), type="l")
Plots the absolute autocorrelation function at lags 0 to lag.max
.
## S3 method for class 'ts' bwplot(x, lag.max = NULL, c.thresh = 2, ...)
## S3 method for class 'ts' bwplot(x, lag.max = NULL, c.thresh = 2, ...)
x |
A univariate time series. |
lag.max |
The maximum lag shown on the plot. |
c.thresh |
The smoothing parameter is chosen by looking for the first time the sample autocorrelation function drops below |
... |
Further arguments passed on to |
Produces a plot that is helpful in choosing the bandwidth for infinite order flat-top spectral density estimates. The smoothing parameter should be chosen to let the large small lag autocorrelations pass unpreturbed while damping out smaller higher lag correlations.
Timothy L. McMurry
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
bwadap
, bwadap.ts
, bwplot
, bwplot.numeric
set.seed(123) x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) bwadap(x) # Choose a smoothing parameter of 3 plot(iospecden(x, l=3), type="l")
set.seed(123) x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) bwadap(x) # Choose a smoothing parameter of 3 plot(iospecden(x, l=3), type="l")
Calculates the standard kernel density estimate using infinite order flat-top kernels. These estimators have been shown to automatically achieve optimal rates of covergence across a wide range of scenarios.
iodensity(x, bw, kernel = c("Trap", "Rect", "SupSm"), n.points = 100, x.points)
iodensity(x, bw, kernel = c("Trap", "Rect", "SupSm"), n.points = 100, x.points)
x |
Univariate data |
bw |
|
kernel |
Three flat-top kernels are implemented, described by the shape of their Fourier transforms. "Trap" is trapezoid shaped and is the default. The rectangular kernel is not recommended and is here for comparison only. SupSm is infinitely differentiable in the Fourier domain; its inverse Fourier transform is estimated numerically, and will be slower. |
n.points |
The number of points at which the density estimate will be calculated if |
x.points |
The points at which the density should be calculated. If missing, the function defaults to the range of |
A list of length 2
x |
The x values at which the density is estimated ( |
y |
The estimated density at the associated |
Timothy L. McMurry
Politis, D. N. (2001). On nonparametric function estimation with infinite-order flat-top kernels, in Probability and Statistical Models with applications, Ch. Charalambides et al. (Eds.), Chapman and Hall/CRC, Boca Raton, 469-483.
McMurry, T. L., & Politis, D. N. (2004). Nonparametric regression with infinite order flat-top kernels. Journal of Nonparametric Statistics, 16(3-4), 549-562.
x <- rnorm(100) bwplot(x) h <- bwadap(x) plot(iodensity(x, bw=h, kernel="Trap", n.points=300), type="l") rug(x)
x <- rnorm(100) bwplot(x) h <- bwadap(x) plot(iodensity(x, bw=h, kernel="Trap", n.points=300), type="l") rug(x)
Calculates the Nadaraya-Watson nonparametric kernel regression estimator using infinite order flat-top kernels. These estimators have been shown to automatically achieve optimal rates of covergence across a wide range of scenarios.
ioksmooth(x, y, bw = 0.1, kernel = c("Trap", "Rect", "SupSm"), n.points = 100, x.points)
ioksmooth(x, y, bw = 0.1, kernel = c("Trap", "Rect", "SupSm"), n.points = 100, x.points)
x |
Predictor variable |
y |
Response variable |
bw |
The kernel bandwidth. Can be chosen with the help of |
kernel |
Three flat-top kernels are implemented, described by the shape of their Fourier transforms. "Trap" is trapezoid shaped and is the default. The rectangular kernel is not recommended and is here for comparison only. SuperSmooth is infinitely differentiable in the Fourier domain, which, in theory, minimizes edge effects in the interior of the domain. It is calculated numerically, and will be slower. |
n.points |
The number of points at which the density estimate will be calculated if |
x.points |
The points at which the density should be calculated. If missing, the function defaults to the range of |
A list of length 2
x |
The |
y |
The estimated regression function at the associated x values. |
The regressions can be unstable in regions where the design density is low. For regression, bwplot
can be used to visually select the large low frequency component, but it is not amenable to algorithmic bandwidth choice.
Timothy L. McMurry
McMurry, T. L., & Politis, D. N. (2004). Nonparametric regression with infinite order flat-top kernels. Journal of Nonparametric Statistics, 16(3-4), 549-562.
McMurry, T. L., & Politis, D. N. (2008). Minimally biased nonparametric regression and autoregression. REVSTAT-Statistical Journal, 6(2), 123-150.
set.seed(123) x <- sort(runif(200, 0, 2*pi)) # Regression function r <- exp(-x^2) + sin(x) # Observed response y <- r + 0.3*rnorm(200) bwplot(x, y, smax=10) # Choose bandwidth about 1/2 plot(x, y) lines(ioksmooth(x, y, bw=1/2, kernel="Trap")) # Add the truth in red lines(x, r, col="red")
set.seed(123) x <- sort(runif(200, 0, 2*pi)) # Regression function r <- exp(-x^2) + sin(x) # Observed response y <- r + 0.3*rnorm(200) bwplot(x, y, smax=10) # Choose bandwidth about 1/2 plot(x, y) lines(ioksmooth(x, y, bw=1/2, kernel="Trap")) # Add the truth in red lines(x, r, col="red")
Calculates a spectral density estimator using infinite order flat-top kernels. These estimators have been shown to automatically achieve optimal rates of covergence across a wide range of scenarios.
iospecden(x, l, kernel = c("Trap", "Rect", "SupSm"), x.points = seq(-pi, pi, len = 200))
iospecden(x, l, kernel = c("Trap", "Rect", "SupSm"), x.points = seq(-pi, pi, len = 200))
x |
A univariate time series. |
l |
The smoothing parameter. If missing, adaptive bandwidth choice is used via |
kernel |
Three flat-top kernels are implemented, described by the shape of their Fourier transforms. "Trap" is trapezoid shaped and is the default. The rectangular kernel is not recommended and is here for comparison only. SupSm is infinitely differentiable in the Fourier domain. |
x.points |
Points at which the spectral density is estimated. If |
If x.points
is not NULL, the function returns a list of length 2
x |
The |
y |
The estimated spectral density function at the associated |
If x.points
is NULL, the function returns the estimated spectral density function rather than its values.
Timothy L. McMurry
Politis, D. N., & Romano, J. P. (1995). Bias-corrected nonparametric spectral estimation. Journal of Time Series Analysis, 16(1), 67-103.
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) plot(iospecden(x), type="l")
x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) plot(iospecden(x), type="l")
Calculates a spectral density estimator using Parzen's piecewise cubic lag window, with plug-in bandwidth chosen using an infinite order pilot.
sospecden(x, l, kernel = c("Trap", "Rect", "SupSm"), x.points = seq(-pi, pi, len = 200))
sospecden(x, l, kernel = c("Trap", "Rect", "SupSm"), x.points = seq(-pi, pi, len = 200))
x |
A univariate time series. |
l |
The smoothing parameter used for the infinite order pilot estimate. If missing, adaptive bandwidth choice is used via |
kernel |
The flat-top kernel used for the pilot estimate. Three kernels are implemented, described by the shape of their Fourier transforms. "Trap" is trapezoid shaped and is the default. The rectangular kernel is not recommended and is here for comparison only. SupSm is infinitely differentiable in the Fourier domain. |
x.points |
Points at which the spectral density is estimated. If |
If x.points
is not NULL, the function returns a list of length 2
x |
The |
y |
The estimated spectral density function at the associated |
If x.points
is NULL, the function returns the estimated spectral density function rather than its values.
Timothy L. McMurry
Politis, D. N., & Romano, J. P. (1995). Bias-corrected nonparametric spectral estimation . Journal of Time Series Analysis, 16(1), 67-103.
Politis, D. N. (2003). Adaptive bandwidth choice. Journal of Nonparametric Statistics, 15(4-5), 517-533.
x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) plot(sospecden(x), type="l")
x <- arima.sim(list(ar=.7, ma=-.3), 100) bwplot(x) plot(sospecden(x), type="l")