I got a set of data, and the ListLogLogPlot
output appears to have a slope of $-1$. Thus, I try to fit a line to show the slope according to this answer.
Thanks to @Hugh's answer:
Note: the IntervalSlider
function included in this code is a new thing of V10.0, so you should run this on V10.0 and later.
I try to get a straight line by working out log coordinates for this data:
nn = Length[data]
lgData = Table[{N[Log[n]], Log[data[[n]]]}, {n, nn}];
Using DynamicModule
to find the 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[ListLogLogPlot[data, ImageSize -> 6 72],
Plot[line, {x, Log[1], Log[nn]}, PlotStyle -> Red, PlotRange -> All]
]]}]]
Unfortunately, it gives me the following error of a string numbers like this:
Fit[{{0., {-3.3123, 3.40072}},...]
Except for the above main problem, I have three minor issues:
1. I am curious to know that what is the base in ListLogLogPlot
? I actually want a base-10 log-log plot, which is given by ListLogLogPlot
so I guess the base built-in it is 10 instead of $e$. But in @Hugh's solution, it just includes Log
rather than Log10
, but appears to give the correct figure, see this question.
2. Is it possible to find the intercepts of the resulting "trendline" accurately?
3. I found that in V9 ListLogLogPlot
with GridLines -> Automatic
yields a plot with grid line corresponding each scale, however, in v10 it yields a plot only with gird line corresponding main scale, as show in the above figure.