1
$\begingroup$

Is it a problem for linear regression (lm in R) to have observations that have multiple values for a given factor? For example, I have the weekly average sales Y for many products and for each product I have information about the color (X1), technology (X2), design (X3). With these three categorical variables, I want to see which might be indicative of higher / lower average weekly sales (Y).

Is it a problem if products can take on several values in a factor? For example, suppose there are 20 different colors (X1) across all products and that product ABC comes in three colors, 5 technologies X2 and 2 designs X3.

Can I handle this with OLS / linear regression using LM in R, or will I get wrong results?

Also, it is not a problem that all my predictor variables are categorical, correct?

$\endgroup$
  • 1
    $\begingroup$ There is nothing inherently wrong with having multiple levels in a factor, however keep in mind that increasing factor levels means you will need larger and larger samples to cover all the possible combinations and obtain a good power. I don't know how big your sample is, but 20 colors seems... a little big. $\endgroup$ – user2974951 Feb 6 at 11:28
  • $\begingroup$ I have 5 factors in total in my real situation. The factors have 5, 3, 14, 26, and 18 factor levels. My sample size is about 4600. So, it could be indeed that certain combinations have very little size (i.e. only a few products that have some combination). $\endgroup$ – Amonet Feb 6 at 12:38
  • 1
    $\begingroup$ Given your factors there are a total of 5*3*14*26*18=98280 possible combinations, which is way too much, much more than you have available data. So you will have to either drop some levels or aggregate them. $\endgroup$ – user2974951 Feb 6 at 12:40
  • $\begingroup$ Forgive my ignorance; is this also the case if a certain product (observation) only has 2 out of 5 levels of a factor, for example? $\endgroup$ – Amonet Feb 6 at 12:54
  • $\begingroup$ The regression model that you will use does not know that, which means that the model will not test only the combinations that are available in the data, but it will test all the possible combinations. $\endgroup$ – user2974951 Feb 6 at 13:00
0
$\begingroup$

There is nothing inherently wrong with having multiple levels in a factor, however keep in mind that increasing factor levels means you will need larger and larger samples to cover all the possible combinations and obtain a good power. I don't know how big your sample is, but 20 colors seems... a little big.

Given your factors there are a total of 5*3*14*26*18=98280 possible combinations, which is way too much, much more than you have available data. So you will have to either drop some levels or aggregate them.

The regression model that you will use does not know which levels are "available", which means that the model will not test only the combinations that are available in the data, but it will test all the possible combinations.

$\endgroup$
  • $\begingroup$ I have another question. How should the data be formatted so that having multiple levels for a factor given an observation will not be a problem? Consider the following situation: product A comes in colors Blue and Red (2 levels), and in 3 technologies (X, Y, Z). Because of this I have 2*3= 6 rows for this one observation (product A) -> doesn't this give false results? Doesn't my regression model now think I have 6 observations, and not just 1? $\endgroup$ – Amonet Feb 7 at 14:04
  • $\begingroup$ @Amonet This is not trivial. One thing you could do is merge some factors, so for example have a variable (colTech) which is an aggregate of color and technology, so for ex. blueX, blueY, ..., redX, ... and so on. $\endgroup$ – user2974951 Feb 11 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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