How can you say for certain that a set of data has a linear slope?

Let's say that you have some set of data and are trying to model that data with an equation. This same set of data might be linear, quadratic, or of an even higher order polynomial.

I know that if you were to do a best-fit, you could model the data as being a number of different orders based on the approach you decide to take. What I am trying to do is write a program that looks at a set of data and says, "this is most likely a linear equation." Is there a way to determine if a set of data is considered "linear"?

Here's my thought process and example taken from my situation. For a program I am writing I ultimately have to determine if data is considered "linear" which seems rather subjective. I was thinking that I could approach it something like this... Try and model the data at a few different orders of polynomials then come back and say... well, it's somewhere between but... it's closer to being a quadratic than it is to being linear. Is there a mathematical process/method I can follow to achieve something like that?

Another one of my concerns is that a set of statistical data is not perfect, so if you were to determine that an equation for a set of data has an order of 1.01... I'd be a bit confused, because that's really close to being linear. Would you just call it linear though?

• Are you aware of how a "best-fit polynomial" is generated in general? – Xoque55 Apr 12 '17 at 13:30
• @Xoque55 No. I am not. I do know how to use tools which do the job for me, but would not actually be able to do one on my own. Is that what you're asking? – Snoop Apr 12 '17 at 13:30
• You might want to characterize your problem in terms of thresholds of errors regarding Least Squares: en.wikipedia.org/wiki/Least_squares. That is, if the error of a linear fit is below a user-specified threshold, then consider the data "linear." But if not, check to see if it satisfies the error threshold for being considered "quadratic." And so on... The nice thing is how if the data actually is truly linear, the true best-fit line will be found (in theory, with exact arithmetic). – Xoque55 Apr 12 '17 at 13:33
• @Xoque55 That sounds fairly promising. When you say user-specified threshold are you talking about... how small the error has to be in order to be considered a fit for the data? – Snoop Apr 12 '17 at 13:40
• That's probably the simplest way to quantify the degree of subjectivity for this type of problem. E.g., you might say that a best-fit line does a good linear approximation but I might say that it doesn't and we should use a quadratic approximation to better capture the data. Assuming that we are both in the dark about the true nature of the data, neither one of us is "more correct" than the other subjectively...but comparing the error of your linear approximation to the error of my quadratic approximation helps justify which approximation we prefer. – Xoque55 Apr 12 '17 at 13:46