"Articificially creat a data set {x_i,y_i} with approximately linear relatition."
SetDirectory[NotebookDirectory[]];
b=2.5;a=-7.1;
y[x_]:=b*x+a;
txy=Table[{x+(2Random[]-1)^3,y[x]+(2Random[]-1)^3},{x,-12,7.5,0.12}];
lpttxy=ListPlot[txy,AxesLabel->{"x","y"}]
ydat[i_]:=txy[[i,2]];xdat[i_]:=txy[[i,1]];
Rsq[b_,a_]:=Sum[(ydat[i]-(b*xdat[i]+a))^2,{i,1,Length[txy]}];
"Values of the data points {x,y}"
txy

"The best fit parameters can be obtained by using Mathematica's built-in function 'FindFit'"
ff=FindFit[txy,bb*x+aa,{bb,aa},x]

"extract besta and bestb from ff: "
besta=aa/.ff
bestb=bb/.ff

"extract bestm and bestc from ff"

"Overlap the best fit straight line on the rawdata"
Show[{lpttxy,Plot[bestb*x+besta,{x,-20,15}]}]

"An alternative but more powerful method to find the best fit parameters for linear function is LinearModelFit"
lmf=LinearModelFit[txy,{x},x]

"The error in bestm and bestc can be retrieved from LinearModelFit using ParameterTable"
lmf[{"BestFit","ParameterTable"}]