Dear all, I would like to know how to run an analysis of covariance in R. For example, I have a data frame ("data") consisting of two second-degree categorical variables ("diagnosis" and "gender"), one continous independent variable ("age") and one continous dependent variable ("response"). I ran a simple anova to see the effects of diagnosis and gender (and interaction): aov.out <- aov(response~diagnosis*gender,data) anova(aov.out) Now I would like to covary for age, how can I add "age" as a covariate to this equation? Thanks, Sasha
> aov.out <- aov(response~diagnosis*gender,data)Just add it where you think it belongs in the sequential sum of squares To adjust the factors for the covariate use aov.out <- aov(response ~ age + diagnosis*gender, data) To adjust the covariate for the factors aov.out <- aov(response ~ diagnosis*gender + age, data) If you want to check for interaction of the factors with the covariate, then use * instead of + in the formula. Please note that I added spaces to your statement to improve human legibility. Rich
> But how is that different from just a 3-way ANOVA with age, diagnosis, > and gender as the the three effects? Isn't ANCOVA a fundamentally > different model?> Thanks, > SashaANCOVA is a linear model with both factors and continuous variables on the right-hand side of the model formula. In pre-computer texts, the commonly used algorithm hid that fact. Rich