English 中文(简体)
Multivariate time series modelling in R
原标题:

I want do fit some sort of multi-variate time series model using R.

Here is a sample of my data:

   u     cci     bci     cpi     gdp    dum1 dum2 dum3    dx  
 16.50   14.00   53.00   45.70   80.63  0   0    1     6.39 
 17.45   16.00   64.00   46.30   80.90  0   0    0     6.00 
 18.40   12.00   51.00   47.30   82.40  1   0    0     6.57 
 19.35   7.00    42.00   48.40   83.38  0   1    0     5.84 
 20.30   9.00    34.00   49.50   84.38  0   0    1     6.36 
 20.72   10.00   42.00   50.60   85.17  0   0    0     5.78 
 21.14   6.00    45.00   51.90   85.60  1   0    0     5.16 
 21.56   9.00    38.00   52.60   86.14  0   1    0     5.62 
 21.98   2.00    32.00   53.50   86.23  0   0    1     4.94 
 22.78   8.00    29.00   53.80   86.24  0   0    0     6.25 

The data is quarterly, the dummy variables are for seasonality.

What I would like to do is to predict dx with reference to some of the others, while (possibly) allowing for seasonality. For argument s sake, lets say I want to use "u", "cci" and "gdp".

How would I go about doing this?

最佳回答

If you haven t done so already, have a look at the time series view on CRAN, especially the section on multivariate time series.

In finance, one traditional way of doing this is with a factor model, frequently with either a BARRA or Fama-French type model. Eric Zivot s "Modeling financial time series with S-PLUS" gives a good overview of these topics, but it isn t immediately transferable into R. Ruey Tsay s "Analysis of Financial Time Series" (available in the TSA package on CRAN) also has a nice discussion of factor models and principal component analysis in chapter 9.

R also has a number of packages that cover vector autoregression (VAR) models. In particular, I would recommend looking at Bernhard Pfaff s VAR Modelling (vars) package and the related vignette.

I strongly recommend looking at Ruey Tsay s homepage because it covers all these topics, and provides the necessary R code. In particular, look at the "Applied Multivariate Analysis", "Analysis of Financial Time Series", and "Multivariate Time Series Analysis" courses.

This is a very large subject and there are many good books that cover it, including both multivariate time series forcasting and seasonality. Here are a few more:

  1. Kleiber and Zeileis. "Applied Econometrics with R" doesn t address this specifically, but it covers the overall subject very well (see also the AER package on CRAN).
  2. Shumway and Stoffer. "Time Series Analysis and Its Applications: With R Examples" has examples of multivariate ARIMA models.
  3. Cryer. "Time Series Analysis: With Applications in R" is a classic on the subject, updated to include R code.
问题回答

In the forecast package, try:

arima(df[,1:4], order=(0,0,0), xreg=df[,6:8])

for forecasting u, cci and gdp.

To predict dx from that, try the VAR model. Here s a good tutorial (PDF).

Don t Know if this functionality was available when you first asked this question but this is easily available in base R now with the arima function; just specify your external regressors with the xreg argument within the function. Try ?arima and when you read the documentation pay special attention to the xreg argument. This has been made very easy, good luck.





相关问题
How to manage a pageview DB

I am interested in tracking my users pageviews on my site. Being that traffic is expanding very quickly, I am worried about robots, etc, and I also want to be able to use tracked data live to alter ...

Statistics Question

Suppose I conduct a survey of 10 people asking whether to rank a movie as 0 to 4 stars. Allowable answers are 0, 1, 2, 3, and 4. The mean is 2.0 stars. How do I calculate the certainty (or ...

Calculating variance with large numbers

I haven t really used variance calculation that much, and I don t know quite what to expect. Actually I m not too good with math at all. I have a an array of 1000000 random numeric values in the ...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Generating correlated numbers

Here is a fun one: I need to generate random x/y pairs that are correlated at a given value of Pearson product moment correlation coefficient, or Pearson r. You can imagine this as two arrays, array ...

Multivariate time series modelling in R

I want do fit some sort of multi-variate time series model using R. Here is a sample of my data: u cci bci cpi gdp dum1 dum2 dum3 dx 16.50 14.00 53.00 45.70 80....

热门标签