I've tried doing burst detection with the bursts package. I'm doing this because I want to find spikes in a time series.
When I do kleinberg(ts)
it says:
Error in kleinberg(ts) :
Input cannot contain events with zero time between!
The time series is:
Time Series:
Start = 1
End = 120
Frequency = 1
[1] 5 5 5 5 5 14 4 8 11 11 11 4 7 3 10 7 13 6 3 3 6 9 9 12 6 6 9 3 9
[30] 6 12 3 3 3 6 9 6 3 3 4 6 6 6 3 6 7 9 9 6 6 15 9 21 9 9 9 9 12
[59] 6 12 3 3 17 9 9 9 9 12 3 12 3 3 13 13 3 7 6 6 6 9 10 3 7 6 16 3 9
[88] 9 9 17 12 9 9 19 20 13 13 16 17 11 14 20 15 14 100 70 20 15 26 44 20 19 8 38 14 15
[117] 11 6 19 21
The output of dput(ts)
for one particular time series I'm interested in is
structure(c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 2L, 4L, 9L, 100L,
78L, 21L, 13L, 15L, 12L, 11L, 9L, 9L, 7L, 8L, 5L, 6L, 6L, 6L,
6L, 4L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 2L, 3L, 3L), .Tsp = c(1,
120, 1), class = "ts")
It seems like kleinberg
needs the subsequent values to change, see the function code. In your time series there are cases where you have a series of the same numbers.
When I tried using kleinberg(unique(ts))
, it worked fine.
Also, using a randomly generated time series, kleinberg()
worked fine:
ts2 <- as.ts(rnorm(1000,mean=1,sd=10))
plot(ts2)
burst <- kleinberg(ts2)
plot(burst)
It's possible that kleinberg
in the default form might not give you what you need but you might find Twitter's AnomalyDetection package useful.