# Plotting a best fit line for listloglogplot data

After playing around with calculating the Overlapping Allan Deviation for my research project (and with much help from this community), I have finally resolved a correct listloglogplot for simulated white noise.

WN = WhiteNoiseProcess[NormalDistribution[0, 10]];
data = RandomFunction[WN, {1, 5000}];
ListPlot[data, Filling -> Axis]
(*Averaging Factor*)
f = 3;
Module[{points, yBinLst, y, M},
points = data["Values"];
yBinLst = Partition[points, m];
y = Mean /@ yBinLst;
M = Length[yBinLst];
Sqrt[
Sum[
(Sum[(y[[i + f]] - y[[i]])^2, {i, j, j + f - 1}]/2)*f^2*(M - 2*f + 1),
{j, 1, M - 2*f + 1}]]]
SeedRandom[0];
mValues = Range[2, 2500, 1];


Similar to all the research I've read concerning the Allan Variance, the output listloglogplot appears to have a -.5(ish) slope, which is consistent with examples from textbooks. However, is it possible to add a fit or "trendline" to a graphic showing the slope is approximately correct?

• The figure does not appear to be a straight line so why would you want to summarize it with a slope as if it were a straight line? Is there just a particular section that is expected to be a straight line?
– JimB
Jun 10 '15 at 17:01
• In the listloglogplot a trend line with a slope of -.5 should be discernable from the graphic. This slope correlates with White Frequency Noise when viewed in a Log Log plot (which is what was initially generated). My hope is to expand this to identify different types of noise from different data sets, and eventually atomic clock noise. I understand it isn't really a straight line, nevertheless, a best fit line should show the expected -.5 slope. Jun 10 '15 at 17:30
• Would you mind showing the figure? We'll just have to agree that "goodness-of-fit" can be in the eye of the beholder (and can require subject matter knowledge which I don't have for this particular application).
– JimB
Jun 10 '15 at 17:36
• Link to graphic link to similar example Jun 10 '15 at 17:41

You data has lots of zeros towards the end. I found out the end of the non-zero data from

nn = Position[aData, 0, 1, 1][[1, 1]] - 1


(* 832 *)

Then to get a straight line I worked out log coordinates for your data

lgData = Table[{N[Log[n]], Log[aData[[n]]]}, {n, nn}];


Now we can do a DynamicModule to work out a tangent to the data to get a straight line.

DynamicModule[{n1 = 1, n2 = nn, line, x},
Column[{
Row[{ IntervalSlider[Dynamic[{n1, n2}], {1, nn, 1},
Method -> "Push", ImageSize -> 6 72,
Appearance -> {"Markers", "Labeled"}]}],

Dynamic[line = Fit[lgData[[n1 ;; n2]], {1, x}, x]],
Dynamic[Show[