JElder
JElder

Reputation: 219

acf returns "'lag.max' must be at least 0" and arima returns "only implemented for univariate time series" despite properly structured timeseries data

I have a dataframe that appears as follows:

  T1       T2       T3
1 4.693798 3.339923 1.960526
2 5.108974 4.041096 3.227176
3 4.323944 3.936614 3.755302
4 4.516129 3.859621 2.921308
5 4.210526 3.716563 3.601480
6 5.143293 4.007018 3.778689

I then convert it to a timeseries data structure and verify it is timeseries data and appears correct as follows:

propTS <- t(as.matrix(propDf[2:4]))
propTS <- as.ts(propTS)
is.ts(propTS)
time(propTS)

It outputs:

      [,1]     [,2]     [,3]     [,4]     [,5]     [,6]
1 4.693798 5.108974 4.323944 4.516129 4.210526 5.143293
2 3.339923 4.041096 3.936614 3.859621 3.716563 4.007018
3 1.960526 3.227176 3.755302 2.921308 3.601480 3.778689

Looks good to me. But when I execute the below acf function, I get the error, "Error in acf(propTS, na.action = na.pass) : 'lag.max' must be at least 0":

acf(propTS, na.action=na.pass)

Similarly, when I attempt to execute the below line, I get the following error, "Error in arima(propTS, order = c(1, 0, 0)) : only implemented for univariate time series":

AR <- arima(propTS, order = c(1,0,0))

I have checked online examples and my data structure appears to be like other time series data that people use as inputs for this function. I have attempted various other solutions for troubleshooting but have not encountered a solution thus far. Can anyone identify what may be wrong with my input and why it is interpreting it as not univariate? It appears univariate to me. I have a column for each individual and three timepoints for the data. Seems univariate.

Notably, this error persists even when generating a 10x50 matrix of random numbers and then proceeding through the same procedure as above by converting to a timeseries.

propTS<-matrix(rnorm(100),nrow=10,ncol=50)

Upvotes: 0

Views: 587

Answers (1)

Mariano Stone
Mariano Stone

Reputation: 176

The error might ocurr when using transpose function t() I´m not sure why are you doing that, but I think you have your own reasons.

propTS <- ts(as.matrix(df))
acf(propTS, na.action = na.pass)

The second error ocurrs because arima() only supports univariate time series, that is only one variable, in this case you have 3. You can do this (if this is what you want).

TS1 <- ts(df$T1)
TS2 <- ts(df$T2)
TS3 <- ts(df$T3)

arima(TS1, order = c(1,0,0))
arima(TS2, order = c(1,0,0))
arima(TS2, order = c(1,0,0))

The acf plots look like this:

Acf plots

Upvotes: 1

Related Questions