How to measure smoothness of a time series in R? Is there a good way to measure smoothness of a time series in R? For example,
-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1.0

is much smoother than
-1, 0.8, -0.6, 0.4, -0.2, 0, 0.2, -0.4, 0.6, -0.8, 1.0

although they have same mean and standard deviation. It would be cool if there is a function to give me a smooth score over a time series.
 A: The standard deviation of the differences will give you a rough smoothness estimate:
x <- c(-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1.0)
y <- c(-1, 0.8, -0.6, 0.4, -0.2, 0, 0.2, -0.4, 0.6, -0.8, 1.0)
sd(diff(x))
sd(diff(y))

Update: As Cyan points out, that gives you a scale-dependent measure. A similar scale-independent measure would use the coefficient of variation rather than standard deviation:
sd(diff(x))/abs(mean(diff(x)))
sd(diff(y))/abs(mean(diff(y)))

In both cases, small values correspond to smoother series.
A: To estimate the roughness of an array, take the squared difference of the normalized differences, and divide by 4. This gives you scale-independence (because of the normalization), and ignores trends (because of using the second difference).
firstD = diff(x)
normFirstD = (firstD - mean(firstD)) / sd(firstD)
roughness = (diff(normFirstD) ** 2) / 4

Zero will be perfect smoothness, 1 is maximal roughness.
You then either use the sum of this measure, or its mean, depending on whether you want your roughness measure to be length-independent.
I think this may be the same as a previous answer elsewhere:
And similar things are discussed in academic sources like this and this, saying we should integrate the squared second derivative. 
I don't read algebra, so I'm not sure if what I'm suggesting is quite the same as any of these.
A: The lag-one autocorrelation will serve as a score and has a reasonably straightforward statistical interpretation too.
cor(x[-length(x)],x[-1])

Score interpretation: 


*

*scores near 1 imply a smoothly varying series

*scores near 0 imply that there's no overall linear relationship between a data point and the following one (that is, plot(x[-length(x)],x[-1]) won't give a scatterplot with any apparent linearity)

*scores near -1 suggest that the series is jagged in a particular way: if one point is above the mean, the next is likely to be below the mean by about the same amount, and vice versa.

A: You could just check the correlation against the timestep number. That would be equivalent to taking the R² of a simple linear regression on the timeseries. Note, though, that those are two very different timeseries, so I don't know how well that works as a comparison.
