Linear Regression-Example 1
A simple set o f data
data = {{1,2},{2,4.1},{3,6.5},{4,8.7},{5,11},{6,14}};
Plot the data
fig0a = ListPlot[data,PlotStyle->Hue[.9],Prolog→AbsolutePointSize[6]];
ListPlot[data,PlotStyle->Hue[.9],PlotJoined->True,Prolog->{AbsolutePointSize[6],Map[Point,data]}];
The statistical package for regression
Needs["Statistics`LinearRegression`"]
Fit the data to a straight line
fit0 = Fit[data,{1,x},x]
Use Regress to get a fit and the error in the slope and interception
regress0 = Regress[data,{1,x},x]
Results: slope = 2.369 ± 0.064 and intecept = -0.573 ± 0.251
The % error is:
Chop[(0.064/2.369)100,6]
(0.251/0.573)100
Plot the fit
fig0b = Plot[fit0,{x,0,10}]
Show both figure
Show[{fig0a,fig0b}]
Created by Mathematica (September 7, 2006) | ![]() |