Learn R Programming

pvar (version 1.0.6)

SplitByExtremum: Split vector according extremum (minimum and maximum).

Description

Splits vectors in quasi-monotonic parts.

Usage

SplitByExtremum(x)
Split_MinMax(x)
Split_MinMax_req(x, add = 1)

Arguments

x
a numeric vector.
add
the inner parameter for accounting in recursion.

Value

  • The index of the points where vector might be spitted.

Details

According to the properties of p-variation, the minimum and maximum are the points where vector might be spitted into separate subsets and analysed independent of each other. These functions does that. Only the function SplitByExtremum are now used in the program. The functions Split_MinMax_req and Split_MinMax are older versions. They work fine, but function Split_MinMax_req uses recursion, therefor it has some limitations. Functions Split_MinMax_req and Split_MinMax are left for illustration purpose - they are much more intuitive then SplitByExtremum. Split_MinMax splits vector only once, while Split_MinMax_req splits vector recurrently.

See Also

pvar

Examples

Run this code
##### randomised sample #####
set.seed(16)
x = BBT(rnorm(30))

# when there are no repeated walues, the results of two functionas are identical
s1 = SplitByExtremum(x); s1
s2 = Split_MinMax_req(x); s2

# only one iteration, one min and on max.
s3 = Split_MinMax(x); s3	
c(1, which.max(x), which.min(x), length(x))

# grafical iliustration:
plot(x, type="l")
points(s1, x[s1], col=2, cex=1, pch=19)
points(s3, x[s3], col=4, cex=2)

##### special sample #####

x = c(0, -0.5, -1, 2, -1, 3, -1, 0)

### in this case functions are not identical. SplitByExtremum makes a better job.
s1 = SplitByExtremum(x); s1
s2 = Split_MinMax_req(x); s2

Run the code above in your browser using DataLab