> cholest.wls <- lm(dLDL ~ lnDOSE, weights=r) > summary(cholest.wls) Call: lm(formula = dLDL ~ lnDOSE, weights = r) Residuals: 1 2 3 4 5 6 4.488 -5.291 -13.410 15.869 3.620 -6.615 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -36.9588 2.2441 -16.469 7.96e-05 *** lnDOSE -7.3753 0.9892 -7.456 0.00173 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 11.58 on 4 degrees of freedom Multiple R-squared: 0.9329, Adjusted R-squared: 0.9161 F-statistic: 55.59 on 1 and 4 DF, p-value: 0.001729 > anova(cholest.wls) Analysis of Variance Table Response: dLDL Df Sum Sq Mean Sq F value Pr(>F) lnDOSE 1 7457.3 7457.3 55.586 0.001729 ** Residuals 4 536.6 134.2 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > x <- seq(0,4,0.01) > y <- predict(cholest.wls,list(lnDOSE=x)) > > > plot(lnDOSE,dLDL,main="Weighted Least Squares Regression of dLDL on ln(DOSE)", + xlab="ln(DOSE)",ylab="dLDL",pch=16) > lines(x,y) > > y <- as.matrix(dLDL) > x0 <- matrix(rep(1,nrow(y)),ncol=1) > x1 <- as.matrix(lnDOSE) > x <- cbind(x0,x1) > w<- diag(sqrt(r)) > > xs <- w %*% x; > ys <- w %*% y; > > betahatw <- solve(t(xs) %*% xs) %*% t(xs) %*% ys > > es <- ys - xs %*% betahatw > ssew <- t(es) %*% es > msew <- ssew/(6-2) > > vbetahatw <- diag(msew[1,1] * solve(t(xs) %*% xs)) > sebetahatw <- sqrt(vbetahatw) > > yhatw <- x %*% betahatw > ew <- y-yhatw > > print(cbind(betahatw,sebetahatw)) sebetahatw [1,] -36.958837 2.2441282 [2,] -7.375305 0.9892326 > print(cbind(yhatw,ew)) [,1] [,2] [1,] -36.95884 1.1588371 [2,] -43.71676 -1.2832390 [3,] -48.82893 -3.8710669 [4,] -53.94111 4.2411052 [5,] -59.05328 0.8532773 [6,] -64.16545 -1.8345506 >