# Find best power of data to give straight line

I have data which follows a power law - I'm just not sure which one.

It could be modelled with something like:

power = RandomInteger[{1, 10}];

data = Table[x^(power), {x, 20}];

ListPlot[data] Now, I want to find the power which might best give me a straight line. This, of course, would be the inverse of power.

i.e.

ListPlot[data^(1/power)] But, how would I do this with empirical data. I cannot get FindFit to do what I want.

Log log transform:

power = RandomInteger[{1, 10}];
data = Table[{x, x^(power)}, {x, 20}];
dt = {Log@#1, Log@#2} & @@@ data;
lm = LinearModelFit[dt, {x}, x]
lm["BestFitParameters"][]
power
Plot[Exp[lm[Log[x]]], {x, 1, 20}, Epilog -> Point[data],
PlotLabel -> Exp[lm[Log[x]]]] I was being stupid.

FindFit[data, x^y, y, x]


Gives you the right answer, then just take the inverse of that. Silly me. Its obvious.

• You could also take logs... – Igor Rivin Apr 8 '17 at 17:42
• It's not always obvious and depends on the "real" data. Consider estimating the power as a parameter with a Box-Cox transformation. And note that "straightening out" the relationship some times messes with the assumption of constant variance about the line. – JimB Apr 8 '17 at 18:45