R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit) R -- ýòî ñâîáîäíîå ÏÎ, è îíî ïîñòàâëÿåòñÿ áåçî âñÿêèõ ãàðàíòèé. Âû âîëüíû ðàñïðîñòðàíÿòü åãî ïðè ñîáëþäåíèè íåêîòîðûõ óñëîâèé. Ââåäèòå 'license()' äëÿ ïîëó÷åíèÿ áîëåå ïîäðîáíîé èíôîðìàöèè. R -- ýòî ïðîåêò, â êîòîðîì ñîòðóäíè÷àåò ìíîæåñòâî ðàçðàáîò÷èêîâ. Ââåäèòå 'contributors()' äëÿ ïîëó÷åíèÿ äîïîëíèòåëüíîé èíôîðìàöèè è 'citation()' äëÿ îçíàêîìëåíèÿ ñ ïðàâèëàìè óïîìèíàíèÿ R è åãî ïàêåòîâ â ïóáëèêàöèÿõ. Ââåäèòå 'demo()' äëÿ çàïóñêà äåìîíñòðàöèîííûõ ïðîãðàìì, 'help()' -- äëÿ ïîëó÷åíèÿ ñïðàâêè, 'help.start()' -- äëÿ äîñòóïà ê ñïðàâêå ÷åðåç áðàóçåð. Ââåäèòå 'q()', ÷òîáû âûéòè èç R. [Çàãðóæåíî ðàíåå ñîõðàíåííîå ðàáî÷åå ïðîñòðàíñòâî] > prcomp function (x, ...) UseMethod("prcomp") > princomp function (x, ...) UseMethod("princomp") > prcomp function (x, ...) UseMethod("prcomp") > ?prcomp starting httpd help server ... done > USArrests Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California 9.0 276 91 40.6 Colorado 7.9 204 78 38.7 Connecticut 3.3 110 77 11.1 Delaware 5.9 238 72 15.8 Florida 15.4 335 80 31.9 Georgia 17.4 211 60 25.8 Hawaii 5.3 46 83 20.2 Idaho 2.6 120 54 14.2 Illinois 10.4 249 83 24.0 Indiana 7.2 113 65 21.0 Iowa 2.2 56 57 11.3 Kansas 6.0 115 66 18.0 Kentucky 9.7 109 52 16.3 Louisiana 15.4 249 66 22.2 Maine 2.1 83 51 7.8 Maryland 11.3 300 67 27.8 Massachusetts 4.4 149 85 16.3 Michigan 12.1 255 74 35.1 Minnesota 2.7 72 66 14.9 Mississippi 16.1 259 44 17.1 Missouri 9.0 178 70 28.2 Montana 6.0 109 53 16.4 Nebraska 4.3 102 62 16.5 Nevada 12.2 252 81 46.0 New Hampshire 2.1 57 56 9.5 New Jersey 7.4 159 89 18.8 New Mexico 11.4 285 70 32.1 New York 11.1 254 86 26.1 North Carolina 13.0 337 45 16.1 North Dakota 0.8 45 44 7.3 Ohio 7.3 120 75 21.4 Oklahoma 6.6 151 68 20.0 Oregon 4.9 159 67 29.3 Pennsylvania 6.3 106 72 14.9 Rhode Island 3.4 174 87 8.3 South Carolina 14.4 279 48 22.5 South Dakota 3.8 86 45 12.8 Tennessee 13.2 188 59 26.9 Texas 12.7 201 80 25.5 Utah 3.2 120 80 22.9 Vermont 2.2 48 32 11.2 Virginia 8.5 156 63 20.7 Washington 4.0 145 73 26.2 West Virginia 5.7 81 39 9.3 Wisconsin 2.6 53 66 10.8 Wyoming 6.8 161 60 15.6 > ?USArrests > p <- prcomp(USArrests) > plot(p) > summary(USArrests + ) Murder Assault UrbanPop Rape Min. : 0.800 Min. : 45.0 Min. :32.00 Min. : 7.30 1st Qu.: 4.075 1st Qu.:109.0 1st Qu.:54.50 1st Qu.:15.07 Median : 7.250 Median :159.0 Median :66.00 Median :20.10 Mean : 7.788 Mean :170.8 Mean :65.54 Mean :21.23 3rd Qu.:11.250 3rd Qu.:249.0 3rd Qu.:77.75 3rd Qu.:26.18 Max. :17.400 Max. :337.0 Max. :91.00 Max. :46.00 > p <- prcomp(USArrests, scale. = TRUE) > plot(p) > ?biplot > methods(biplot) [1] biplot.default* biplot.prcomp* biplot.princomp* Non-visible functions are asterisked > ?biplot.prcomp > biplot(p) > p2 <- prcomp(USArrests) > biplot(p2) > plot(p) > plot(p2) > biplot(p2) > biplot(p) > p$rotation PC1 PC2 PC3 PC4 Murder -0.5358995 0.4181809 -0.3412327 0.64922780 Assault -0.5831836 0.1879856 -0.2681484 -0.74340748 UrbanPop -0.2781909 -0.8728062 -0.3780158 0.13387773 Rape -0.5434321 -0.1673186 0.8177779 0.08902432 > USArrests Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California 9.0 276 91 40.6 Colorado 7.9 204 78 38.7 Connecticut 3.3 110 77 11.1 Delaware 5.9 238 72 15.8 Florida 15.4 335 80 31.9 Georgia 17.4 211 60 25.8 Hawaii 5.3 46 83 20.2 Idaho 2.6 120 54 14.2 Illinois 10.4 249 83 24.0 Indiana 7.2 113 65 21.0 Iowa 2.2 56 57 11.3 Kansas 6.0 115 66 18.0 Kentucky 9.7 109 52 16.3 Louisiana 15.4 249 66 22.2 Maine 2.1 83 51 7.8 Maryland 11.3 300 67 27.8 Massachusetts 4.4 149 85 16.3 Michigan 12.1 255 74 35.1 Minnesota 2.7 72 66 14.9 Mississippi 16.1 259 44 17.1 Missouri 9.0 178 70 28.2 Montana 6.0 109 53 16.4 Nebraska 4.3 102 62 16.5 Nevada 12.2 252 81 46.0 New Hampshire 2.1 57 56 9.5 New Jersey 7.4 159 89 18.8 New Mexico 11.4 285 70 32.1 New York 11.1 254 86 26.1 North Carolina 13.0 337 45 16.1 North Dakota 0.8 45 44 7.3 Ohio 7.3 120 75 21.4 Oklahoma 6.6 151 68 20.0 Oregon 4.9 159 67 29.3 Pennsylvania 6.3 106 72 14.9 Rhode Island 3.4 174 87 8.3 South Carolina 14.4 279 48 22.5 South Dakota 3.8 86 45 12.8 Tennessee 13.2 188 59 26.9 Texas 12.7 201 80 25.5 Utah 3.2 120 80 22.9 Vermont 2.2 48 32 11.2 Virginia 8.5 156 63 20.7 Washington 4.0 145 73 26.2 West Virginia 5.7 81 39 9.3 Wisconsin 2.6 53 66 10.8 Wyoming 6.8 161 60 15.6 > p$rotation PC1 PC2 PC3 PC4 Murder -0.5358995 0.4181809 -0.3412327 0.64922780 Assault -0.5831836 0.1879856 -0.2681484 -0.74340748 UrbanPop -0.2781909 -0.8728062 -0.3780158 0.13387773 Rape -0.5434321 -0.1673186 0.8177779 0.08902432 > p$sdev [1] 1.5748783 0.9948694 0.5971291 0.4164494 > plot(p) > ?plot.prcomp > plot(p$sdev / sum(p$sdev)) > plot(p$sdev / sum(p$sdev), type = "l") > p <- prcomp(mtcars) > plot(p) > p <- prcomp(mtcars, scale. = TRUE) > plot(p) > plot(p$sdev / sum(p$sdev), type = "l") > plot(cumsum(p$sdev) / sum(p$sdev), type = "l") > plot(p$sdev / sum(p$sdev), type = "l") > plot(p) > ?mtcars > p <- prcomp(~. - am, data = mtcars, scale. = TRUE) > plot(p) > p$rotation PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 mpg -0.3676849 0.07050060 -0.25307189 -0.023839139 -0.09364602 0.32157165 -0.7812632548 0.22808807 0.08632212 cyl 0.3841978 -0.01701023 -0.17077126 -0.006734756 -0.07952499 -0.13857889 -0.2406667939 0.01072593 -0.84442468 disp 0.3732901 -0.12384551 -0.01932973 0.267778162 -0.34790757 0.41908809 -0.0133173797 0.19421427 0.01725708 hp 0.3518966 0.22190444 0.13283590 -0.066155894 -0.54456501 -0.01246362 -0.2210832412 -0.55977835 0.28695372 drat -0.2840020 0.36330088 0.09482286 0.845964758 -0.10848239 -0.17195240 0.0264160366 -0.05998469 -0.12500329 wt 0.3436179 -0.21198325 0.40913106 0.262218369 0.13840943 0.31672385 -0.0001221624 0.37682291 0.12482357 qsec -0.2347962 -0.46614200 0.47094732 0.080754555 0.20991163 0.19884954 -0.2345300940 -0.53371760 -0.21795724 vs -0.3289499 -0.18813504 0.44855116 -0.212021461 -0.61498761 -0.27939340 0.0481282276 0.36324316 -0.14040218 gear -0.1828965 0.55364511 0.22342836 -0.264638610 -0.02610613 0.60163619 0.2821952883 -0.04611741 -0.30568247 carb 0.2418766 0.44048898 0.48937044 -0.131839886 0.33680215 -0.30355864 -0.3807878345 0.17963643 0.07062972 PC10 mpg 0.1148822255 cyl 0.1621035805 disp -0.6620945216 hp 0.2522435580 drat 0.0380752789 wt 0.5690303710 qsec -0.1682303816 vs -0.0008875261 gear 0.0471352177 carb -0.3205608643 > biplot(p) > ?biplot.prcomp > mtcars2 <- mtcars > rownames(mtcars2) <- NULL > mtcars2 mpg cyl disp hp drat wt qsec vs am gear carb 1 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 2 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 3 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 4 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 5 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 6 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 7 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 8 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 9 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 10 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 11 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 12 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 13 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 14 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 15 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 16 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 17 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 18 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 19 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 20 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 21 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 22 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 23 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 24 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 25 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 26 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 27 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 28 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 29 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 30 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 31 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 32 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 > p2 <- prcomp(~. - am, data = mtcars, scale. = TRUE) > biplot(p2) > p2 <- prcomp(~. - am, data = mtcars2, scale. = TRUE) > biplot(p2) > p2$rotation PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 mpg -0.3676849 0.07050060 -0.25307189 -0.023839139 -0.09364602 0.32157165 -0.7812632548 0.22808807 0.08632212 cyl 0.3841978 -0.01701023 -0.17077126 -0.006734756 -0.07952499 -0.13857889 -0.2406667939 0.01072593 -0.84442468 disp 0.3732901 -0.12384551 -0.01932973 0.267778162 -0.34790757 0.41908809 -0.0133173797 0.19421427 0.01725708 hp 0.3518966 0.22190444 0.13283590 -0.066155894 -0.54456501 -0.01246362 -0.2210832412 -0.55977835 0.28695372 drat -0.2840020 0.36330088 0.09482286 0.845964758 -0.10848239 -0.17195240 0.0264160366 -0.05998469 -0.12500329 wt 0.3436179 -0.21198325 0.40913106 0.262218369 0.13840943 0.31672385 -0.0001221624 0.37682291 0.12482357 qsec -0.2347962 -0.46614200 0.47094732 0.080754555 0.20991163 0.19884954 -0.2345300940 -0.53371760 -0.21795724 vs -0.3289499 -0.18813504 0.44855116 -0.212021461 -0.61498761 -0.27939340 0.0481282276 0.36324316 -0.14040218 gear -0.1828965 0.55364511 0.22342836 -0.264638610 -0.02610613 0.60163619 0.2821952883 -0.04611741 -0.30568247 carb 0.2418766 0.44048898 0.48937044 -0.131839886 0.33680215 -0.30355864 -0.3807878345 0.17963643 0.07062972 PC10 mpg 0.1148822255 cyl 0.1621035805 disp -0.6620945216 hp 0.2522435580 drat 0.0380752789 wt 0.5690303710 qsec -0.1682303816 vs -0.0008875261 gear 0.0471352177 carb -0.3205608643 > biplot(p2, choice = 2:3) > biplot(p2, choice = 4:3) > biplot(p2, choice = 4:5) > l <- lm(mpg ~ ., data = mtcars) > summary(l) Call: lm(formula = mpg ~ ., data = mtcars) Residuals: Min 1Q Median 3Q Max -3.4506 -1.6044 -0.1196 1.2193 4.6271 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 12.30337 18.71788 0.657 0.5181 cyl -0.11144 1.04502 -0.107 0.9161 disp 0.01334 0.01786 0.747 0.4635 hp -0.02148 0.02177 -0.987 0.3350 drat 0.78711 1.63537 0.481 0.6353 wt -3.71530 1.89441 -1.961 0.0633 . qsec 0.82104 0.73084 1.123 0.2739 vs 0.31776 2.10451 0.151 0.8814 am 2.52023 2.05665 1.225 0.2340 gear 0.65541 1.49326 0.439 0.6652 carb -0.19942 0.82875 -0.241 0.8122 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.65 on 21 degrees of freedom Multiple R-squared: 0.869, Adjusted R-squared: 0.8066 F-statistic: 13.93 on 10 and 21 DF, p-value: 3.793e-07 > library(faraway) > library(help=faraway) > ?eco > ?LifeCycleSavings > l <- lm(sr ~ ., data = LifeCycleSavings) > summary(l) Call: lm(formula = sr ~ ., data = LifeCycleSavings) Residuals: Min 1Q Median 3Q Max -8.2422 -2.6857 -0.2488 2.4280 9.7509 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 28.5660865 7.3545161 3.884 0.000334 *** pop15 -0.4611931 0.1446422 -3.189 0.002603 ** pop75 -1.6914977 1.0835989 -1.561 0.125530 dpi -0.0003369 0.0009311 -0.362 0.719173 ddpi 0.4096949 0.1961971 2.088 0.042471 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.803 on 45 degrees of freedom Multiple R-squared: 0.3385, Adjusted R-squared: 0.2797 F-statistic: 5.756 on 4 and 45 DF, p-value: 0.0007904 > l <- lm(mpg ~ ., data = mtcars) > library(MASS) > l2<-stepAIC(l) Start: AIC=70.9 mpg ~ cyl + disp + hp + drat + wt + qsec + vs + am + gear + carb Df Sum of Sq RSS AIC - cyl 1 0.0799 147.57 68.915 - vs 1 0.1601 147.66 68.932 - carb 1 0.4067 147.90 68.986 - gear 1 1.3531 148.85 69.190 - drat 1 1.6270 149.12 69.249 - disp 1 3.9167 151.41 69.736 - hp 1 6.8399 154.33 70.348 - qsec 1 8.8641 156.36 70.765 147.49 70.898 - am 1 10.5467 158.04 71.108 - wt 1 27.0144 174.51 74.280 Step: AIC=68.92 mpg ~ disp + hp + drat + wt + qsec + vs + am + gear + carb Df Sum of Sq RSS AIC - vs 1 0.2685 147.84 66.973 - carb 1 0.5201 148.09 67.028 - gear 1 1.8211 149.40 67.308 - drat 1 1.9826 149.56 67.342 - disp 1 3.9009 151.47 67.750 - hp 1 7.3632 154.94 68.473 147.57 68.915 - qsec 1 10.0933 157.67 69.032 - am 1 11.8359 159.41 69.384 - wt 1 27.0280 174.60 72.297 Step: AIC=66.97 mpg ~ disp + hp + drat + wt + qsec + am + gear + carb Df Sum of Sq RSS AIC - carb 1 0.6855 148.53 65.121 - gear 1 2.1437 149.99 65.434 - drat 1 2.2139 150.06 65.449 - disp 1 3.6467 151.49 65.753 - hp 1 7.1060 154.95 66.475 147.84 66.973 - am 1 11.5694 159.41 67.384 - qsec 1 15.6830 163.53 68.200 - wt 1 27.3799 175.22 70.410 Step: AIC=65.12 mpg ~ disp + hp + drat + wt + qsec + am + gear Df Sum of Sq RSS AIC - gear 1 1.565 150.09 63.457 - drat 1 1.932 150.46 63.535 148.53 65.121 - disp 1 10.110 158.64 65.229 - am 1 12.323 160.85 65.672 - hp 1 14.826 163.35 66.166 - qsec 1 26.408 174.94 68.358 - wt 1 69.127 217.66 75.350 Step: AIC=63.46 mpg ~ disp + hp + drat + wt + qsec + am Df Sum of Sq RSS AIC - drat 1 3.345 153.44 62.162 - disp 1 8.545 158.64 63.229 150.09 63.457 - hp 1 13.285 163.38 64.171 - am 1 20.036 170.13 65.466 - qsec 1 25.574 175.67 66.491 - wt 1 67.572 217.66 73.351 Step: AIC=62.16 mpg ~ disp + hp + wt + qsec + am Df Sum of Sq RSS AIC - disp 1 6.629 160.07 61.515 153.44 62.162 - hp 1 12.572 166.01 62.682 - qsec 1 26.470 179.91 65.255 - am 1 32.198 185.63 66.258 - wt 1 69.043 222.48 72.051 Step: AIC=61.52 mpg ~ hp + wt + qsec + am Df Sum of Sq RSS AIC - hp 1 9.219 169.29 61.307 160.07 61.515 - qsec 1 20.225 180.29 63.323 - am 1 25.993 186.06 64.331 - wt 1 78.494 238.56 72.284 Step: AIC=61.31 mpg ~ wt + qsec + am Df Sum of Sq RSS AIC 169.29 61.307 - am 1 26.178 195.46 63.908 - qsec 1 109.034 278.32 75.217 - wt 1 183.347 352.63 82.790 > l <- lm(mpg ~ . - am, data = mtcars) > summary(l) Call: lm(formula = mpg ~ . - am, data = mtcars) Residuals: Min 1Q Median 3Q Max -2.9886 -1.6738 -0.3834 0.9796 5.4395 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 17.59704 18.41902 0.955 0.3498 cyl -0.44543 1.02029 -0.437 0.6667 disp 0.01275 0.01805 0.706 0.4876 hp -0.02022 0.02199 -0.919 0.3679 drat 1.10054 1.63356 0.674 0.5075 wt -3.93430 1.90734 -2.063 0.0511 . qsec 0.57571 0.71086 0.810 0.4267 vs -0.22311 2.08103 -0.107 0.9156 gear 1.22953 1.43393 0.857 0.4004 carb -0.26242 0.83653 -0.314 0.7567 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.68 on 22 degrees of freedom Multiple R-squared: 0.8596, Adjusted R-squared: 0.8022 F-statistic: 14.97 on 9 and 22 DF, p-value: 1.855e-07 > l2<-stepAIC(l) Start: AIC=71.11 mpg ~ (cyl + disp + hp + drat + wt + qsec + vs + am + gear + carb) - am Df Sum of Sq RSS AIC - vs 1 0.0826 158.12 69.125 - carb 1 0.7069 158.75 69.251 - cyl 1 1.3692 159.41 69.384 - drat 1 3.2606 161.30 69.761 - disp 1 3.5804 161.62 69.825 - qsec 1 4.7118 162.75 70.048 - gear 1 5.2816 163.32 70.160 - hp 1 6.0709 164.11 70.314 158.04 71.108 - wt 1 30.5650 188.61 74.766 Step: AIC=69.12 mpg ~ cyl + disp + hp + drat + wt + qsec + gear + carb Df Sum of Sq RSS AIC - carb 1 0.6725 158.80 67.260 - cyl 1 1.2886 159.41 67.384 - drat 1 3.2639 161.39 67.778 - disp 1 3.7211 161.84 67.869 - qsec 1 5.2229 163.35 68.164 - gear 1 5.3164 163.44 68.183 - hp 1 6.9592 165.08 68.503 158.12 69.125 - wt 1 30.4892 188.61 72.767 Step: AIC=67.26 mpg ~ cyl + disp + hp + drat + wt + qsec + gear Df Sum of Sq RSS AIC - cyl 1 2.055 160.85 65.672 - drat 1 2.810 161.61 65.822 - gear 1 4.681 163.48 66.190 - qsec 1 7.390 166.19 66.716 158.80 67.260 - disp 1 11.211 170.01 67.443 - hp 1 12.981 171.78 67.775 - wt 1 76.291 235.09 77.815 Step: AIC=65.67 mpg ~ disp + hp + drat + wt + qsec + gear Df Sum of Sq RSS AIC - drat 1 4.936 165.79 64.639 - gear 1 9.278 170.13 65.466 - disp 1 9.846 170.70 65.573 160.85 65.672 - qsec 1 17.833 178.69 67.036 - hp 1 18.419 179.27 67.141 - wt 1 84.464 245.32 77.178 Step: AIC=64.64 mpg ~ disp + hp + wt + qsec + gear Df Sum of Sq RSS AIC - disp 1 8.692 174.48 64.274 165.79 64.639 - qsec 1 17.694 183.48 65.884 - gear 1 19.848 185.63 66.258 - hp 1 20.149 185.94 66.310 - wt 1 91.501 257.29 76.703 Step: AIC=64.27 mpg ~ hp + wt + qsec + gear Df Sum of Sq RSS AIC - qsec 1 11.057 185.54 64.241 174.48 64.274 - gear 1 11.579 186.06 64.331 - hp 1 13.505 187.99 64.660 - wt 1 105.091 279.57 77.361 Step: AIC=64.24 mpg ~ hp + wt + gear Df Sum of Sq RSS AIC - gear 1 9.510 195.05 63.840 185.54 64.241 - hp 1 91.647 277.19 75.086 - wt 1 94.554 280.09 75.420 Step: AIC=63.84 mpg ~ hp + wt Df Sum of Sq RSS AIC 195.05 63.840 - hp 1 83.274 278.32 73.217 - wt 1 252.627 447.67 88.427 > summary(l2) Call: lm(formula = mpg ~ hp + wt, data = mtcars) Residuals: Min 1Q Median 3Q Max -3.941 -1.600 -0.182 1.050 5.854 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 37.22727 1.59879 23.285 < 2e-16 *** hp -0.03177 0.00903 -3.519 0.00145 ** wt -3.87783 0.63273 -6.129 1.12e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.593 on 29 degrees of freedom Multiple R-squared: 0.8268, Adjusted R-squared: 0.8148 F-statistic: 69.21 on 2 and 29 DF, p-value: 9.109e-12 > anova(l, l2) Analysis of Variance Table Model 1: mpg ~ (cyl + disp + hp + drat + wt + qsec + vs + am + gear + carb) - am Model 2: mpg ~ hp + wt Res.Df RSS Df Sum of Sq F Pr(>F) 1 22 158.04 2 29 195.05 -7 -37.007 0.7359 0.6442 >