How to calculate nonlinearity/linearity of an array which contains distance between points?

110 Views Asked by At

There is an array which contains points as shown below;

[ -0.0249795, -0.00442094, -0.00397789, -0.00390947, -0.00384182, -0.0037756, -0.00371057, 0.00180882, 0.00251853, 0.00239539, 0.00244367, 0.00249255, 0.00254166, 0.00259185, 0.0116467, 0.0155782, 0.016471 ]

First of all, honestly, i don't know whether there is a measurement of nonlinearity or not. If there is, i would like to know what that's name is.

So how can i calculate the linearity or nonlinearity of this points distribution. I mean, after you draw a line from these points, how much will the line be linear and non-linear?

e.g. some line points, p1= [1,-0.0249795], p2= [2, -0.00442094] ...

2

There are 2 best solutions below

0
On BEST ANSWER

Let your array be $a = (a_1,a_2,\ldots, a_n)$. Then you could use some formulas to compute lines through $a_1$ and $a_2$, $a_2$ and $a_3$, and so forth. By comparing each slope to the average, you get some kind of measurement of linearity. In numbers:

The slope of the line connecting $a_i$ and $a_{i+1}$ is

$$m_i = \frac{a_{i+1} - a_i}{i+1 - i} = a_{i+1} - a_i$$

Doing this you get $n-1$ slopes $m_1, \ldots, m_{n-1}$ and the average equals $$m := \frac{m_1 +\ldots + m_{n-1}}{n-1} = \frac{a_n - a_1}{n-1}$$

Now you can compute how much all the $m_i$ differ from $m$ $$r = \sqrt{ \sum_{i=1}^{n-1} (m_i - m)^2}$$ Then $r = 0$ if and only if all points are on a straight line and $r > 0$ if they are not.

While this is quite easy to compute, I still encourage you to look at linear regressions and its error value since the method above is quite susceptible for errors: If all but one point lie on a straight line and the only bad one has a huge discrepancy, then the $r$ is still quite big although the points are 'close' to being on a straight line.

0
On

The term "linear" is used somewhat differently than what one would first expect, as it is not so much about whether or not a function looks like a straight line, but more about how nicely it behaves when doing certain things to it. What you are looking for is probably linear regression, where you (or your computer) draw the straight line that best fits your data, that is, the line that minimizes the distance from it self to the data points.