Estimation of Nonparametric Trend Functions via Kernel Regression
Estimation of Nonparametric Trend Functions via Kernel Regression
This function estimates the nonparametric trend function in an equidistant time series with Nadaraya-Watson kernel regression.
knsmooth(y, mu =1, b =0.15, bb = c(0,1))
Arguments
y: a numeric vector that contains the time series data ordered from past to present.
mu: an integer 0, 1, 2, ... that represents the smoothness parameter of the second order kernel function that will be used; is set to 1 by default.
Number (‘mu’)
Kernel
0
Uniform Kernel
1
Epanechnikov Kernel
2
Bisquare Kernel
3
Triweight Kernel
...
...
b: a real number 0<b<0.5; represents the relative bandwidth that will be used for the smoothing process; is set to 0.15 by default.
bb: can be set to 0 or 1; the parameter controlling the bandwidth used at the boundary; is set to 0 by default.
Number (‘bb’)
Estimation procedure at boundary points
0
Fixed bandwidth on one side with possible large bandwidth on the other side at the boundary
1
The k-nearest neighbor method will be used
Returns
The output object is a list with different components:
b: the chosen (relative) bandwidth; input argument.
bb: the chosen bandwidth option at the boundaries; input argument.
mu: the chosen smoothness parameter for the second order kernel; input argument.
n: the number of observations.
orig: the original input series; input argument.
res: a vector with the estimated residual series.
ye: a vector with the estimates of the nonparametric trend.
Details
The trend is estimated based on the additive nonparametric regression model for an equidistant time series
yt=m(xt)+ϵt,
where yt is the observed time series, xt is the rescaled time on the interval [0,1], m(xt) is a smooth and deterministic trend function and ϵt are stationary errors with E(ϵt)=0.
This function is part of the package smoots and is used for the estimation of trends in equidistant time series. The applied method is a kernel regression with arbitrarily selectable second order kernel, relative bandwidth and boundary method. Especially the chosen bandwidth has a strong impact on the final result and has thus to be selected carefully. This approach is not recommended by the authors of this package.
Examples
# Logarithm of test datatest_data <- gdpUS
y <- log(test_data$GDP)#Applied knmooth function for the trend with two different bandwidthstrend1 <- knsmooth(y, mu =1, b =0.28, bb =1)$ye
trend2 <- knsmooth(y, mu =1, b =0.05, bb =1)$ye
# Plot of the resultst <- 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.05)"), fill = c("red","blue"), cex =0.6)title(sub = expression(italic("Figure 1")), col.sub ="gray47", cex.sub =0.6, adj =0)
References
Feng, Y. (2009). Kernel and Locally Weighted Regression. Verlag für Wissenschaft und Forschung, Berlin.
Author(s)
Yuanhua Feng (Department of Economics, Paderborn University),