[R] CCF and Lag questions
Kjetil Brinchmann Halvorsen
kjetilbrinchmannhalvorsen at gmail.com
Thu Mar 2 20:09:05 CET 2006
Pallavi Naresh wrote:
> I am new to R and new to time series modeling.
>
> I have a set of variables (var1, var2, var3, var4, var5) for which I have
> historical yearly data.
> I am trying to use this data to produce a prediction of var1, 3 years into
> the future.
>
> I have a few basic questions:
>
> 1) I am able to read in my data, and convert it to a time series format
> using 'ts.'
>
> data_ts <- ts(data, start = 1988, end = 2005, frequency = 1, deltat = 1)
>
> However, I am not able to refer to the individual columns or variables of my
> new time series object. For example, I am able to reference 'var1' by
> typing, data$var1, but I can not do the same by using data_ts$var1. I don't
> see how I can use data_ts without being able to reference the individual
> columns in my dataset.
So you have a multiple time series. Type
class(data_ts) to see.
This is a matrix, not a data.frame so you need:
data_ts[,"var1"] in place of data_ts$var1
>
> 2) Since I'm trying to build a multivariate time series model, I want to
> find the correlations of var1 with my other variables (var1, var2, ...etc.)
> and their lagged values.
>
> But since I'm trying to produce a forecast for 3 years into the future, I
> want to find the ccf between var1 and my other variables lagged 3 years. I
> tried doing:
>
> ccf(var1, lag(var2, 3))
Try
ccf( data_ts[,"var1"], data_ts[,"var2"])
>
> but I get the following error:
>
> Error in na.fail.default(ts.union(as.ts(x), as.ts(y))) :
> missing values in object
So if you have missing values in the object try:
ccf( data_ts[,"var1"], data_ts[,"var2"], na.action=na.pass)
>
> Does anyone know how to use the lag funciton and ccf together?
Is it necessary?
Kjetil
>
> 3) Suppose var1 and var2 are both of length 20.
> I would expect the correlation of the fourth lag of ccf(var1, var2) to be
> the same as lag zero of:
> ccf(var1[1:17], var2[4:20]), but they are not. Can someone explain why not?
>
>
> 4) How do I interpret the negative lags produced from the ccf function?
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list