R version 2.9.2 (2009-08-24)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

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.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>
>
> election.table <- read.table('http://www-stat.stanford.edu/~jtaylo/courses/stats191/data/election.table', header=T)
>
> election.step.both <- step(lm(V ~ I + D + W +G:I + P + N, election.table), direction='both')
Start: AIC=-128.54
V ~ I + D + W + G:I + P + N

Df Sum of Sq RSS AIC
- P 1 5.506e-05 0.024 -130.487
- W 1 1.698e-04 0.024 -130.386
0.024 -128.536
- N 1 0.003 0.027 -127.927
- D 1 0.012 0.036 -121.972
- I:G 1 0.051 0.074 -106.520

Step: AIC=-130.49
V ~ I + D + W + N + I:G

Df Sum of Sq RSS AIC
- W 1 1.196e-04 0.024 -132.381
0.024 -130.487
- N 1 0.003 0.027 -129.769
+ P 1 5.506e-05 0.024 -128.536
- D 1 0.014 0.038 -122.762
- I:G 1 0.054 0.077 -107.710

Step: AIC=-132.38
V ~ I + D + N + I:G

Df Sum of Sq RSS AIC
0.024 -132.381
- N 1 0.003 0.027 -131.740
+ W 1 1.196e-04 0.024 -130.487
+ P 1 4.876e-06 0.024 -130.386
- D 1 0.014 0.038 -124.760
- I:G 1 0.059 0.083 -108.123
>
> print(summary(election.step.both))

Call:
lm(formula = V ~ I + D + N + I:G, data = election.table)

Residuals:
Min 1Q Median 3Q Max
-0.043509 -0.019208 -0.004912 0.009626 0.090627

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.506530 0.020689 24.483 4.15e-14 ***
I -0.019417 0.014701 -1.321 0.20515
D 0.055436 0.018180 3.049 0.00765 **
N -0.004653 0.003177 -1.465 0.16241
I:G 0.009588 0.001519 6.314 1.03e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.03862 on 16 degrees of freedom
Multiple R-squared: 0.7883, Adjusted R-squared: 0.7353
F-statistic: 14.89 on 4 and 16 DF, p-value: 2.95e-05

>
> election.step.backward <- step(lm(V ~ I + D + W +G:I + P + N, election.table), direction='backward')
Start: AIC=-128.54
V ~ I + D + W + G:I + P + N

Df Sum of Sq RSS AIC
- P 1 5.506e-05 0.024 -130.487
- W 1 1.698e-04 0.024 -130.386
0.024 -128.536
- N 1 0.003 0.027 -127.927
- D 1 0.012 0.036 -121.972
- I:G 1 0.051 0.074 -106.520

Step: AIC=-130.49
V ~ I + D + W + N + I:G

Df Sum of Sq RSS AIC
- W 1 0.0001196 0.024 -132.381
0.024 -130.487
- N 1 0.003 0.027 -129.769
- D 1 0.014 0.038 -122.762
- I:G 1 0.054 0.077 -107.710

Step: AIC=-132.38
V ~ I + D + N + I:G

Df Sum of Sq RSS AIC
0.024 -132.381
- N 1 0.003 0.027 -131.740
- D 1 0.014 0.038 -124.760
- I:G 1 0.059 0.083 -108.123
>
> print(summary(election.step.backward))

Call:
lm(formula = V ~ I + D + N + I:G, data = election.table)

Residuals:
Min 1Q Median 3Q Max
-0.043509 -0.019208 -0.004912 0.009626 0.090627

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.506530 0.020689 24.483 4.15e-14 ***
I -0.019417 0.014701 -1.321 0.20515
D 0.055436 0.018180 3.049 0.00765 **
N -0.004653 0.003177 -1.465 0.16241
I:G 0.009588 0.001519 6.314 1.03e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.03862 on 16 degrees of freedom
Multiple R-squared: 0.7883, Adjusted R-squared: 0.7353
F-statistic: 14.89 on 4 and 16 DF, p-value: 2.95e-05

>
> election.step.forward <- step(lm(V ~ 1, election.table), list(upper = ~ I + D + W +G:I + P + N), direction='forward')
Start: AIC=-107.78
V ~ 1

Df Sum of Sq RSS AIC
+ D 1 0.028 0.085 -111.797
+ I 1 0.014 0.099 -108.465
+ P 1 0.012 0.100 -108.237
0.113 -107.779
+ N 1 0.002 0.110 -106.236
+ W 1 0.001 0.112 -105.957

Step: AIC=-111.8
V ~ D

Df Sum of Sq RSS AIC
+ P 1 0.010 0.075 -112.417
0.085 -111.797
+ W 1 0.007 0.078 -111.560
+ I 1 0.001 0.083 -110.119
+ N 1 3.261e-06 0.085 -109.798

Step: AIC=-112.42
V ~ D + P

Df Sum of Sq RSS AIC
0.075 -112.417
+ W 1 3.194e-04 0.074 -110.507
+ N 1 1.850e-04 0.075 -110.469
+ I 1 2.633e-05 0.075 -110.424
>
> print(summary(election.step.forward))

Call:
lm(formula = V ~ D + P, data = election.table)

Residuals:
Min 1Q Median 3Q Max
-0.101121 -0.036838 -0.006987 0.019029 0.163250

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.514022 0.022793 22.552 1.2e-14 ***
D 0.043134 0.017381 2.482 0.0232 *
P -0.006017 0.003891 -1.546 0.1394
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.06442 on 18 degrees of freedom
Multiple R-squared: 0.3372, Adjusted R-squared: 0.2636
F-statistic: 4.579 on 2 and 18 DF, p-value: 0.02468

>
>

>
> proc.time()
user system elapsed
0.840 0.048 0.882
R script