Question: is it possible to increase the accuracy of the BestFit
property for LinearModelFit
?
I have code that uses LinearModelFit
and the BestFit
property to return the best fitting slope of a list of data. But, a peculiar result I've ran into is very slightly negative slope as a result for data where the slope is 0.
Example:
{{Log[10], Log[2]}, {Log[20], Log[2]}, {Log[30], Log[2]},{Log[40], Log[2]}, {Log[50], Log[2]}}
produces
7.411988753*10^-21
for the slope, even though we can see that the exact slope is 0.
Here is the context:
For[j = 1, j <= Length[pointsList], j++,
measureData = Map[{Log[1/#], Log[BoxCount[pointsList[[j]], #]]} &, scaleList];
line = LinearModelFit[measureData, x, x];
AppendTo[dimensionList, Coefficient[line["BestFit"], x, 1]]];
pointsList
is just a list of lists of points; scaleList = {1/10, 1/20, 1/30, 1/40, 1/50}
. The example I shared was one list from pointsList
and its corresponding element in dimensionList
.
So, is there a way to increase the accuracy of linear model fit? Alternatively, I could emplace an If
expression to solve the best fitting slopes I can solve algebraicly, but I was hoping this wasn't necessary.
...,WorkingPrecision->100]
toLinearModelFit[...]
to have a 100 digits working precision. $\endgroup$...WorkingPrecision->Infinity]
to have exact arithmetic $\endgroup$BoxCount
? $\endgroup$Coefficient[line["BestFit"] // Chop
$\endgroup$