First I don't really know Mathematica and I haven't done stats in a very long time.
I have been trying to find (Google and RTFM) a way to reproduce the results produced by the Mathematica LinearModelFit
function using scipy.stats.linregress
. It is now obvious that this is not the way to go except for the most simple cases.
LinearModelFit[ydata, 1/(2 n - x)^100, x]
produces 16.3766 + <<70>>/(2580 - x)^100
If someone could point me in the right direction I would appreciate it.
Thanks in advance.
data: http://pastebin.com/RTp5em0W
Screen shot of Mathematica Notebook: https://i.sstatic.net/lT43O.jpg
Note: I did not do the Mathematica work. ddd is the data that can be found at the pastebin link. The y in the denominator should be x.
I don't know the python solution, but one way to handle this problem is to transform your x data according to the functional form you are supplying as the argument to LinearModelFit
:
n=1290
LinearModelFit[ydata, 1/(2 n - x)^100, x]["BestFit"]
16.1504 + 1.471945513739138*10^315/(2580 - x)^100
is equivalent to:
xtransform = 1/(2 n - #)^100 & /@ Range[Length[ydata]];
LinearModelFit[Transpose[{xtransform, ydata}], x, x]["BestFit"]
16.1504 + 1.471945513739138*10^315 x
You should readily be able to do that transform and use standard linear regression in python. You might have precision issues due to the large exponent however.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With