# How do I perform an ANCOVA ? (master thesis deadline) [closed]

My dataset consists of several morphological measurements for 5 island populations of a certain lizard species. I want to test for each population if there is a significant difference in the measurements between males and females (sexual dimorphism or SD). Additionally I want to test whether there is a significant difference in the magnitude of SD between the populations.

My professor said I should do an ANOVA in R with sex and population as factors. This is my code:

lm3 <- lm(logSVL ~ sex + Place + sex:Place)


For the morphological measurement SVL (general indication of body size) I see a significant effect of sex and population (both p<0.0001) and no significant interaction between sex and population (p=0.5). When I try to look at two by two differences in population (I guess this is how I see if there is a significant difference between each population) with this code:

TukeyHSD(aov(logSVL ~ Place + sex))


I get the next error:

Error in rep.int(n, length(means)) : unimplemented type 'NULL' in 'rep3'
In replications(paste("~", xx), data = mf) : non-factors ignored: sex


What did I do wrong?

My professor also said that an ANCOVA with SVL as covariate might be more correct than an ANOVA. I tried an ANCOVA as follows:

lm1 <- lm(logSVL ~ Place + sex + sex:Place)


My handbook for R said that I should then do several tests like summary(lm1), coef(lm1) but I don't know how to interpret the output. I also don't know how to check if all the assumptions are met, the handbook is a bit confusing.

Did I do the ANOVA and ANCOVA right? If no, what did I do wrong? Is ANCOVA really better in my case? My thesis is due to the 13th, I know it's a lot of questions but I really hope someone can/wants to help me. Thanks anyway.

• Could you give us a 'head()' output of your data.frame? Sex may not be coded approriately, and that's why you're getting an error, based on the error code. For the TukeyHSD, you'd also want to include what comparison is of interest by adding the variable using quotes "Place" after your aov() function: TukeyHSD(aov(logSVL~Place+sex),'Place'). – Kunio Aug 6 '18 at 2:23
• That made the TUkeyHSD function work! Thanks. I'll add the head() to the original post. – BiologyStudent Aug 6 '18 at 9:19

For sex, check to see if it's a factor with is.factor(data$sex) and if not coerce it with data$sex <- as.factor(data\$sex).