在tsoutliers

时间:2015-06-25 17:59:45

标签: r time-series

我试图让 tsoutliers 包的 tso()函数起作用,但是当 dplyr 包装已加载,我似乎无法搞清楚。有什么想法吗?

以下是前一个答案中的一些代码,只有在命名空间中未加载 dplyr 时才会起作用。

dat.change <- c(12.013995263488, 11.8460207231808, 11.2845153487846, 11.7884417180764, 
                11.6865425802022, 11.4703118125303, 11.4677576899063, 11.0227199625084, 
                11.274775836817, 11.03073498338, 10.7771805591742, 10.7383206158923, 
                10.5847230134625, 10.2479315651441, 10.4196381241735, 10.467607842288, 
                10.3682422713283, 9.7834431752935, 9.76649842404295, 9.78257968297228, 
                9.87817694914062, 9.3449034905713, 9.56400153361727, 9.78120084558148, 
                9.3445162813738, 9.36767436354887, 9.12070987223648, 9.21909859069157, 
                8.85136359917466, 8.8814423003979, 8.61830163359642, 8.44796977628488, 
                8.06957847272046, 8.37999165387824, 7.98213210294954, 8.21977468333673, 
                7.683960439316, 7.73213584532496, 7.98956476021092, 7.83036046746187, 
                7.64496198988985, 4.49693528397253, 6.3459274845112, 5.86993447552116, 
                4.58301192892403, 5.63419551523625, 6.67847511602895, 7.2005344054883, 
                5.54970477623895, 6.00011922569104, 6.882667104467, 4.74057284230894, 
                6.2140437333397, 6.18511450451019, 5.83973575417525, 6.57271194428385, 
                5.36261938326723, 5.48948831338016, 4.93968645996861, 4.52598133247377, 
                4.56372558828803, 5.74515428123725, 5.45931581984165, 5.58701112949141, 
                6.00585679276365, 5.41639695946931, 4.55361875158434, 6.23720558202826, 
                6.19433060301002, 5.82989415940829, 5.69321394985076, 5.53585871082265, 
                5.42684812413063, 5.80887522466946, 5.56660158483312, 5.7284521523444, 
                5.25425775891636, 5.4227645808924, 5.34778016248718, 5.07084809927736, 
                5.324066161355, 5.03526881241705, 5.17387528516352, 5.29864121433813, 
                5.36894461582415, 5.07436929444317, 4.80619983525015, 4.42858947882894, 
                4.33623051506001, 4.33481791951228, 4.38041031792294, 3.90012900415342, 
                4.04262777674943, 4.34383842876647, 4.36984816425014, 4.11641092254315, 
                3.83985887104645, 3.81813419810962, 3.85174630901311, 3.66434598962311, 
                3.4281724860426, 2.99726515704766, 2.96694634792395, 2.94003031547181, 
                3.20892607367132, 3.03980832743458, 2.85952185077593, 2.70595278908964, 
                2.50931109659839, 2.1912274016859)

library("tsoutliers")
dat.ts<- ts(dat.change, frequency=1)
data.ts.outliers <- tso(dat.ts)

我获得的错误是:

> data.ts.outliers <- tso(dat.ts)
Error in filter_(.data, .dots = lazyeval::lazy_dots(...)):
 argument ".data" is missing, with no default

我很确定这个问题与 dplyr 存在冲突,但我不确定如何轻松解决问题。如果我没有安装 dplyr ,那么一切都很好并且可以运行。

任何想法?

2 个答案:

答案 0 :(得分:1)

正如您所说,stats::filterdplyr::filter之间存在冲突。我通过在包stats::filter的命名空间中添加tsoutliers作为导入来修复它。

新版本的软件包尚未在CRAN上播放,与此同时,您可以从此temporary link获取来自此link和Windows二进制文件的来源。

答案 1 :(得分:1)

我编写了以下函数,在调用replaceOutliers <- function(series) { require(tsoutliers) detach("package:dplyr", unload=TRUE) o <- tso(ts(series)) print(paste("Replacing", length(o$outliers$ind), "outliers for series")) series <- o$yadj library(dplyr) return(series) } 时卸载dplyr:

R

绝对不是一个优雅的解决方案,但我不想弄乱你的 var data = {} 代码。