# Can I do an ANOVA while controlling for a categorical variable (an ANCOVA except the covariate is categorical)

I'm looking at nesting differences between 3 species of fish. These fish nest in colonies (all 3 species intermix in the colonies), and measurements were taken at several different colonies throughout the lake. I am wanting to see how continuous variables such as nest depth vary between the 3 species. Depth also varies between colony, but I do not care about this difference. Is there a way I can investigate differences in nest depth between species, while controlling for the underlying differences in nest depth between colonies? Thanks!

In R syntax that could then look like lm( depth ~ 0 + factor(colony) + factor(species)) or lm( log_depth ~ 0 + factor(colony) + factor(species)). The syntax I used assumes you did not already declare in your dataframe or tibble that colony and species are categorical factors rather than numerical data, in which case you could omit the factor() around the variables. 0+ just means I don't want an intercept, but you could also get any comparisons you want if you had an intercept. Just about any other statistical software should be able to fit such a model, too. You'd be asking how much each species is off from the depth of the colony, you could argue that you're assuming that it's always to the same extent across all colonies or at least that you're asking for an answer as if that were the case (and it made sense to just average while controlling for the colony depth).
You can then look at the coefficients for the different species and/or ask for comparisons (each software will have its own ways of specifying what you want e.g. with the emmeans R package, with the LSMEANS statement in SAS etc.).