# Fitting data in Log-Log scale

I want to fit my data from a txt file to a curve in log-log scale. What I tried to do was this:

data = Import["Path", "Table"][[All, {2, 1}]];
FindFit[Log[data], Log[1 - Gamma[A, B/x]/Gamma[A]], {A, B}, x]


When I plot this, this is not the scale I get from ListLogLogPlot. How do I fit data on log-log scale to a curve in log-log scale? The curve I want to fit is $f(x)=1-\Gamma[a,b/x]/\Gamma[a]$ (Data and everything is imported correctly - I just want to change the scale on which I'm fitting)

• Are you aware that fitting the curve in log-space will generally yield a different fit? Also, assumptions about distribution of errors (e.g, that they are normally distributed) will often be violated. – Sjoerd C. de Vries Jan 13 '16 at 23:01
• Yes, I'm aware of that. That's why I want to do it. (My data has a lot of points near the origin of axis and I'm mostly interested in the points far away). – Caims Jan 13 '16 at 23:03

data = Table[{x, 1 - Gamma[1, 2/x]/Gamma + Random[]/10}, {x, 1, 10, .1}];
res = FindFit[data, 1 - Gamma[A, B/x]/Gamma[A], {A, B}, x];
(* {A -> 0.913848, B -> 2.06033} *)

Show[
ListLogLogPlot[data],
LogLogPlot[1 - Gamma[A, B/x]/Gamma[A] /. res // Evaluate, {x, 1, 10}],
Frame -> True
] You can fit in log-log space, but then don't forget to scale x in your gamma expression as Exp[x], because you scaled it as Log[x] in the input:

res2 = FindFit[Log[data], Log[1 - Gamma[A, B/Exp[x]]/Gamma[A]], {A, B}, x]
(* {A -> 0.923818, B -> 2.09093} *)

Show[
ListLogLogPlot[data],
LogLogPlot[1 - Gamma[A, B/x]/Gamma[A] /. res // Evaluate, {x, 1, 10}],
LogLogPlot[1 - Gamma[A, B/x]/Gamma[A] /. res2 // Evaluate, {x, 1, 10},
PlotStyle -> {Red, Dashed}],
Frame -> True
] The two fits are very similar, but if you inspect the fitted parameters you'll see they differ slightly. As I said in the comments above, fitting in the log domain is not the same as in the linear domain.

• I don't think that's what I want to do. Doesn't your code fit my curve to a "linear" data and just shows log-log plot of it? (Meant the first one) – Caims Jan 13 '16 at 23:20
• @Caims What about the second one? I wasn't too sure what you actually wanted. – Sjoerd C. de Vries Jan 13 '16 at 23:30
• It is perfect, Thank you so much! That's what I wanted. – Caims Jan 13 '16 at 23:33