TSO function problem in tsoutliers
I'm trying to get the function tso () package tsoutliers , but I continue to work with the same error the maddening, when dplyr loaded package that I can not understand. Any ideas?
Here's some code from the previous answer that seemed to only work when dplyr is not loaded into the namespace.
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)
ERROR I am getting:
> data.ts.outliers <- tso(dat.ts)
Error in filter_(.data, .dots = lazyeval::lazy_dots(...)):
argument ".data" is missing, with no default
I'm pretty sure the problem is with a conflict with dplyr , but I'm not sure how to easily get around it. If I don't install dplyr everything will be smooth and running.
Any ideas?
As you say, there is a conflict between stats::filter
and dplyr::filter
. I fixed it by adding stats::filter
as an import in the package namespace tsoutliers
.
The new version of the package is not yet included in CRAN, in the meantime you can get sources from this temporary link and Windows binaries from this link.
source to share
I wrote the following function that dumps dplyr when called tso()
:
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)
}
Absolutely not an elegant solution, but I didn't want to step into the R
tsoutliers code .
source to share