Fitting

<<"ErrorBarPlots`" (* Make sure to execute this cell!! *)

Sample data : (x, y, σy)

data={{0,0.18804,0.1},{1,2.40351,0.1},{2,4.76703,0.1},{3,6.80721,0.1},{4,8.95863,0.1},{5,10.9312,0.1},{6,13.0096,0.1},{7,14.6587,0.1},{8,16.8880,0.1},{9,18.3569,0.1},{10,20.3084,0.1}};

MatrixForm[data]

Separate data from uncertainties, and create table of weights

xydata=Table[{data[[i,1]],data[[i,2]]},{i,1,Length[data]}];
w=Table[1/data[[i,3]]^2,{i,1,Length[data]}];

MatrixForm[xydata]
w

Plot data with errorbars

dataPlot=ErrorListPlot[data,PlotStyle->PointSize[0.006]]

Fit data to a line

Clear[x];
lm=LinearModelFit[xydata,{1,x},x,Weights->w]

fitPlot= Plot[lm[x],{x,0,10}];

Show[dataPlot,fitPlot]

lm["BestFitParameters"]

lm["ParameterTable"]

MatrixForm[lm["CovarianceMatrix"]]

MatrixForm[lm["CorrelationMatrix"]]

IS THIS A GOOD FIT?  DO YOU BELIEVE THE UNCERTAINTIES?

Plot the residuals of the fit.

ErrorListPlot[Table[{data[[i,1]],lm[data[[i,1]]]-data[[i,2]],data[[i,3]]},{i,1,Length[data]}],PlotStyle->PointSize[0.016]]

Define a χ2 function; calculate χ2 for the linear fit.

χ2[data_]:= Sum[(lm[data[[i,1]]]-data[[i,2]])^2/data[[i,3]]^2,{i,1,Length[data]}]

χ2[data]

Fit not so good.   Try fit to a quadratic

Fit data to a quadratic

Clear[x];
lm=LinearModelFit[xydata,{1,x,x^2},x,Weights->w]

Residuals for quadratic fit

ErrorListPlot[Table[{data[[i,1]],lm[data[[i,1]]]-data[[i,2]],data[[i,3]]},{i,1,Length[data]}],PlotStyle->PointSize[0.016]]

χ2[data]

Consistent with quadratic model!