On Wed, 17 Nov 2010, Summers, Peter wrote:
In trying to answer questions from some of my students, I did
the following (using the data set "food.gdt" from Hill et al):
1) define x1 = 1/x
2) wls x1 y 0 x, save residuals uhat1
3) define ystar = y/sqrt(x), cstar = 1/sqrt(x), xstar =
x/sqrt(x) (ie, wls "by hand")
4) ols ystar cstar xstar, save residuals uhat2
(I actually used the gui, but replicated this with the console)
I was surprised to find that uhat1 and uhat2 are different, even
though the coefficient estimates are exactly the same. In fact,
uhat2 = cstar*uhat1. Is this intended?
Yes, it's intended. The residuals we report from WLS are the same
as those reported by R. They represent the deviations of actual y
from the predictions for y generated by the coefficients of the
weighted model applied to actual X.
The following script illustrates the point.
<script>
open data4-1
series w = 1/sqft
wls w price 0 sqft
series u1 = $uhat
series chk1 = price - ($coeff[1] + $coeff[2]*sqft)
series ystar = price/sqrt(sqft)
series cstar = 1/sqrt(sqft)
series xstar = sqft/sqrt(sqft)
ols ystar cstar xstar
series u2 = $uhat
series chk2 = ystar - ($coeff[1]*cstar + $coeff[2]*xstar)
print u1 chk1 u2 chk2 -o
# compare R, if available
foreign language=R --send-data
y <- gretldata[,"price"]
x <- gretldata[,"sqft"]
w <- gretldata[,"w"]
model <- lm(y ~ x, weights=w)
model
model$residuals
end foreign
</script>
Allin Cottrell