tvOLS {tvReg} | R Documentation |
Time-Varying Ordinary Least Squares
Description
tvOLS
estimate time-varying coefficient of univariate
linear models using the kernel smoothing OLS.
Usage
tvOLS(x, ...)
## S3 method for class 'matrix'
tvOLS(
x,
y,
z = NULL,
ez = NULL,
bw,
est = c("lc", "ll"),
tkernel = c("Triweight", "Epa", "Gaussian"),
singular.ok = TRUE,
...
)
## S3 method for class 'tvlm'
tvOLS(x, ...)
## S3 method for class 'tvar'
tvOLS(x, ...)
## S3 method for class 'tvvar'
tvOLS(x, ...)
Arguments
x |
An object used to select a method. |
... |
Other arguments passed to specific methods. |
y |
A vector with dependent variable. |
z |
A vector with the variable over which coefficients are smooth over. |
ez |
(optional) A scalar or vector with the smoothing values. If
values are not included then the vector |
bw |
A numeric vector. |
est |
The nonparametric estimation method, one of "lc" (default) for linear constant or "ll" for local linear. |
tkernel |
A character, either "Triweight" (default), "Epa" or "Gaussian" kernel function. |
singular.ok |
Logical. If FALSE, a singular model is an error. |
Value
tvOLS
returns a list containing:
coefficients |
A vector of length obs, number of observations time observations. |
fitted |
A vector of length obs with the fitted values from the estimation. |
residuals |
A vector of length obs with the residuals from the estimation. |
See Also
bw
for bandwidth selection, tvLM
and
tvAR
.
Examples
tau <- seq(1:500)/500
beta <- data.frame(beta1 = sin(2*pi*tau), beta2 = 2*tau)
X <- data.frame(X1 = rnorm(500), X2 = rchisq(500, df = 4))
error <- rt(500, df = 10)
y <- apply(X*beta, 1, sum) + error
coef.lm <- stats::lm(y~0+X1+X2, data = X)$coef
coef.tvlm <- tvOLS(x = as.matrix(X), y = y, bw = 0.1)$coefficients
plot(tau, beta[, 1], type="l", main="", ylab = expression(beta[1]), xlab = expression(tau),
ylim = range(beta[,1], coef.tvlm[, 1]))
abline(h = coef.lm[1], col = 2)
lines(tau, coef.tvlm[, 1], col = 4)
legend("topright", c(expression(beta[1]), "lm", "tvlm"), col = c(1, 2, 4), bty="n", lty = 1)