A colleague asked the following:
"Is there a way to do a multiple stepwise regression on continuous data that incorporates phylogenetic information and selects the best model based on an AICc score?"
Although I myself had not done this before, I figured that stepwise regression with objects of class "gls" would likely be something that someone, somewhere, in the wide world of R would have thought of before - and this is indeed correct.
Here's a complete demo with simulation code.
First, simulate data. In this case, x1 and x3 have an effect on y, so they ought to be found in the final model - but x2 and x4 intentionally do not.
## simulate data (using phytools)
Now let's fit our model & run the stepwise regression method using AIC:
## run stepwise AIC (using MASS & nlme)
trace just controls the amount of information about the backward & forward stepwise procedure that is being run. If we want more, we should increase it.
Finally, here's a worked simulation with results:
> ## build model (using nlme)
> ## run stepwise AIC (using MASS & nlme)
Generalized least squares fit by maximum likelihood
Model: y ~ x1 + x3
(Intercept) x1 x3
-0.4952197 0.6882657 -0.5108970
Correlation Structure: corBrownian
Degrees of freedom: 26 total; 23 residual
Residual standard error: 0.594681
This is just about what we'd expect. Cool.