# How to regress two categorical variables

I'm not looking for a detailed answer, just some pointers towards possible things I could read to better understand this problem.

Let's say that we have a survey that asks two questions, $X$ and $Y$. How do you regress $Y$ against $X$? I know that if $Y$ is binary you can use logistic regression, but generally, how do you regress an unordered $Y$ against an unordered $X$? Ordered $Y$ against unordered $X$? Unordered $Y$ against ordered $X$? Ordered $Y$ against Ordered $X$?

I'm working on some survey analysis software, and in it I attempt to predict $Y$ with $X$ using the following method:

Suppose $X$ has $X_1,\cdots, X_n$ responses, and $Y$ has $Y_1,\cdots,Y_m$ responses. Then I calculate a matrix, where the $[i,j]$ element is $\mathbb{P}(Y_i|X_j)$. I then have the user enter in a hypothetical response distribution for $X$ (so new $X_1,\cdots, X_n$, call it $X_{new_1},\cdots,X_{new_n}$). Then if you multiply the matrix by this column vector, you get a new distribution for the $Y$ response variable.

I'm really not sure how good this method is, and I was very careful to propagate error with each operation (each $\mathbb{P}(Y_i|X_j)$ has a confidence interval) to try not to mislead people, but I came up with this method on my own and it seems too simple.

## 1 Answer

There are a number of variants of logistic regression. If your Y variable has just two levels, you can use the standard version of LR. If you have more than two levels of Y, you can use multinomial LR if they are unordered, or ordinal LR if they are ordered.

The distribution of X variables does not affect the type of LR used. You can always represent categorical X variables with dummy codes (the most common type is reference level coding). If the levels of X are ordered, there are other coding schemes available, but they typically use the same number of degrees of freedom and only (in essence) display the output differently. You can also substitute real numbers for the levels (i.e., the mean of the underlying continuous variable for each level). This induces measurement error, but saves degrees of freedom. If you have some knowledge of the topic to ground your choices, the pros can outweigh the cons.

To learn more about these topics, try reading a book on logistic regression. Agresti's books are popular:

Short of reading a whole book, you can start with some of the threads on CV that discuss these topics. Here are a couple of searches, sorted by votes: