Time series and stl in R: Error only univariate series are allowed

前端 未结 4 522
萌比男神i
萌比男神i 2021-01-04 01:03

I am doing analysis on hourly precipitation on a file that is disorganized. However, I managed to clean it up and store it in a dataframe (called CA1) which takes the form a

相关标签:
4条回答
  • 2021-01-04 01:42

    That error is a result of the shape of your data. Try > dim(rainCA1); I suspect it to give something like > [1] 135264 1. Replace rainCA1 <- ts(dat1 ... by rainCA1 <- ts(dat1[[1]] ..., and it should work.

    Whether it does so correctly, I wonder... It seems to me your first order of business is to get your data of a consistent format. Make sure ts() gets the right input. Check out the precise specification of ts.

    ts() does not interpret date-time formats. ts() requires consecutive data points with a fixed interval. It uses a major counter and a minor counter (of which frequency fit into one major counter). For instance, if your data is hourly and you expect seasonality on the daily level, frequency equals 24. start and end, therefore, are primarily cosmetic: start merely indicates t(0) for the major counter, whereas end signifies t(end).

    0 讨论(0)
  • 2021-01-04 01:48

    If you apply dim() in co2 or AirPassengers it will return NULL. Thus, I suggest you to apply dim(rainCA1)<-NULL

    It worked for me many times.

    0 讨论(0)
  • 2021-01-04 01:53

    One solution I found is time_series_var <- ts(data[, c("var_of_interest")]) and then time_series_var <- ts(as.vector(time_series_var)) and then the error related to univariate disappears as the dimensions are now correct.

    0 讨论(0)
  • 2021-01-04 02:09

    I tried to explain the write way with a very easy example to avoid these kind of errors in another question, linked here:

    stl() decomposition won't accept univariate ts object?

    0 讨论(0)
提交回复
热议问题