Create intervals

rstudio

#1

I want to compare previous data points in my plot (see image).The red dots are my data points, the black vertical lines are intervals. Now I want my algorithm to have a "mind" and also compare the previous data points to create improved intervals (blue lines) which start at the beginning of the deviation and end afterwards.

I was imagining doing so by using a for loop (going through all the points) and/or with an if-else statement (comparing the points) and trying to keep it general, so other data points can be used. I was thinking of using maybe the standard deviation or sth similar. I honestly dont know how to compare all the points and then set the intervals. Below is my desired output. It would be really great if I could get some help/advice on this.

Unbenannt


#2

The key words are "trying to keep it general". This makes the problem closer to machine learning, e.g. either anomaly detection or clustering or supervised learning. Providing more information, e.g. a graph with 100+ points might help narrowing the recommendation.


#3

Thanks for your answer Mike. Unfortunately, I only have this dataset and only these few datapoints.


#4

With this few data points I believe that your system (where you select the intervals manually) is as good as any other method (and it is faster since it is already implemented). One might create some sort of a rule, but, due to limited data, it will overfit the noise in this particular data set instead of being able to generalize.