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

前端 未结 6 1447
悲&欢浪女
悲&欢浪女 2020-12-29 17:08

I\'m have issues with stl() time series decomposition function in R telling me my ts object is not univariate when it actually is?

tsData <- ts(data = dum         


        
6条回答
  •  庸人自扰
    2020-12-29 17:27

    I had the same error and indeed, as mentioned by nrussell, the problem was that I was passing a time series that was also a matrix.

    (However, the $index thing didn't work for me and R complained that a ts object must have one or more observations. I'm fairly new at R and have no idea why this is, but for me the following approach worked)

    you can remedy this with:

    dummyVector = as.vector(t(dummyData))
    

    And then continue to get the stl:

    tsData = ts(dummyVector, start=2012, end=(2014, 12), frequency = 12)
    stl = stl(tsData, "periodic")
    

    If you use R Studio, you can see that now, your timeseries is listed under

    Time-Series [1:36] from 2012 to 2015: yourData

    whereas before, it was likely listed as

    int[1:3, 1:12] yourData

提交回复
热议问题