# Statistics Linearity Question

1. Oct 7, 2014

### roam

1. The problem statement, all variables and given/known data

I have two different experimental curves, and I would like to measure how closely a straight line fits each data, and which curve is more crooked. In statistics how can I measure this "linearity"?

By the way this is about stepper motor step linearity (ideally it has to be a straight line i.e. homogeneous step sizes). I am comparing the two plots made for two different speeds:

2. Relevant equations

3. The attempt at a solution

I'm new to stats and I'm not sure what method to use. I'm very confused because some websites say I have to calculate the $R^2$ value, while others say I need a some kind of regression line.

So, if the linearity could somehow be determined from the equation of regression line, what kind of regression do I need to use (linear or quadratic, cubic, etc)? And how exactly do I determine linearity from that equation?

Any explanation is greatly appreciated.

P.S. I am using Matlab.

2. Oct 7, 2014

### Staff: Mentor

I am not sure of the nomenclature, but I assume R2 is just a correlation coefficient, which in this case is a measure of how good the linear regression is. Two sides of the same coin.

3. Oct 8, 2014

### roam

Thank you for the clarification. A high $R^2$ is what I think I will need to show good linearity.

4. Oct 8, 2014

### Yanick

R2 may be one way to do it but remember that is just a measure of how "far" away your linear fit is from the data (in the R2 it is squared to get rid of negative numbers and somehow normalized such that a perfect fit gets you a value of 1). You can have a lower R2 from noisy data which are still linear or from data which are not described well by a linear equation. What I would do is to fit a line, calculate the residuals, then either show the residuals are just noise with respect to the independant variable (this would just be a plot showing that there is no pattern to the residuals) or you can make a histogram/frequency plot of the residuals and show that they follow a gaussian/normal type of distribution.

It all depends on how far you want to go to show the linearity of your data (sometimes just plotting your line and data on the same graph is enough).