1
$\begingroup$

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]

enter image description here

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)]

enter image description here

But, how would I do this with empirical data. I cannot get FindFit to do what I want.

$\endgroup$
1
$\begingroup$

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"][[2]]
power
Plot[Exp[lm[Log[x]]], {x, 1, 20}, Epilog -> Point[data], 
 PlotLabel -> Exp[lm[Log[x]]]]

enter image description here

| improve this answer | |
$\endgroup$
0
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ You could also take logs... $\endgroup$ – Igor Rivin Apr 8 '17 at 17:42
  • 1
    $\begingroup$ 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. $\endgroup$ – JimB Apr 8 '17 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.