2
$\begingroup$

I have data with two categorical independent variables and one continuous dependent variable. I want to check for the independence between variables. What type of test will tell me whether they are independent or not? My data looks like this:

gender  time      sleep_hrs
male    day        5.5
female  day        7.40
male    night      9.30
female  night      10.5

I have four groups here:

  • male - day
  • male - night
  • female - day
  • female - night
$\endgroup$
4
  • $\begingroup$ Are you asking about independence between variables? $\endgroup$
    – utobi
    Commented Feb 10, 2023 at 20:17
  • $\begingroup$ @utobi Yes, exactly $\endgroup$ Commented Feb 10, 2023 at 20:18
  • $\begingroup$ You could consider a regression of sleep vs rest, possibly including also interactions. Are the measurements taken out repeatedly? $\endgroup$
    – utobi
    Commented Feb 10, 2023 at 20:21
  • $\begingroup$ sorry, I'm new to statistics and don't understand you a little bit. would you please elaborate more? $\endgroup$ Commented Feb 10, 2023 at 20:24

1 Answer 1

3
$\begingroup$

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.

$\endgroup$

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.