2
$\begingroup$

I am working with a data set with 3000+ rows. The response variable p is binary (1 representing purchase of a specific item, 0 representing no purchase) and I have 10 explanatory variables. Of these, most are binary categorical variables or continuous, but 2 are ordinal. These are:

  • owned: number of the item already owned (with values 0,1,2,...,7)
  • visits: number of times visiting the store (with values 0,1,2,...,5).

Within my data, I have < 100 observations for levels 5, 6 and 7 of owned (level 7 has only 2 observations) and < 60 for levels 3, 4 and 5 of visits. I have to perform a logistic linear regression with the data.

My first instinct was to treat these variables as factors, however on looking at the glm summary factors based model I can see that the p values are large for the dummy variables representing levels with few data points. Also, the factors have quite a lot of levels, leading to large parameter numbers.

I am wondering if it's acceptable to instead use the actual data with the values (eg treating them like continuous variables rather than as factors), or if this would be statistically incorrect since non whole values don't make sense in this context? I performed a test comparing these two models of $$H_0: \beta_{\text{owned2}} = 2\beta_{\text{owned1}}, ..., \beta_{\text{owned7}}=7\beta_{\text{owned1}} \text{ and } \beta_{\text{visits2}} = 2\beta_{\text{visits1}}, ..., \beta_{\text{visits5}}=5\beta_{\text{visits1}}$$ against the general alternative and got a non significant p value, suggesting the non factor / restricted model couldn't be rejected.

Alternatively I was also considering merging some of the data categories (eg making them binary or making the categories intervals), however this approach seemed like it might reduce the amount of information I had. I could also for example remove the level 7 observations since there are so few.

So in summary, should I treat this data as factors (using owned <- as.factor(owned) etc within the glm) or not, and if so how can I statistically justify doing so? Or is there some other approach I am missing?

$\endgroup$
1

1 Answer 1

0
$\begingroup$

I don't see why integers as explanatory variables should cause any issues when treated as continuous in a logistic regression. Note that your variables are counts, as opposed to the variables in each of the questions linked by @kjetilbhalvorsen. The main thing to be worried about is the same for any continuous variable in logistic regression: is the response log-odds linear in the predictor? Your test seems to suggest that in this case that's not a bad assumption, except that you don't appear to have done anything to check zero counts, which in context seems to be the most likely to not fit into the same relationship as the other values.

If you decide the relationship isn't linear enough, then treating them as factors, or fitting splines/polynomials as @kjetilbhalvorsen suggests in a comment, or some other transformation, all sound like good approaches; the latter approaches should reduce the problem of the large counts being uncommon. If the positive values look good for a linear fit but zero does not, maybe just adding an indicator "is 0" variable would suffice.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.