Applying the Chi-Squared Test to Animal Behavior

Davida Rosenstrauch
9 min readDec 1, 2020

Years ago, this pre-data-scientist was a college student and pre-veterinarian. I may not remember anything about the molecular biology pre-requisite courses that ended up being for naught once I decided to switch tracks, but one class that does stick with me was the one in which I conducted animal behavioral research at the Saint Louis Zoo. Over a two-month period I spent 40 hours observing Tembo and Haji, the two spotted hyenas (Crocuta crocuta) in captivity at the zoo.

Group of spotted hyena cubs
They get a bad rap, but look how cute!

Background

I could write an entire blog post about the biology and social structures of spotted hyenas, but this is a data science post, so I’ll save that in case the veterinarian thing every comes up again. For now, I’ll just focus on the points most relevant to our data today, and frankly, the ones I find most interesting. In the wild, spotted hyenas live in female-dominated societies. This is evidenced in several structural ways, such as the fact that females stay in their same approximately-90-indivdual clan for their entire lives whereas males all emigrate to new clans after reaching maturity, the fact that females have best access to limited food resources within their clans, and more. Female Crocuta are also physically larger and more aggressive than males.

Feel free to reach out (or Google, or stand outside in the dead of winter taking notes in a zoo) if you want to learn more about female dominance in spotted hyenas, but for now I’ll say one more thing: one main behavior that is often pointed to by researchers in the wild are how often spotted hyenas approach individuals of the other sex, and how those being approached react. In the wild, females very rarely approach males, and when males approach them they often react aggressively or with no response at all. All of these are further evidence of female dominance in Crocuta societies, and the area of my research that I will be highlighting here.

Methods

Data was collected from February through April of 2013 at the Saint Louis Zoo. Two hyenas, one of each sex, both six years old at the time and born in the same litter, were observed over 40 hours. Data highlighted below was collected via all-occurrence sampling, in which I recorded every occurrence of male- or female-dominant behavior.

Tembo and Haji in their enclosure at the Saint Louis Zoo
Tembo and Haji in their enclosure at the Saint Louis Zoo

Results

As noted above, in the wild, female Crocuta very rarely approach males. In this captivity study, I observed more male-to-female approaches than vice versa, but not as wide a gap as I expected. Out of 51 total approaches, the male approached the female 31 times, and the inverse was true 20 times. These correspond to 61% and 39% of observed approaches respectively.

A bar graph with x-axis “Individual Being Approached” and y-axis is “Number of Approaches.” F bar is at 31 and M bar at 20.

Response to being approached is also an important marker of dominance in spotted hyenas. In my research I characterized each response as one of four categorical markers: fear, greeting, aggression, or no response. Examples of a fearful response include yelping or jumping away. A greeting response is represented by the typical Crocuta greeting ritual, which includes lifting a hind leg and sniffing or licking each other’s anogenital regions. Aggressive responses include growling and snarling. Of these four categories, fear and greeting are more likely to be displayed by a submissive individual, while aggression and lack of response more likely displayed by a dominant individual.

Similar to the proportion of approaches, the behavior observed in the zoo, represented below, seems to indicate female dominance, but not as starkly as research has shown in the wild. For example, the female showed zero fearful reactions and the male showed zero aggressive reactions, which are both consistent with female dominance. However, the male also showed no response to the female 48% of the times he was approached, which is typically a more likely response from a female to a male in the wild. Similarly, female Crocuta in the wild rarely participate in the typical greeting ritual, but this data shows that the one at the Saint Louis Zoo did so 23% of the times she was approached.

Bar graph with x-axis “Reactions” and y-axis “% of Occurrences.” Each reaction category has a F bar and M bar.

Enter the Chi-Squared Test

When I first analyzed this data in 2013, I saw the above bar chart of approach responses and decided that it did indeed indicate female dominance between these two hyenas. But since there are anomalies compared to what we’d expect to see, this time around I decided to conduct a chi-squared test to be sure.

A chi-squared test tests the relationship between categorical variables. In our case, our null hypothesis is that which individual is being approached has no impact on the likelihood of approach reaction. In other words, that we are equally likely to see an aggressive reaction if the female is approaching the male or vice versa, and so forth for each reaction category. We will calculate this with 95% confidence.

But how to calculate?

The short answer is by using some pretty simple code. But first, the manual version!

Here is a table that shows us how many times each hyena responded with each of our response categories:

Table with column labels F, M, Total, row labels Fear, Greeting, Aggression, No Response, Total and corresponding values.

Our observed values (O) are the values we observed as outlined in the table above, but our expected values (E) correspond to an equal percentage distribution between each individual for each category. For example, if we know that there were 4 examples of a fearful response, we would expect this to be split between the male and the female in accordance with their number of times being approached. Namely, we’d expect the female to respond fearfully (31/51) * 4 times and the male to respond fearfully (20/51) * 4 times. In other words, we’d expect each of those percentage bars in the last bar chart to be equal, which would correspond to different raw numbers of occurrences. We can apply this reasoning to each response category. Remember that our null hypothesis was that there was no difference in the hyenas’ responses, so we’re assuming, or expecting, that the number of approaches they had to respond to will be the only thing making a difference in their number of responses. We can therefore expand our table as such:

Same column and row heads as prev table, but now values include both observed and expected values.

And now the moment we’ve all been waiting for: calculating the chi-squared statistic. By using our above O and E values, and the below formula,

Chi-squared = the summation of (O minus E) squared over E

we end up with a chi-squared value of:

