[R] Discover significant change in sorted vector
Charles Annis, P.E.
Charles.Annis at StatisticalEngineering.com
Wed Apr 22 14:57:37 CEST 2009
Please excuse my nit-picking: In physicists the third and fourth derivative
of position are jerk (or jolt) and jounce, respectively. Impulse is the
integral of force with respect to time.
Charles Annis, P.E.
Charles.Annis at StatisticalEngineering.com
phone: 561-352-9699
eFax: 614-455-3265
http://www.StatisticalEngineering.com
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of David Winsemius
Sent: Wednesday, April 22, 2009 8:47 AM
To: Hans-Henning Gabriel
Cc: r-help at r-project.org
Subject: Re: [R] Discover significant change in sorted vector
On Apr 22, 2009, at 8:06 AM, Hans-Henning Gabriel wrote:
>> Hans-Henning Gabriel wrote:
>>> Hi,
>>>
>>> suppose I have a simple sorted vector like this:
>>>
>>> a <- c(2,3,3,5,6,8,8,9,15, 25, 34,36,36,38,41,43,44,44,46);
>>>
>>> Is there a function in R, I can use to discover that from index 8
>>> to index 11 the values are changing significantly?
>>> The function should return a value pointing to one of the indices
>>> 8, 9, 10 or 11. Any of them would be fine.
>>> The difficulty is that there may be no big gap. I mean, indices 8
>>> and 11 are somehow "connected" by indices 9 and 10. So, it's not
>>> an option to just search for biggest difference between the values.
>>>
>>> Perfect would be a function that is able to discover multiple
>>> changes if it is present in the data.
>>>
>> Hi Henning,
>> Is max(diff(a)) any good to you?
>>
>> Jim
>>
>
> Hi Jim,
>
> no, I'm affraid it's not. It's more like that the slope is low for
> many values, then it starts getting stronger for few values, then it
> gets low again for many values. But the thing is that the slope may
> _not_ change immediately.
>
Well <something> needs to change immediately. Think of this as
position, speed and acceleration, i.e. speed is the first derivative
of position and acceleration is the second derivative. (In physics the
third derivative is sometimes called impulse, the thing that changes
when acceleration goes from zero to some positive value.) If first
differences is not what you want, then look at second differences as
below:
> x <- c(2,3,3,5,6,8,8,9,15, 25, 34,36,36,38,41,43,44,44,46);
> max(diff(diff(x)))
[1] 5
> diff(diff(x))
[1] -1 2 -1 1 -2 1 5 4 -1 -7 -2 2 1 -1 -1 -1 2
> which(diff(diff(x))==max(diff(diff(x))))
[1] 7
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list