This may seem silly, but I've been crazy for the last hour trying to find a way to automate the linear fit of my data. All I need is the slope.
Say I have some data list={1,2,3,4,5,6,7,8};
and want to find the slope that fits it best, something like m = Slope[list]
, so that I can use m
wherever I want.
Fit[{1, 2, 3, 4, 5, 6, 7}, {1, x}, x]
returns me 4.0284*10^-15 + 1. x
, in wich case the value I want is 1.
. How can I get that value programmaticly? The function Fit
returns the results in a not very useful form... Why?
Notice that I have 2337 curves to fit. I can't do them all by eye or copy and paste. Surely I'm missing something.
Thanks
D[Fit[{1, 2, 3, 4, 5, 6, 7}, {1, x}, x], x]
? $\endgroup$Coefficient[Fit[{1, 2, 3, 4, 5, 6, 7}, {1, x}, x], x]
works too. $\endgroup$lm = LinearModelFit[{1, 2, 3, 4, 5, 6, 7}, {1, x}, x]; First@Pick[lm["BestFitParameters"], lm["BasisFunctions"], x]
. There are lots of fitting functions. Try?*Fit
. $\endgroup$D
, esp. when the model has other functions. $\endgroup$