2.4314 + 3.7688 + 0.1030 + 0.1596 + 2.2770 + 3.5294 + 0.0025 + 0.0039 = 12.28

To determine the critical value, first calculate our degrees of freedom, which equals (number of rows — 1) * (number of columns -1). In our case, we have 3 * 1 = 3 degrees of freedom. With this information, and knowing that we want a significance level of 0.05 for 95% confidence, check out this handy table and determine our critical value. Spoiler alert: it’s 7.8147. Since our chi-squared statistic value of 12.28 is higher than this, it falls in the rejection region and we know we can reject our null hypothesis. In other words, we reject, with 95% confidence, the hypothesis that there is no difference in approach responses between our two hyenas.

Looking at the coded version of this chi-squared test, which I’ve included below, we also see that our p value is 0.006, which indicates that we will reject the null hypothesis since it is below our 5% significance level. This also confirms that our calculation of our critical value and chi-squared statistic were both correct (whew, that would have been awkward).

Why it Matters

What a wild ride we’ve been on together. Personal history? Check. Zoology tidbits? You betcha. Statistics? Yep, got those in too (which is good because, well, this is really a data science blog post). But what’s the point?

You, laughing at my witticisms. Did you really thing you’d get this far without a Lion King reference?
Alternatively, me laughing at my own witticisms and you just waiting for me to get back to math.

As I’ve alluded to throughout this post, while evidence of female dominance in spotted hyenas can be observed in captivity, it is much more apparent in the wild. This has been the case in much wider-ranging research than mine (Wider than 40 hours-worth of data with 2 individuals? Shocking, I know). It can be tempting to see approach reaction data like the ones I shared and, knowing what we know about hyenas in the wild, extrapolate that this is significant evidence of female dominance. But with nebulous areas like almost-equal proportions of a lack of response, or unusually high greeting rate from the female, this is hard to know for sure without statistical testing. In our case, our chi-squared test confirmed our suspicion that there was a statistically significant difference in the response from each of our individuals. With our sample size of only one individual per sex, we can’t necessarily exclusively relate this back to sex (maybe it’s a personality thing!), but knowing what we do about prior research on Crocuta crocuta in both captivity and the wild, it seems like a safe bet.

One more dose of cute as a reward for making it to the end

Resources

On Chi-Squared Testing

On Hyenas

Boydston EE, Kpheim KM, Szykman M, Holekamp KE (2003). Individual variation in space use by female spotted hyenas. Journal of Mammaloloy 84: 1006–1018.

East ML, Burke T, Wihelm K, Greig C, Hofer H (2003). Sexual conflicts in spotted hyenas: male and female mating tactics and their reproductive outcome with respect to age, social status and tenure. Proceedings: Biological Sciences 270: 1247–1254.

East ML, Hofer H, Wickler, W (1993). The erect ‘penis’ is a flag of submission in a female-dominated society: greetings in Serengeti spotted hyenas. Behavioral Ecology and Sociobiology 33: 355–370.

“Hyena.” The Columbia Encyclopedia, 6th ed. 2013. Retrieved March 16, 2013 from Encyclopedia.com: http://www.encyclopedia.com/doc/1E1-hyena.html

Holekamp KE, Sakai ST, Lundrigan BL (2007). The spotted hyena (Crocuta crocuta) as a model system for study of the evolution of intelligence. Journal of Mammalology. 88: 545–554.

Kappeler, PM (1993). Female dominance in primates and other mammals. Perspectives in Ethology: Volume 10: Behavior and Evolution 5: 143–158.

Kolowski JM, Katan D, Theis, KR, Holekamp KE (2007). Daily patterns of activity in the spotted hyena. Journal of Mammalology. 88: 1017–1028.

Owen P (2001). “Crocuta crocuta.” Digital Morphology. Retrieved March 18, 2013 from http://digimorph.org/specimens/Crocuta_crocuta/.

Pickrell J (2002). Rebranding the Hyena. Science News. 161: 267–269.

Smuts BB, Smuts RW (1993). Male aggression and sexual coercion of females in nonhuman primates and other mammals: evidence and theoretical implications. Advances in the Study of Behavior 22: 1–63.

“Spotted Hyaena (Crocuta crocuta).” IUCN Hyaena Specialist Group. Retrieved March 18, 2013 from http://www.hyaenidae.org/the-hyaenidae/spotted-hyena-crocuta- crocuta.html

“Spotted Hyena.” National Geographic. Retrieved March 18, 2013 from http://animals.nationalgeographic.com/animals/mammals/hyena/#

Szykman M, Engh AL, Van Horn RC, Funk SM, Scribner KT, Holekamp KE (2001). Association patterns among male and female spotted hyenas (crocuta crocuta) reflect male mate choice. Behavioral Ecology and Sociobiology. 50: 231–238.

Szykman M, Van Horn RC, Engh AL, Boydston EE, Holekamp KE (2007). Courtship and mating in free-living spotted hyenas. Behaviour. 144: 815–846.

Van Horn RC, McElhinny TL, Holekamp KE (2003). Age estimation and dispersal in the spotted hyena (Crocuta crocuta). Journal of Mammalology. 84: 1019–1030.

Watts HE, Holekamp KE (2009). Ecological determinants of survival and reproduction in the spotted hyena. Journal of Mammalology 90: 461–471.

Watts HE, Tanner JB, Lundrigan BL, Holekamp KE (2009). Post-weaning maternal effects and the evolution of female dominance in the spotted hyena. Proceedings: Biological Sciences 276: 2291–2298.

--

--