Hi,

I am trying to do stepwise variable selection with the function step. I want to allow in the model all main effects, double interactions and quadratic terms. However, I would like to respect the hierarchy of the terms, i.e. a quadratic term can be added to the model only if the main effect has already been added and an interaction can be added to the model only if both main effects have already been added.

Here is an example of what I tried :


steplm<-step(lm(Fertility ~1, data = swiss),scope=list(upper=~(Agriculture+Examination+Education+Catholic+Infant.Mortality)^2 + Agriculture:Agriculture + Examination:Examination + Education:Education + Catholic:Catholic + Infant.Mortality:Infant.Mortality,lower=~1),direction="both",trace=1)

This command works for the interactions, but it completely ignores the quadratic terms. I also tried :


steplm<-step(lm(Fertility ~1, data = swiss),scope=list(upper=~(Agriculture+Examination+Education+Catholic+Infant.Mortality)^2 + I(Agriculture^2) + I(Examination^2) + I(Education^2) + I(Catholic^2) + I(Infant.Mortality^2),lower=~1),direction="both",trace=1)

With this last command, the hierarchy for the quadratic terms is not respected.

In summary, I don't know how to tell R to respect the hierarchy for the quadratic terms in the selection process. Does anyone know how to do this?

Many thanks,

Sophie

	[[alternative HTML version deleted]]

