0
$\begingroup$

I need to find the linear slope on a log log plot for small values x and for large values of x, but I am not sure how. You can only fit data right, so how do I tell it to fit a log log plot? Here is my graph and my data:

 MuhData={{0.7366, 0.238124}, {1.016, 0.844452}, {1.4732, 2.30787}, {1.938, 
  4.91981}, {0.3048, 0.00808025}, {0.5131, 0.0588889}};
loglogstuff = 
 ListLogLogPlot[{MuhData}, 
   PlotTheme -> "Scientific", 
   PlotMarkers -> {{\[FilledSquare], 15}}, PlotStyle -> {Blue}, 
   PlotLegends -> 
    PointLegend[Automatic, {"Large"}, 
     LegendFunction -> Frame]]

If I get a linear fit for small values it tells me the power relationship and same for large values. Somehow I need to find 1 fit for each (small values and large values of x) and it needs to be linear. Any help on how to do this is appreciated.

$\endgroup$
1
$\begingroup$

LogLogPlot just takes the Log of the data and provides some neat formatting of the axes:

GraphicsRow[{ListLogLogPlot[MuhData, Frame -> True], 
  ListPlot[Log[MuhData], Frame -> True]}, ImageSize -> 600]

enter image description here

So you can just fit a line to the Log of the data:

lm = LinearModelFit[Log[MuhData], x, x];
Normal[lm]

-0.498215 + 3.49921 x

Show[Plot[Normal@lm, {x, -1.5, 1}, PlotStyle -> Red, Frame -> True], loglogstuff]

enter image description here

Or (like in BlacKow's answer):

f0 = Normal[lm] /. x -> Log[x] // Exp

0.607614 x^3.49921

Show[LogLogPlot[f0, {x, 0.2, 2}, PlotStyle -> Red, Frame -> True], loglogstuff]

enter image description here


EDIT:

To fit separately for small and large x values I'd Take, according to the comment of OP, the first two and last two points and do separate fits:

lm1 = LinearModelFit[Take[Log@MuhData, 2], x, x]
Normal[lm1]

-0.231552 + 3.93645 x

lm2 = LinearModelFit[Take[Log@MuhData, -2], x, x]
Normal[lm2]

-0.287282 + 3.8137 x

Show[Plot[Normal@lm1, {x, -1.5, 0}, PlotStyle -> Red, Frame -> True], 
 Plot[Normal@lm2, {x, 0, 1}, PlotStyle -> Blue, 
  Frame -> True], loglogstuff, PlotRange -> All]

enter image description here

Or

f1 = Normal[lm1] /. x -> Log[x] // Exp
f2 = Normal[lm2] /. x -> Log[x] // Exp

Show[LogLogPlot[f1, {x, 0.3, 1}, PlotStyle -> Red, Frame -> True], 
 LogLogPlot[f2, {x, 1, 2}, PlotStyle -> Blue, 
  Frame -> True], loglogstuff, PlotRange -> All]

enter image description here


A bit more general: if one defines "small x" such that x<1, and "large" as x>1, then one can Select the data for respective fits:

lm3 = LinearModelFit[Log@Select[MuhData, #[[1]] < 1 &], x, x]
Normal[lm3]

-0.267396 + 3.83288 x

lm4 = LinearModelFit[Log@Select[MuhData, #[[1]] > 1 &], x, x]
Normal[lm4]

-0.214781 + 2.72766 x

Show[Plot[Normal@lm3, {x, -1.5, 0}, PlotStyle -> Red, Frame -> True], 
 Plot[Normal@lm4, {x, 0, 1}, PlotStyle -> Blue, 
  Frame -> True], loglogstuff, PlotRange -> All]

enter image description here

Or

f3 = Normal[lm3] /. x -> Log[x] // Exp
f4 = Normal[lm4] /. x -> Log[x] // Exp

Show[LogLogPlot[f3, {x, 0.3, 1}, PlotStyle -> Red, Frame -> True], 
 LogLogPlot[f4, {x, 1, 2}, PlotStyle -> Blue, 
  Frame -> True], loglogstuff, PlotRange -> All]

enter image description here

$\endgroup$
  • $\begingroup$ what about the issue of finding 2 fits, one for small x and one for large x? $\endgroup$ – Shrodinger 2016 Oct 12 '16 at 18:00
  • $\begingroup$ What are "small" and "large"? The division is not very clear from the loglogplot. $\endgroup$ – corey979 Oct 12 '16 at 18:03
  • $\begingroup$ True, I define small as the first two points lets say and large as the last two points $\endgroup$ – Shrodinger 2016 Oct 12 '16 at 18:04
  • 2
    $\begingroup$ @Shrodinger2016. You have no business getting 2 fits with just 6 data points. (Plus, the linear fit doesn't seem to be too bad.) $\endgroup$ – JimB Oct 12 '16 at 18:08
  • $\begingroup$ These data points are averages of 10 trials each, and I am expected to have two power law relationships. Don't blame me, blame my class for not giving me more supplies. $\endgroup$ – Shrodinger 2016 Oct 12 '16 at 18:10
2
$\begingroup$
ft = Fit[Log@MuhData, {1, x}, x] /. x -> Log[x] // Exp

Show[ListLogLogPlot[{MuhData}, PlotTheme -> "Scientific", 
  PlotMarkers -> {{\[FilledSquare], 15}}, PlotStyle -> {Blue}, 
  PlotLegends -> 
   PointLegend[Automatic, {"Large"}, LegendFunction -> Frame]], 
 LogLogPlot[ft, {x, 0.3, 2.0}, PlotStyle -> Red, PlotRange -> Full]]

enter image description here

$\endgroup$

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.