Commit ff3287b9 authored by Rubin, Paul's avatar Rubin, Paul

Corrected call to add1 (works with "."), demo'd init superset of full.

parent b8e29747
......@@ -133,7 +133,7 @@ stepwise <-
# If we get here, we failed to drop a term; try adding one.
# Note: add1 throws an error if nothing can be added (current == full), which we trap with tryCatch.
a <- tryCatch(
add1(current, fm, test = "F"),
add1(current, full, test = "F"),
error = function(e) NULL
if (is.null(a)) {
......@@ -224,6 +224,14 @@ stepwise(Fertility ~ 0 + Agriculture + Examination + Education + Catholic + Infa
Every model has an intercept.
Similarly, if the initial model contains variables not included in the full model, they will automatically be added to the full model. To demonstrate this, we run stepwise with a full model consisting of just a constant term and a bigger initial model.
stepwise(Fertility ~ 1, Fertility ~ 1 + Examination + Catholic + Infant.Mortality, aToEnter, aToLeave)
Notice that Examination and Infant.Mortality (not included in the "full" model) are retained but that Education (which is in neither the "full" nor the initial model) is never added.
Next, we run "forward" stepwise regression (in which variables may enter but may not leave the model under construction) and "backward" stepwise regression (in which variables may leave but may not enter).
To demonstrate forward regression, we begin with a model containing only a constant term and the Examination variable, and observe that Examination (which has been consistently dropped above) remains in the final model. The demonstration code omits the value, but setting it explicitly to something sufficiently large would produce the same result.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment