What is a good way to measure the "linearity" of a dataset? I have an empirically gathered dataset which relates two variables. Over a small range the relationship appears linear, however over a larger range there is clearly some second order polynomial relationship as can be seen in the image at http://imgur.com/W7f9p.
I'm trying to get a measure of linearity for different ranges considered. E.g. at 20 < x < 60 or 100 < x < 120 it is very linear, but at 20 < x < 180 it is not very linear. I have tried to fit a straight line to the data and calculate the R^2 data (goodness of fit) but this shows that the straight line over the larger range has a better fit than over the smaller range. While this may be true with MS Excel, from the image it is clear that the larger range is less linear...if you hold the side of a piece of paper against the points.
Is there a better way to measure the "linearity" of a dataset?  
 A: Fit a quadratic instead of a linear function. The absolute value of the estimate of the highest coefficient of the quadratic serves as a sensible measure of linearity, which is zero if the data lie exactly on a line. Moreover, if the data come from a linear model with Gaussian noise, the Gauss-Markov theorem guarantees that the coefficient estimates are unbiased, hence under repetition of the fit with multiple data from the same model distribution, the expected value of the coefficient will be zero. 
Of course in a single fit, one usually doesn't get zero, so one would have to 
use some test for the significance of the coefficients.
A: One way to go would be to run a hierarchical regression with your Y-axis variable as the outcome/criterion. In step/block 1 you would enter your X variable as a predictor, and in step/block 2, enter a product term (X squared or multiplied against itself). The X squared term represents your quadratic component. The standardized regression weights (betas) for X and X squared would give you some sense of the "strength" of the linear and quadratic components relative to each other, and the change in R-squared from step/block 1 to step/block 2 is an indication of how much better the model fits the data when you have added in the quadratic component.
See Ch. 8 in Keith, T. Z. (2005). Multiple regression and beyond. Allyn & Bacon. 978-0205326440
A: The best measure of linearity between two variables x and y is the Pearson product moment correlation coefficient.  The closer it is to 1 in absolute value the closer the fit is to a perfect straight line.  Now if you think there is good linearity in a subregion, calculate the correlation for just those pairs in the subregion.  If there is achange in shape outside that region it should show up in a drop in the correlation when all the data are included.
A: I can't speak for the value of this approach, but this source suggests the following approach I'd not seen before (which I've rewritten into R code).
lin.tester.func <- function(x,y) {

  Sz.func <- function(z) {
    Sz1 <- sum(z^2)
    Sz2 <- sum(z)^2
    divZ <- Sz2 / length(z)
    Sz <- Sz1 - divZ 
    Sz
  }

  Sx <- Sz.func(x)
  Sy<- Sz.func(y)
  SsqrtXY <- sqrt(Sx) * sqrt(Sy)
  Sxy <- sum(x * y) - ((sum(x) * sum(y)) / mean(length(x),length(y)))
  Sxy / SsqrtXY
  # closer to 1, the more linear. 
}


*

* Please edit if you know a name to this approach and please comment on utility/validity. 
