Confidence intervals
Usage
confint_filter(
x,
coef,
coef_var = coef,
level = 0.95,
asymmetric_var = TRUE,
gaussian_distribution = FALSE,
exact_df = TRUE,
...
)Arguments
- x
input time series.
- coef
moving-average (
moving_average()) or finite filter (finite_filters()) used to filter the series.- coef_var
moving-average (
moving_average()) or finite filter (finite_filters()) used compute the variance (throwvar_estimator()). By default equal tocoef.- level
confidence level.
- asymmetric_var
if
asymmetric_var = TRUEthen the variance is estimated for each asymmetric filters instead of using the variance associated the symmetric estimates.- gaussian_distribution
if
TRUEuse the normal distribution to compute the confidence interval, otherwise use the t-distribution.- exact_df
if
TRUEcompute the exact degrees of freedom for the t-distribution (whengaussian_distribution = FALSE), otherwise uses an approximation.- ...
other arguments passed to the function
moving_average()to convertcoefto a"moving_average"object.
Details
Let \((\theta_i)_{-p\leq i \leq q}\) be a moving average of length \(p+q+1\) used to filter a time series \((y_i)_{1\leq i \leq n}\). Let denote \(\hat{\mu}_t\) the filtered series computed at time \(t\) as: $$ \hat{\mu}_t = \sum_{i=-p}^q \theta_i y_{t+i}. $$ If \(\hat{\mu}_t\) is unbiased, a approximate confidence for the true mean is: $$ \left[\hat{\mu}_t - z_{1-\alpha/2} \hat{\sigma} \sqrt{\sum_{i=-p}^q\theta_i^2}; \hat{\mu}_t + z_{1-\alpha/2} \hat{\sigma} \sqrt{\sum_{i=-p}^q\theta_i^2} \right], $$ where \(z_{1-\alpha/2}\) is the quantile \(1-\alpha/2\) of the standard normal distribution.
The estimate of the variance \(\hat{\sigma}\) is obtained using var_estimator() with the parameter coef_var.
The assumption that \(\hat{\mu}_t\) is unbiased is rarely exactly true, so variance estimates and confidence intervals are usually computed at small bandwidths where bias is small.
When coef (or coef_var) is a finite filter, the last points of the confidence interval are
computed using the corresponding asymmetric filters
Examples
x <- retailsa$DrinkingPlaces
coef <- lp_filter(6)
#> Error in .jcall("jdplus/filters/base/r/LocalPolynomialFilters", "Ljdplus/toolkit/base/core/math/linearfilters/ISymmetricFiltering;", "filters", as.integer(horizon), as.integer(degree), kernel, endpoints, d, tweight, passband): RcallMethod: cannot determine object class
confint <- confint_filter(x, coef)
#> Error in UseMethod("finite_filters", sfilter): no applicable method for 'finite_filters' applied to an object of class "function"
plot(confint, plot.type = "single",
col = c("red", "black", "black"),
lty = c(1, 2, 2))
#> Error in object$coefficients: $ operator is invalid for atomic vectors