Hi Will, Quick answer to that question: yes.
The key is that categorical variables cannot be modeled directly in a GLM framework. These categorical variables, or index variables, are transformed into n x (k - 1) matrices of index variables. These index variables are binary where a 1 corresponds to the observed having that state. K is the number of states in the index variable. Only k - 1 columns are necessary because the intercept of the model corresponds to the remaining state. The interpretation of the beta coefficients for each of the (k - 1) predictors are then their contrast to or difference between that state and the state "held" by the intercept. R will do this silently when you fit the model. If all k states are included while also including an intercept term, the model becomes unidentifiable because you've effectively included two intercept terms which are additively non-identifiable. I hope that makes sense. Cheers, Peter On Wed, Feb 4, 2015 at 5:20 PM, William Gearty <wgea...@stanford.edu> wrote: > Hi Liam, > > Thanks for the help! > Does this type of linear model work if X1 and X2 are categorical variables? > > -Will > > On Wed, Feb 4, 2015 at 2:48 PM, Liam J. Revell <liam.rev...@umb.edu> > wrote: > > > Hi William. > > > > You should be able to fit this kind of model using gls in the nlme > > package. In your case, this would look something like: > > > > library(ape) > > library(nlme) > > fit<-gls(Y~X1*X2,data,correlation=corBrownian(1,tree)) > > anova(fit) > > > > for instance. This is just a linear model with multiple predictors and > > residual error that is correlated according to the phylogeny. > > > > If you search R-sig-phylo for gls and/or nlme, or search the web for GLS > > and phylogenies, you should be able to find out more info. > > > > All the best, Liam > > > > Liam J. Revell, Assistant Professor of Biology > > University of Massachusetts Boston > > web: http://faculty.umb.edu/liam.revell/ > > email: liam.rev...@umb.edu > > blog: http://blog.phytools.org > > > > > > On 2/4/2015 5:38 PM, William Gearty wrote: > > > >> Apologies if this has been asked before... > >> I'm trying to perform a phylogenetic ANOVA with multiple predictors. > >> I'm able to do a normal ANOVA with multiple predictors like this: > >> > >> aov(Y ~ X1 * X2, data) > >>> > >> > >> However, I'd like to account for phylogenetic relatedness and tried > doing > >> something similar with aov.phylo: > >> > >> aov(Y ~ X1 * X2, phy) > >>> > >> > >> However, the function yells at me: > >> > >> 'formula' must be of the form 'dat~group', where 'group' is a named > >>> factor > >>> vector and 'dat' is a data matrix or named vector > >>> > >>> Therefore, it seems like aov.phylo is not built to perform a > >> multi-predictor analysis like the normal aov function is. > >> Are there any similar functions that would be able pull this off? Is > there > >> way around this with aov.phylo? > >> Any thoughts would be greatly appreciated, > >> Will > >> > >> > > > -- > William Gearty > PhD Student, Paleobiology > Department of Geological and Environmental Sciences > Stanford School of Earth Sciences > people.stanford.edu/wgearty > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at > http://www.mail-archive.com/r-sig-phylo@r-project.org/ > -- Peter D Smits Grad student Committee on Evolutionary Biology University of Chicago psm...@uchicago.edu http://home.uchicago.edu/~psmits/home.html [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/