Hi there,
I am reading the tutorial and trying to understand the
concept of weighted least squares.
I am a little confused about the form of the data one
should have. For each x, we should have multiple responses
so as to see if we have heteroscedacity, and then calculate
the variances of Y for each Xi? If I have data like the
following example (one y for one x) how can I calculate the
variance in order to use the formula for the weights
(w=1/σ^2) since the variance of a single number is 0?
Weighted Least Squares is not an appropriate method to data
like this? I have arbitrarily set weight 0.2 to the outlier.
x = (1:10)';
y = 10  2*x + randn(10,1);
y(10) = 0;
bls=regress(y,[ones(1,length(x))' x])
w=[1 1 1 1 1 1 1 1 1 0.2]';
[bw,sew_b,msew] = lscov([ones(1,length(x))' x],y,w)
brob = robustfit(x,y)
scatter(x,y,'filled'); grid on; hold on
plot(x,bls(1)+bls(2)*x,'r','LineWidth',2);
plot(x,bw(1)+bw(2)*x,'g','LineWidth',2)
plot(x,brob(1)+brob(2)*x,'k','LineWidth',2)
legend('Data','Ordinary Least Squares','Weighted
Fit','Robust Regression')
