R : Copyright 1999, The R Development Core Team Version 0.99.0 Under development (unstable) (December 31, 1999) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type "?license" or "?licence" for distribution details. R is a collaborative project with many contributors. Type "?contributors" for a list. Type "demo()" for some demos, "help()" for on-line help, or "help.start()" for a HTML browser interface to help. Type "q()" to quit R. > ###-- Linear Models, basic functionality -- weights included. > > ## From John Maindonald : > roller <- data.frame( + weight = c(1.9, 3.1, 3.3, 4.8, 5.3, 6.1, 6.4, 7.6, 9.8, 12.4), + depression = c( 2, 1, 5, 5, 20, 20, 23, 10, 30, 25)) > > roller.lmu <- lm(weight~depression, data=roller) > roller.lsfu <- lsfit(roller$depression, roller$weight) > > roller.lsf <- lsfit(roller$depression, roller$weight, wt = 1:10) > roller.lsf0 <- lsfit(roller$depression, roller$weight, wt = 0:9) > roller.lm <- lm(weight~depression, data=roller, weights= 1:10) > roller.lm0 <- lm(weight~depression, data=roller, weights= 0:9) > roller.lm9 <- lm(weight~depression, data=roller[-1,],weights= 1:9) > roller.glm <- glm(weight~depression, data=roller, weights= 1:10) > roller.glm0<- glm(weight~depression, data=roller, weights= 0:9) > > all.equal(deviance(roller.lm), + deviance(roller.glm)) [1] TRUE > all.equal(weighted.residuals(roller.lm), + residuals (roller.glm)) [1] TRUE > > all.equal(deviance(roller.lm0), + deviance(roller.glm0)) [1] TRUE > all.equal(weighted.residuals(roller.lm0, drop=FALSE), + residuals (roller.glm0)) [1] TRUE > > (im.lm0 <- influence.measures(roller.lm0)) Influence measures of lm(formula = weight ~ depression, data = roller, weights = 0:9) : dfb.1. dfb.dprs dffit cov.r cook.d hat inf 2 -0.0530 0.0482 -0.0530 1.551 0.001635 0.1277 3 -0.1769 0.1538 -0.1782 1.569 0.018065 0.1742 4 0.0130 -0.0113 0.0131 1.842 0.000100 0.2613 5 -0.1174 -0.0185 -0.3370 1.049 0.055523 0.0892 6 -0.1031 -0.0162 -0.2960 1.229 0.045771 0.1114 7 -0.0118 -0.1891 -0.5010 1.070 0.119319 0.1555 8 0.7572 -0.5948 0.7972 1.467 0.309976 0.3510 9 0.1225 -0.2067 -0.2664 2.391 0.040794 0.4470 * 10 -0.3348 1.1321 2.0937 0.233 0.895835 0.2826 * > > all.equal(unname(im.lm0 $ infmat), + unname(cbind( dfbetas (roller.lm0) + , dffits (roller.lm0) + , covratio (roller.lm0) + ,cooks.distance(roller.lm0) + ,lm.influence (roller.lm0)$hat) + )) [1] TRUE > > all.equal(rstandard(roller.lm9), + rstandard(roller.lm0),tol=1e-15) [1] TRUE > all.equal(rstudent(roller.lm9), + rstudent(roller.lm0),tol=1e-15) [1] TRUE > > all.equal(summary(roller.lm0)$coef, + summary(roller.lm9)$coef, tol=1e-15) [1] TRUE > all.equal(print(anova(roller.lm0), signif.st=FALSE), + anova(roller.lm9), tol=1e-15) Analysis of Variance Table Response: weight Df Sum Sq Mean Sq F value Pr(>F) depression 1 158.408 158.408 5.4302 0.05259 Residuals 7 204.202 29.172 [1] TRUE >