Fit a continuous AR model to an irregularly sampled univariate time series with the Kalman filter
car(x, y=NULL, scale = 1.5, order = 3, ctrl=car_control())
# S3 method for car
print(x, digits = 3, ...)
# S3 method for car
summary(object, ...)
# S3 method for car
plot(x, type=c("spec", "pred", "diag"),...)
# S3 method for car
predict(object, se.fit = TRUE, digits = 3, plot.it=TRUE,...)
# S3 method for car
spectrum(object, frmult=1, n.freq, plot.it = TRUE, na.action = na.fail, ...)
# S3 method for car
AIC(object, ..., k=NULL)
# S3 method for car
tsdiag(object, gof.lag = 10, ...)
# S3 method for car
kalsmo(object)
two column data frame or matrix with the first column
being the sampled time and the second column being the observations at
the first column; otherwise x
is a numeric vector of sampled time. It can be a car
object for S3 methods
not used if x
has two columns; otherwise y
is a numeric vector of observations at sampled time x
.
The kappa value referred to in the paper by Belcher et a. (1994). We now recommend selection of kappa along with the model order by using AIC. Also, it is suggested to choose kappa close to 2pi times 1/mean.delta (reciprocal of the mean time between observations), though it is a good idea to explore somewhat lower and higher values to see whether the spectrum estimates were sensitive to this choice. Choosing kappa lower increases the risk of trying to estimate the spectrum beyond the effective Nyquist frequency of the data - though this does depend on the distribution of intersample times.
order of autoregression.
control parameters used in predict and numerical optimization.
object of class car
in plot
a character indicating the type of plot. type="spec", call spec
;
type="pred", call predict
;
type="diag", call diag
Logical: should standard errors of prediction be returned?
return value digits
Logical: plot the forecast values?
the maximum number of lags for a Portmanteau goodness-of-fit test
numerical value, can be used to multiply the frequency range
number of frequency
penalty, not used
NA
action function.
further arguments to be passed to particular methods
A list of class "car"
with the following elements:
The number of observations used in fitting
The order of the fitted model. This is chosen by the user.
The number of parameters estimated. This may include the mean and the observation noise ratio.
The kappa value referred to in the paper of Belcher et al.
If vri=1, estimate the observation noise ratio.
The estimated observation noise ratio.
The estimated innovation variance.
The estimated reparameterized autoregressive parameters.
The estimated mean of the series used in fitting and for use in prediction.
All estimated parameters, which include phi
, and possibly x.mean
and vr
.
The estimated standard error of b
The estimated correlation matrix of b
The estimated covariance matrix of phi
. See also
AIC
The real part of roots of phi
. See also AIC
The imaginary part of roots of phi
. See also
AIC
The numeric vector of sampled time.
The numeric vector of observations at sampled time
tim
.
The filtered time series with the Kalman filter.
The estimated variance of Kalman filtered time series
filser
The smoothed time series with the Kalman smoother.
The estimated variance of smoothed time series
sser
The standardized residuals from the fitted model.
Time of predictions.
Predictions for the pretime
.
Prediction variance of pred
Fitted values including pred
for all the time series. See also fty
.
Variance of fitted values including prv
for all the time series. See also fty
.
Forecast type
Numeric vector: iteration
Numeric vector: sum of squares for each tnit
Matrix with rows for tnit
and columns for parameter estimates
AIC value for the fitted model
BIC value for the fitted model
spectrum
returns (and by default plots) the spectral density of the fitted model.
tsdiag
is a generic diagnostic function for continuous AR model. It will generally plot the residuals,
often standadized, the autocorrelation function of the residuals, and
the p-values of a Portmanteau test for all lags up to gof.lag
.
The method for car
object plots residuals scaled by the estimate of their (individual) variance, and use the Ljung--Box version of the portmanteau test.
AIC
For continuous CAR model selection, t-statistic and AIC are calculated
based on reparameterized coefficients phi
and covariance matrix
ecov
. From the t-statistic, the final model is chosen such that
if the true model order
is less than the large value used for
model estimation then for i > order
the deviations of the
estimated parameters phi
from their true value of 0 will be
small. From the AIC, the final model is chosen based on the smallest AIC
value. A table with t-statistic and AIC for the corresponding model order.
factab
calculate characteristic roots and system frequency from the estimated
reparameterized coefficients of CAR fits.
smooth
computes components corresponding to the diagonal transition matrix with the Kalman smoother. This may not be stable for some data due to numerical inversion of matrix.
Belcher, J. and Hampton, J. S. and Tunnicliffe Wilson, G. (1994). Parameterization of continuous time autoregressive models for irregularly sampled time series data. Journal of the Royal Statistical Society, Series B, Methodological,56,141--155
Jones, Richard H. (1981). Fitting a continuous time autoregression to discrete data. Applied Time Series Analysis II, 651--682
Wang, Zhu (2004). The Application of the Kalman Filter to Nonstationary Time Series through Time Deformation. PhD thesis, Southern Methodist University
Wang, Zhu and Woodward, W. A. and Gray, H. L. (2009). The Application of the Kalman Filter to Nonstationary Time Series through Time Deformation. Journal of Time Series Analysis, 30(5), 559-574.
Wang, Zhu (2013). cts: An R Package for Continuous Time Autoregressive Models via Kalman Filter. Journal of Statistical Software, Vol. 53(5), 1--19. http://www.jstatsoft.org/v53/i05
car_control
for predict and numerical optimization parameters, and AIC
for model selection
# NOT RUN {
data(V22174)
fit <- car(V22174,scale=0.2,order=7, ctrl=car_control(trace=TRUE))
summary(fit)
spectrum(fit)
tsdiag(fit)
AIC(fit)
factab(fit)
###fitted values vs observed values
ntim <- dim(V22174)[1]
plot(V22174[,1], V22174[,2], type="l")
points(V22174[,1], fit$pre2[1:ntim], col="red")
### alternatively
fit2 <- car(V22174,scale=0.2,order=7, ctrl=car_control(fty=3))
plot(V22174[,1], V22174[,2], type="l")
points(V22174[,1], fit2$pre2, col="red")
data(asth)
fit <- car(asth,scale=0.25,order=4, ctrl=car_control(n.ahead=10))
kalsmo(fit)
# }
Run the code above in your browser using DataCamp Workspace