twitter / AnomalyDetection

Anomaly Detection with R
GNU General Public License v3.0
3.55k stars 776 forks source link

Encounter Error when do anomaly detection on a constant series #36

Open alvinyr opened 9 years ago

alvinyr commented 9 years ago

hi, when I try anomaly detection on a constant series, there is an error. I know it's impossible to find out anomaly from that kind of data. I just think it's better to tell "there is no anomaly" than throw out error.

test <- rep(1,1000) AnomalyDetectionVec(test, period=14, plot=T, direction='both') Error in if (R > lam) num_anoms <- i : missing value where TRUE/FALSE needed

erikriverson commented 9 years ago

R is likely NaN in this case, so could check R's value with is.nan() before the comparison is made.

owenvallis commented 9 years ago

Thanks, for pointing out the issue and the suggestion for a fix. Adding the check for the nan actually kicked the error up to the max(ares) line. I setup a check for sigma equalling 0, and we now break out of the ESD loop if that is the case.