Basically, I have the data where I am trying to assess whether there is any correlation between the gender of the manager and the gender of people within their team. I decided to do the chi-squared test on these categorical data by counting the number of males and females within the team and then doing the test against the data for the manager.

However, there are many more male managers and employees within the dataset rather than females, which is why I believe I got skewed results at first. The challenge lies in the imbalance of males and females and the potential impact on analysis results. The goal is to balance the sample sizes between males and females, ensuring a fair comparison, and then calculating p-values to assess the significance of the relationship. I did that by using random sampling but my results when I plot them look kind of weird now.





My question is: did I do the right thing? I am kind of confused now on how to interpret these results :/

EDIT: Performing a chi-squared test using pd.crosstab to create a contingency table for manager_gender and the count of females or males (Count_Female or Count_Male) in a team. It calculates the chi-squared statistic and the p-value associated with the test. Then I am comparing the p-value to the significance level alpha to determine whether the correlation between manager_gender and the count of females or males is statistically significant.

data = {
    'manager_gender': ['female', 'male', 'female', 'male'],
    'Count_Female': [1, 3, 5, 1],
    'Count_Male': [3, 5, 1, 2]

Contingency table for females:


Contingency table for males:


  • 3
    $\begingroup$ Hi! It's a bit unclear what your data looks like, and on what you conducted the chi-squared test. Can you edit your question to provide a snippet of the data? An example of a table on which you conducted the chi-squared test would be useful. $\endgroup$
    – J-J-J
    Aug 20, 2023 at 23:02
  • $\begingroup$ @J-J-J this is a very rough example of what i am trying to do $\endgroup$ Aug 20, 2023 at 23:21
  • $\begingroup$ It's very hard to say what you should do based on "very rough examples". Also, you have a year variable. What's its role? $\endgroup$
    – Peter Flom
    Aug 20, 2023 at 23:41
  • $\begingroup$ Also, what is your plot? Year is on the x axis, but what is your p-value from? And what are the lines? $\endgroup$
    – Peter Flom
    Aug 20, 2023 at 23:43

1 Answer 1


I think your approach violates the independence assumption.

I would use manager_gender as a predictor, and the gender of each person within the team as a binary outcome. But you need to account for the fact that individuals are nested within teams, using either survey methods (clustering) or multilevel modeling. You also mention authors, not teams. I would use PyStan for this (I think).

Can a person be an author more than once? If so, it's going to be more difficult.

@Peter Flom said it regarding non-independence: Employees are nested within teams. Say you have four managers. 1 female, 3 male. Each male only hires males, each female only hires females. Each hires 50 people. With your analysis, the sample size will be 200, and it will be highly significant. However the effective sample size is 4 - the number of managers. Your p-value will be (very, very) wrong. This is an extreme example, to make the point, but because employees are nested within teams, you have violated independence and your p-value will be wrong (how wrong? Who knows.)

  • $\begingroup$ Thank you - sorry the authors were just poor wording on my side, I edited it now! $\endgroup$ Aug 20, 2023 at 23:35
  • $\begingroup$ can you elaborate on why I am violating the independence assumption? $\endgroup$ Aug 20, 2023 at 23:37
  • 2
    $\begingroup$ Employees are nested within teams. $\endgroup$
    – Peter Flom
    Aug 21, 2023 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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