Let's say I'm measuring the occurrence of yellow or blue beetles at 8 sites in a study area, and I selected these sites such that 4 are on the edges of lakes, and 4 are in meadows. I'm testing to see if there is a difference between lakes and meadows for dominant beetle colour.
So, I can approach this like a normal chi-squared test: come up with the frequency of blue beetles near lakes and in meadows, then compare to see if there's a meaningful difference between these two.
But, what if it turns out there are other properties of the sites that could predict whether beetles are more likely to be blue or yellow, other than the site's location in a meadow or on a lake edge. How do I test for independence between sites while also testing for independence between treatments (lake vs meadow)? In other words, how can I control for possible (real) differences between sites while also testing for differences between lakes & meadows?
I can't find a good way to do this without doing two consecutive tests - and therefore having to risk an increased chance of a false positive.