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]];

[Graphics:../HTMLFiles/MATH5_TUT1_446.gif]

ListPlot[data,PlotStyle->Hue[.9],PlotJoined->True,Prolog->{AbsolutePointSize[6],Map[Point,data]}];

[Graphics:../HTMLFiles/MATH5_TUT1_447.gif]

The statistical package for regression

Needs["Statistics`LinearRegression`"]

Fit the data  to a straight line

fit0 = Fit[data,{1,x},x]

-0.573333 + 2.36857 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

0

43.8045

Plot the fit

fig0b = Plot[fit0,{x,0,10}]

[Graphics:../HTMLFiles/MATH5_TUT1_452.gif]

-Graphics -

Show both figure

Show[{fig0a,fig0b}]

[Graphics:../HTMLFiles/MATH5_TUT1_454.gif]

-Graphics -


Created by Mathematica  (September 7, 2006) Valid XHTML 1.1!