# Alternatives to Chi-Squared for Single Categorical Outcome and Single Categorical Predictor w/counts for factors [R]

I am from an applied background, where X2 and G-tests are the default ways to analyze count data (default as in, until today, I had no idea there were other ways, as I was only taught these methods). However, now that I see there are model-based approaches, I would like to analyze my data in this fashion (if possible).

The data is in a contingency table, and the first column is an individual. Each of cells in the next five columns has a count for something, such as a clothing type. Thus, I have something like

Person    Jeans    Collar.Shirt     Mini.Skirt     Maxi.Skirt     Tank.Top
1               5          10                4               2            7
2               7           5                12              5            15
3               15          7                10              10           8
4               6           7                3               11           17


If I consider my first column a response variable, and the next five as predictors, I should, in theory, be able to do some type of regression. However, for this, it seems that since clothing types are all clothes, I end up with a single predictor, with counts as each level of a factor.

Because I have more outcomes than predictors, assuming I consider each its on IV, a multinomial logistic regression is going to end up with a lot of empty values, making this (in my mind, anyhow) inappropriate.

That leaves me with, as far as I know, Poisson and negative binomial regression.

When I attempted, in R, a NB model, using MASS on the wide-format table above, I get an error.

This is the code I used for the NB:

summary(NB <- glm.nb(Person ~ Jeans + Collar.Shirt + Mini.Skirt + Maxi.Skirt + Tank.Top, data = d))


This is the error:

 Warning messages:
1: In theta.ml(Y, mu, sum(w), w, limit = control$maxit, trace = control$trace >  :  iteration limit reached
2: In theta.ml(Y, mu, sum(w), w, limit = control$maxit, trace = control$trace >  :  iteration limit reached


When I do Poisson for this same dataframe, I do get results. Nothing significant, other than the Null...and each of the IV's have Z=0 and p=1. The Null Deviance is 10.3 and the Residual is 0.4. As I understand it, since the Residual is quite low, this model, as insignificant as it may be, does well at explaining the data. However, it seems inappropriate to use this model, given I technically have factors of a single predictor.

So, if I reshape the data into a long format, so that it looks like:

Person    Clothing         Count
1               Jeans             5
1               Mini.Skirt        4
1               Maxi.Skirt        2
1               Tank.Top          7
2               Jeans             7
...             ...               ...


where there are now five factors for the predictor "clothing" and counts of each item for "count",

and run the code for NB:

summary(NB2 <- glm.nb(Person ~ Clothing, data = d))


or run the code for Poisson:

summary(pois2 <- glm(Person ~ Clothing, family = poisson, data = d))


my Null and Residual Deviance values are the same (for both). This indicates a problem, I would think.

So, this all being said...Is there a way to do this, or am I stuck with my old standby??

Thank you!

• Welcome. I don't think I am the guy who can answer, but for the others : How your dataset looks like is not really clear, could you edit your question by giving us some rows and tell us what the variables are. Maybe giving the exact formula you typed in R could help too. – brumar Jul 5 '15 at 7:46
• Made edits. Let me know if it's still unclear. – BeyondApplied Jul 5 '15 at 8:40

Thanks for the edit ! This is much better ! Now I may see a part of the problem. I guessed $Person$ is the same as $Individual$. I think that in your mind, by analogy with the chi2 test, Person ~ Clothing represents the association between Individuals and Clothing. But as far as I know, it does not work like that. The response variable (at the left of the ~) is want you want to predict, what we call the response term. So in your case, you would prefer sthg along the line of Count~ Individual+Clothing. But you are looking for an interaction with Individual and Clothing, so Count~ Individual*Clothing, including all the interactions terms is more close from what you want.