\begin{Schunk}
\begin{Sinput}
 X <- model.matrix(lm.D9)
 XTX <- t(X) %*% X
 XTXinv <- solve(XTX)
 Beta <- XTXinv %*% t(X) %*% weight
\end{Sinput}
\end{Schunk}
