0
$\begingroup$

I'm building a model and trying to get the relationship between two multi-level categorical variables.

For example, I want to know the relationship between race and likelihood of graduate from collage, we have 5 races and YES or NO for graduation. How to find the which race have higher likelihood or which have lower?

Thanks

$\endgroup$
1
  • 1
    $\begingroup$ Can we see the data please? $\endgroup$
    – JahKnows
    Commented May 4, 2019 at 5:51

5 Answers 5

1
$\begingroup$

Traditional statistics like Chi-squared tests and Cramer's V can be used to determine relationship between two categorical features.

$\endgroup$
0
$\begingroup$

It can be a logistic regression, with Graduation as a binary dependent variable (1 for Yes and 0 for No) and Race as independent. You would encode Race as five separate dummy (1/0) variables, with each subject in your dataset having a 1 in one of those variables and 0 in the other four. Then you would run the regression with one of those five dummies omitted from the regression as the reference category. You would use the output to draw conclusions, such as odds of graduating for students of race A are X% higher than the odds for students of Race B.

$\endgroup$
2
  • $\begingroup$ If Graduation wasn't binary, would you still use log. reg.? $\endgroup$
    – jiggunjer
    Commented Jun 3, 2019 at 10:26
  • $\begingroup$ @jiggunjer It depends. I recommend you ask a separate question, providing specifics about your data and research question. $\endgroup$
    – AlexK
    Commented Jun 3, 2019 at 15:50
0
$\begingroup$

There is a Scikit-Learn module "LogisticRegression" which will easily perform this calculation (albeit its only for Python not R, which might be a problem). The advantage of Scikit is that if you wanted to perform a linear SVC ... its easy because it is just another module. Furthermore, if you wanted to assess the data within an ML framework, its an easy extension. Again, you would need to learn a bit of Python to import your data.

$\endgroup$
0
$\begingroup$

As bradS mentioned, you can use Cramers_V.

def cramers_v(confusion_matrix):
    """ calculate Cramers V statistic for categorial-categorial association.
        uses correction from Bergsma and Wicher,
        Journal of the Korean Statistical Society 42 (2013): 323-328
    """
    chi2 = ss.chi2_contingency(confusion_matrix)[0]
    n = confusion_matrix.sum()
    phi2 = chi2 / n
    r, k = confusion_matrix.shape
    phi2corr = max(0, phi2 - ((k-1)*(r-1))/(n-1))
    rcorr = r - ((r-1)**2)/(n-1)
    kcorr = k - ((k-1)**2)/(n-1)
    return np.sqrt(phi2corr / min((kcorr-1), (rcorr-1)))
$\endgroup$
-1
$\begingroup$

One suggestion is to label encoding on these categorical variables and find the correlation. Or I believe we can use count plot for the same.

$\endgroup$
1
  • $\begingroup$ you don't need encoding to find correlation $\endgroup$
    – Blenz
    Commented Jun 3, 2019 at 12:03

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.