Skip to content

Instantly share code, notes, and snippets.

@njtierney
Created September 12, 2016 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njtierney/7ca595e3fba843269d8313e8225bf794 to your computer and use it in GitHub Desktop.
Save njtierney/7ca595e3fba843269d8313e8225bf794 to your computer and use it in GitHub Desktop.
iris_lm_fit_all <- lm(Sepal.Length ~ ., iris)
iris_lm_fit_all_step <- step(iris_lm_fit_all,
scope = Sepal.Length ~ .^2)
#> Start: AIC=-348.57
#> Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species
#>
#> Df Sum of Sq RSS AIC
#> + Petal.Length:Species 2 0.4883 13.068 -350.07
#> + Sepal.Width:Petal.Length 1 0.2754 13.281 -349.64
#> + Sepal.Width:Petal.Width 1 0.2269 13.329 -349.10
#> + Sepal.Width:Species 2 0.3848 13.172 -348.88
#> + Petal.Width:Species 2 0.3720 13.184 -348.74
#> <none> 13.556 -348.57
#> + Petal.Length:Petal.Width 1 0.0897 13.467 -347.56
#> - Petal.Width 1 0.4090 13.966 -346.11
#> - Species 2 0.8889 14.445 -343.04
#> - Sepal.Width 1 3.1250 16.681 -319.45
#> - Petal.Length 1 13.7853 27.342 -245.33
#>
#> Step: AIC=-350.07
#> Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species +
#> Petal.Length:Species
#>
#> Df Sum of Sq RSS AIC
#> + Sepal.Width:Petal.Length 1 0.4570 12.611 -353.41
#> + Sepal.Width:Petal.Width 1 0.4449 12.623 -353.26
#> + Sepal.Width:Species 2 0.4398 12.628 -351.20
#> + Petal.Width:Species 2 0.3875 12.681 -350.58
#> <none> 13.068 -350.07
#> + Petal.Length:Petal.Width 1 0.1614 12.907 -349.93
#> - Petal.Length:Species 2 0.4883 13.556 -348.57
#> - Petal.Width 1 0.3156 13.384 -348.49
#> - Sepal.Width 1 3.2285 16.297 -318.95
#>
#> Step: AIC=-353.41
#> Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species +
#> Petal.Length:Species + Sepal.Width:Petal.Length
#>
#> Df Sum of Sq RSS AIC
#> - Petal.Width 1 0.14317 12.754 -353.71
#> <none> 12.611 -353.41
#> + Petal.Width:Species 2 0.28583 12.325 -352.85
#> + Petal.Length:Petal.Width 1 0.07466 12.537 -352.30
#> + Sepal.Width:Petal.Width 1 0.00434 12.607 -351.46
#> + Sepal.Width:Species 2 0.10983 12.501 -350.72
#> - Sepal.Width:Petal.Length 1 0.45704 13.068 -350.07
#> - Petal.Length:Species 2 0.66991 13.281 -349.64
#>
#> Step: AIC=-353.71
#> Sepal.Length ~ Sepal.Width + Petal.Length + Species + Petal.Length:Species +
#> Sepal.Width:Petal.Length
#>
#> Df Sum of Sq RSS AIC
#> <none> 12.754 -353.71
#> + Petal.Width 1 0.14317 12.611 -353.41
#> + Sepal.Width:Species 2 0.06729 12.687 -350.51
#> - Petal.Length:Species 2 0.79054 13.545 -348.69
#> - Sepal.Width:Petal.Length 1 0.62946 13.384 -348.49
iris_lm_fit_all_step
#>
#> Call:
#> lm(formula = Sepal.Length ~ Sepal.Width + Petal.Length + Species +
#> Petal.Length:Species + Sepal.Width:Petal.Length, data = iris)
#>
#> Coefficients:
#> (Intercept) Sepal.Width
#> 1.8164 0.8055
#> Petal.Length Speciesversicolor
#> 0.6548 -1.0041
#> Speciesvirginica Petal.Length:Speciesversicolor
#> -2.8432 0.3179
#> Petal.Length:Speciesvirginica Sepal.Width:Petal.Length
#> 0.5997 -0.1053
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment