问题描述
我正在尝试使用 tsoutliers 包在时间序列中查找异常值.
I'm trying to locate outliers in a time series using the tsoutliers package.
我使用的是经典的 Nile 数据集(您可以在这里找到:https://vincentarelbundock.github.io/Rdatasets/datasets.html) 并且我没有成功地让 tso() 函数工作.
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.
我的代码是:
nile.outliers <- tso(Nile,types = c("AO","LS","TC"))
但是,我收到了这个语法错误,或者我认为这是一个语法错误:
However, I get this syntax error, or what I assume is a syntax error:
tso0(x = y, xreg = xreg, cval = cval, delta = delta, n.start = n.start, 中的错误:试图从不是 S4 对象的对象(类data.frame")中获取插槽y"
如果有人能帮我解决这个问题,那就太棒了!谢谢!
If anyone can help me figure out this problem that would be amazing! Thanks!
推荐答案
吹毛求疵:这不是语法错误(可能来自 R),而是来自 tso0
函数的运行时错误在 tsoutliers
包中.
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.
但是从您对从何处获取数据的描述来看,当 tso
想要一个 "ts"
对象时,您似乎正在传入一个数据框.您不需要下载数据,它内置于 R 中;所以你删除你创建的坏的,并使用内置的:
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"))
这篇关于使用 Nile 数据集的 tsoutliers 包出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!