The weights can be used to define the relative precision of the various points. However, there is no provision to specify that you know the variance of each point, and that the weights are exactly equal to the reciprocals of those variances. The CFTOOL function still estimates the residual variance and uses it in the computation of the coefficient standard errors, even if you have weights.
It is common in statistics to specify weights W to minimize
sum( W(i) * (y(i)-yfit(i)).^2 )
For example, suppose y(i) is the average of n(i) measurements. That means that if the individual measurements have variance v, then the ith average of y(i) has variance v/n(i). The n values are used as the weights. To estimate v such that the n values are proportional to the inverses of the y(i) variances, it cannot be assumed that the variances are exactly equal to the n values.
The weights are used in computing the confidence intervals, but the weights are not taken as known precisions (inverse variances) of the data, they are taken as proportional to them. We still estimate an overall variance factor.
The GLMFIT function in the Statistics Toolbox does treat the variances as known for some distributions. For instance, the code below makes it clear that the weights are being used:
x =.3 + 10*rand(100,1);
noise = randn(100,1)./x;
y = 5 + 2*x + 5*noise;
scatter(x,y);
xx = linspace(0,10);
f1 = fit(x,y,'poly1')
line(xx,f1(xx),'color','r');
f2 = fit(x,y,'poly1','weight',x)
line(xx,f2(xx),'color','g')
legend('Data','Unweighted fit','Weighted fit','location','SE')
Best Answer