1
$\begingroup$

I am not sure the title is easy to understand, but this is because I'm struggling to find out if my question is machine-learning related, or just correlation-related, or anything else.

Context: I have a categorical variable that can take three values. And 75 samples, 25 per category. On top of knowing what the category is, I have continuous variables for each sample. The goal is not to build a predictor; the goal is to determine if there is correlation between the categorical variable and one of the continuous variables because there are good (non mathematical ones) reasons to believe that there is a causation effect (the continuous variable causing the categorical one, I'm not sure if it is useful to know the direction of the causation effect when conducting such a correlation analysis but I'm including it just in case - I'll happily read anything on that matter as I'm very eager to fully understand what I'm doing). Finally, I should add that it would make more sense that we only choose one continuous variable to predict the categorical one (they all represent the same physical stuff but just from different machines for example - although I guess using the outputs of several machines could in theory help, I think the sample size is too low to see this and I fear overfitting).

My first idea was to plot boxplots (c.f. below, not my data, but 3 categories and a continuous variable on the plot as I do) for each continuous variable (so I'll end with dozens of boxplots). And then pick the one variable that would lead to boxplots being the most different (the example I've given is an example of a "bad continuous variable"). But I don't really have a "metric" when it comes to measuring "the difference" of boxplots. Is there one? I've googled some stuff and just found "rules of thumbs" on how to "compare boxplots with the eye" e.g.:

  • Compare the respective medians, to compare location.
  • Compare the interquartile ranges (that is, the box lengths), to compare dispersion.
  • Look at the overall spread as shown by the adjacent values. (This is another aspect of dispersion.)
  • Look for signs of skewness. If the data do not appear to be symmetric, does each batch show the same kind of asymmetry?
  • Look for potential outliers. This doesn't seem very rigorous because I, the human, would have to make the final decision as to what variable makes the 3 most different boxplots.

enter image description here

Furthermore, all of this looks a bit flawed because I'm not considering the fact that several continuous variables together might help predicting the categorical one. However, my variables being pretty correlated, my sample size pretty low and the predicted variable being quite subject to variability (as in, I'm expecting one continuous variable to be just a little bit helpful at distinguishing what category the sample is in, meaning, I don't have a problem where I will end up with high accuracy), I figured that doing some sort of machine learning stuff (random forest + cross-validation + feature importance) was not going to be the best path.

$\endgroup$

1 Answer 1

1
$\begingroup$

Your idea of looking at boxplots can be formalized as a F-test on a linear model regressing the category on each continuous variable in turn.

For example, here's a dataset in which x is not related with the category, while y distinguishes category 3 from the other two:

n <- 25
df <- rbind(
  data.frame(cat=1, x=rnorm(n, 0), y=rnorm(n, 0)),
  data.frame(cat=2, x=rnorm(n, 0), y=rnorm(n, 0)),
  data.frame(cat=3, x=rnorm(n, 0), y=rnorm(n, 1))
)
df$cat <- as.factor(df$cat)

Fitting a model on y and conducting the F-test:

> summary(lm(y ~ cat, df))
...

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept)  0.06571    0.20798   0.316  0.75295   
cat2        -0.07065    0.29412  -0.240  0.81084   
cat3         0.88950    0.29412   3.024  0.00345 **

...
F-statistic:  6.62 on 2 and 72 DF,  p-value: 0.002295

The "F-statistic" is testing the null hypothesis that all coefficients are zero against the alternative that at least one is non-zero. Fitting a similar model on x ~ cat results in a non-significant F-test.

If you are rather interested in finding a case where all categories can be separated by a single variable you would need to find a case in which all coefficients are significantly different from zero (and each other).

Also, you may want to perform some adjustment for multiple hypothesis testing if you are comparing "many" p-values.

$\endgroup$
10
  • $\begingroup$ Thanks for the answer and the examples. I know a bit about adjusted p-value but is it applicable here? It says here (analytics-toolkit.com/glossary/p-value-adjustment) "A p-value adjustment is necessary when one performs multiple comparisons or multiple testing in a more general sense: performing multiple tests of significance where only one significant result will lead to the rejection of an overall hypothesis.". Is our "overall hypothesis" here "no continuous variable is related to the categorical one"? $\endgroup$ Commented Apr 26, 2022 at 21:32
  • $\begingroup$ Also, I'm not really familiar with the F-test (why does it appear when you're fitting a linear model) - after some research it seems it tests if the variances are the same but what variances are we talking about ? $\endgroup$ Commented Apr 26, 2022 at 21:45
  • $\begingroup$ If my boxplot are offset (not the same mean/median) but with the same variance, I would want the test to say that the continuous variable is related to the categorical one. Because you only change the mean of y in your example I guess this isn't the variance we're comparing so I'm a bit confused about this (admitedly I probably should understand it fully because it's the fundamentals but it looks like I haven't mastered them) $\endgroup$ Commented Apr 26, 2022 at 21:45
  • 1
    $\begingroup$ @FluidMechanicsPotentialFlows yes, the "overall hypothesis" is "no continuous variable is related to the categorical one", and you need to correct because you are conducting a separate test for each variable. The F-test compares the variance of the response variable y with the variance of the residuals of the model y~cat. If the latter is smaller it means that cat has predictive power (ie, it reduces variance) $\endgroup$
    – BlackBear
    Commented Apr 27, 2022 at 8:01
  • 1
    $\begingroup$ The problem was set up for multinomial logistic regression. Everything else is just a detour. Note that for binary Y the minimum sample size needed if there are zero features to learn about is $n=96$. That is the sample size that yields a margin of error of no more than 0.1 in estimating a probability. If there were binary Y and one binary X the needed sample size is 2 $\times$ 96. For 3-category Y the sample size needs are larger (at least when Y is unordered). $\endgroup$ Commented Apr 27, 2022 at 11:29

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.