RE: Coefficients from Fit as a list?
- To: mathgroup at smc.vnet.net
- Subject: [mg63420] RE: [mg63396] Coefficients from Fit as a list?
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Fri, 30 Dec 2005 02:32:35 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi LZ,
> How can I store the coefficients from the Fit function as a list?
The easiest way is to use CoefficientList. For example,
data = (Random[Real, {-1, 1}] + 2 # ) & /@ Range[25];
dplt = ListPlot[data, PlotJoined -> False];
ft = Fit[data, {1, x}, x]
coef = CoefficientList[ft, x]
DisplayTogether[{
ListPlot[data, PlotJoined -> False],
Plot[Evaluate[ft], {x, 0, 25}, PlotStyle -> Red]
}];
Another way is to use Regress instead as this can output the coefficients as
a list anyway. For example,
Needs["Statistics`LinearRegression`"]
Regress[data, {1, x}, x, RegressionReport -> {BestFitCoefficients,
SummaryReport}]
coef = BestFitParameters /. %
Regards,
Dave.