gsmooth | R Documentation |
This function is an R function for estimating the trend function and its derivatives in an equidistant time series with local polynomial regression and a fixed bandwidth given beforehand.
gsmooth(y, v = 0, p = v + 1, mu = 1, b = 0.15, bb = c(0, 1))
y |
a numeric vector that contains the time series data ordered from past to present. | |||||||||||||||||||||||||
v |
an integer
| |||||||||||||||||||||||||
p |
an integer Exemplary for
| |||||||||||||||||||||||||
mu |
an integer
| |||||||||||||||||||||||||
b |
a real number | |||||||||||||||||||||||||
bb |
can be set to
|
The trend or its derivatives are estimated based on the additive nonparametric regression model for an equidistant time series
y_t = m(x_t) + \epsilon_t,
where y_t
is the observed time series, x_t
is the rescaled time
on the interval [0, 1]
, m(x_t)
is a smooth and deterministic
trend function and \epsilon_t
are stationary errors with
E(\epsilon_t) = 0
(see also Beran and Feng, 2002).
This function is part of the package smoots
and is used in
the field of analyzing equidistant time series data. It applies the local
polynomial regression method to the input data with an arbitrarily
selectable bandwidth. By these means, the trend as well as its derivatives
can be estimated nonparametrically, even though the result will strongly
depend on the bandwidth given beforehand as an input.
NOTE:
The estimates are obtained with regard to the rescaled time points on the
interval [0, 1]
. Thus, if \nu > 0
, the estimates might not
reflect the values for the actual time points. To rescale the estimates, we
refer the user to the rescale
function of the smoots
package.
With package version 1.1.0, this function implements C++ code by means
of the Rcpp
and
RcppArmadillo
packages for
better performance.
The output object is a list with different components:
the chosen (relative) bandwidth; input argument.
the chosen bandwidth option at the boundaries; input argument.
the chosen smoothness parameter for the second order kernel; input argument.
the number of observations.
the original input series; input argument.
the chosen order of polynomial; input argument.
a vector with the estimated residual series; is set to NULL
for v > 0
.
the order of derivative; input argument.
the weighting system matrix used within the local polynomial
regression; this matrix is a condensed version of a complete weighting system
matrix; in each row of ws
, the weights for conducting the smoothing
procedure at a specific observation time point can be found; the first
[nb + 0.5]
rows, where n
corresponds to the number of
observations, b
is the bandwidth considered for smoothing and
[.]
denotes the integer part, contain the weights at the
[nb + 0.5]
left-hand boundary points; the weights in row
[nb + 0.5] + 1
are representative for the estimation at all
interior points and the remaining rows contain the weights for the right-hand
boundary points; each row has exactly 2[nb + 0.5] + 1
elements,
more specifically the weights for observations of the nearest
2[nb + 0.5] + 1
time points; moreover, the weights are normalized,
i.e. the weights are obtained under consideration of the time points
x_t = t/n
, where t = 1, 2, ..., n
.
a vector with the estimates of the selected nonparametric order of
derivative on the rescaled time interval [0, 1]
.
Yuanhua Feng (Department of Economics, Paderborn University),
Author of the Algorithms
Website: https://wiwi.uni-paderborn.de/en/dep4/feng/
Dominik Schulz (Research Assistant) (Department of Economics, Paderborn
University),
Package Creator and Maintainer
Beran, J. and Feng, Y. (2002). Local polynomial fitting with long-memory, short-memory and antipersistent errors. Annals of the Institute of Statistical Mathematics, 54(2), 291-311.
Feng, Y., Gries, T. and Fritz, M. (2020). Data-driven local polynomial for the trend and its derivatives in economic time series. Journal of Nonparametric Statistics, 32:2, 510-533.
Feng, Y., Gries, T., Letmathe, S. and Schulz, D. (2019). The smoots package in R for semiparametric modeling of trend stationary time series. Discussion Paper. Paderborn University. Unpublished.
# Logarithm of test data
test_data <- gdpUS
y <- log(test_data$GDP)
# Applied gsmooth function for the trend with two different bandwidths
results1 <- gsmooth(y, v = 0, p = 1, mu = 1, b = 0.28, bb = 1)
results2 <- gsmooth(y, v = 0, p = 1, mu = 1, b = 0.11, bb = 1)
trend1 <- results1$ye
trend2 <- results2$ye
# Plot of the results
t <- seq(from = 1947, to = 2019.25, by = 0.25)
plot(t, y, type = "l", xlab = "Year", ylab = "log(US-GDP)", bty = "n",
lwd = 2,
main = "Estimated trend for log-quarterly US-GDP, Q1 1947 - Q2 2019")
points(t, trend1, type = "l", col = "red", lwd = 1)
points(t, trend2, type = "l", col = "blue", lwd = 1)
legend("bottomright", legend = c("Trend (b = 0.28)", "Trend (b = 0.11)"),
fill = c("red", "blue"), cex = 0.6)
title(sub = expression(italic("Figure 1")), col.sub = "gray47",
cex.sub = 0.6, adj = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.