Syntax error with tsoutliers package using Nile dataset

谁说胖子不能爱 提交于 2019-12-11 18:11:41

问题


I'm trying to locate outliers in a time series using the tsoutliers package.

I'm using the classic Nile dataset (which you can find here: https://vincentarelbundock.github.io/Rdatasets/datasets.html) and I'm unsucessfully getting the tso() function to work.

My code is:

nile.outliers <- tso(Nile,types = c("AO","LS","TC"))

However, I get this syntax error, or what I assume is a syntax error:

Error in tso0(x = y, xreg = xreg, cval = cval, delta = delta, n.start = n.start, : trying to get slot "y" from an object (class "data.frame") that is not an S4 object

If anyone can help me figure out this problem that would be amazing! Thanks!


回答1:


A quibble: that's not a syntax error (which would come from R), it's a run-time error from the tso0 function in the tsoutliers package.

But from your description of where to get the data, it looks as though you are passing in a data frame, when tso wants a "ts" object. You don't need to download the data, it's built in to R; so you remove the bad one you created, and use the built-in one:

rm(Nile)
nile.outliers <- tso(Nile,types = c("AO","LS","TC"))


来源:https://stackoverflow.com/questions/53323636/syntax-error-with-tsoutliers-package-using-nile-dataset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!