The typical way to handle this problem is to run a linear regression model, where sleep_hrs
is the response and gender
and time
are predictors. In your case, however, your predictors are categorical variables and thus performing a linear regression model boils down to performing an ANOVA test.
Since you are interested in the joint behaviour of gender
and time
, the two-way ANOVA is what you are looking for. I am not very familiar with python
, but in R
, assuming the dataset is mydata
, you can proceed this way.
Run
summary(aov(sleep_hrs ~ gender * time, data = mydata))
and look at the p-value (column Pr(>F)) of the row gender:time. If the p-value is low enough, say less than $0.01$ if you choose $\alpha=0.01$, then it means there is an interaction effect. That is to say, the four groups are statistically different in terms of mean sleep_hrs
.
Then look at the rows named gender
and time
. The associated p-value of gender
tells you if males have different mean sleep_hrs
with respect to females; by the same token, the p-value associated with time
tells you if the two time
groups have the same mean sleep_hrs
.
You should also take a look at the residuals of the model to make sure they satisfy the assumptions of the ANOVA test.