0
$\begingroup$

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. part of dataset head(dataset)

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 addition: Warning message:
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.

$\endgroup$
  • $\begingroup$ 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'). $\endgroup$ – Kunio Aug 6 '18 at 2:23
  • $\begingroup$ That made the TUkeyHSD function work! Thanks. I'll add the head() to the original post. $\endgroup$ – BiologyStudent Aug 6 '18 at 9:19
1
$\begingroup$

Just include the numeric predictor with the factor covariates in the linear model and do the anova.

Also in R syntax you can just put in Sex*Place instead of Sex + Place + Sex:Place.

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).

What I think is going on is you probably have sex encoded directly as a numeric dummy variable (ie 0 = female , 1= male) or as a character string maybe. Once you have it defined as a factor you should be able to get the post-hoc comparisons. Do note that Tukey's HSD ignores non-factor variables, so I think the results for Tukey's HSD may ignore the fact that it's an ANCOVA.

Also see the answers in this question about ANCOVA.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.