# slopeOP

##### slopeOP

Optimal partitioning algorithm for change-in-slope problem with a finite number of states (beginning and ending values of each segment is restricted to a finite set of values called states). The algorithm takes into account a continuity constraint between successive segments and infers a continuous piecewise linear signal.

##### Usage

```
slopeOP(data, states, penalty = 0, constraint = "null", minAngle = 0,
type = "channel", testMode = FALSE)
```

##### Arguments

- data
vector of data to segment: a univariate time series

- states
vector of states = set of accessible starting/ending values for segments in increasing order.

- penalty
the penalty value (a non-negative real number)

- constraint
string defining a constraint : "null", "isotonic", "unimodal" or "smoothing"

- minAngle
a minimal inner angle in degree between consecutive segments in case constraint = "smoothing"

- type
string defining the pruning type to use. "null" = no pruning, "channel" = use monotonicity property, "pruning" = pelt-type property

- testMode
a boolean, if true the function also returns the percent of elements to scan (= ratio scanned elements vs. scanned elements if no pruning)

##### Value

a list of 3 elements = (changepoints, states, globalCost). (Pruning is optional)

`changepoints`

is the vector of changepoints (we return the extremal values of all segments from left to right)

`states`

is the vector of successive states. states[i] is the value we inferred at position changepoints[i]

`globalCost`

is a number equal to the global cost of the non-penalized change-in-slope problem. That is the value of the fit to the data ignoring the penalties for adding changes

*pruning*is the percent of positions to consider in cost matrix Q (returned only if testMode = TRUE)

##### Examples

```
# NOT RUN {
myData <- slopeData(index = c(1,100,200,300), states = c(0,5,3,6), noise = 1)
slopeOP(data = myData, states = 0:6, penalty = 10)
# }
```

*Documentation reproduced from package slopeOP, version 1.0.0, License: MIT + file LICENSE*