0
$\begingroup$

Suppose I have a linear model:

model.lm2 <- lm(df$SalesPrice ~ df$SqFeet + df$Garage + df$Year + df$Quality + df$Style + df$Lot)
summary(model.lm2)

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -2680.9219   397.1155  -6.751 4.04e-11 ***
df$SqFeet     105.8539     6.8433  15.468  < 2e-16 ***
df$Garage       9.6069     4.9504   1.941  0.05286 .  
df$Year         1.4262     0.2011   7.092 4.50e-12 ***
df$Quality2  -133.4846    10.4911 -12.724  < 2e-16 ***
df$Quality3  -149.4913    13.9734 -10.698  < 2e-16 ***
df$Style2     -25.2898     9.0856  -2.784  0.00558 ** 
df$Style3     -13.4706     8.7225  -1.544  0.12313    
df$Style4      11.6082    18.0938   0.642  0.52145    
df$Style5     -26.8263    14.8151  -1.811  0.07077 .  
df$Style6      -4.6575    14.9504  -0.312  0.75553    
df$Style7     -40.5276     8.5626  -4.733 2.88e-06 ***
df$Lot          1.2919     0.2312   5.589 3.75e-08 ***

As you can see the factor variable Style has four insignificant levels(3,4,5,6).

The question is: Does in make sense to recode insignificant levels of factor variable(3,4,5,6 into the level 1)? Would this transformation make predictions of this model better? if yes why/is no why?

$\endgroup$
2
$\begingroup$

No, I do not think it makes sense to recode insignificant levels into the same category.

First, is the omnibus test for Style significant? A comparison of nested models will tell you this:

mod0 <- lm(SalesPrice ~ SqFeet + Garage + Year + Quality + Lot, df)
mod1 <- lm(SalesPrice ~ SqFeet + Garage + Year + Quality + Style + Lot, df)
anova(mod0,mod1)

It looks like from your output that the omnibus test for Style would be significant. What your output is telling us is that Syle2 is different from Style1, and Style7 is different from Style1.

That means that levels 3, 4, 5, and 6 of Style are not different from 1. However, I would still not collapse these into one.

One reason is theoretical: Are the different levels really qualitatively different forms of Style? If so, it does not make sense to recode them as the same and consider them as the same construct.

Another reason is statistical: You are not looking at all the possible pairwise comparisons. Looking at the output, it is likely that—while the levels 4 and 5 are not different from 1—they are significantly different from one another.

You can test this by using the glht() function from the multcomp package. All possible pairwise comparisons can be formulated as linear combinations of the coefficients from the output you have. For instance, to test the difference between Style4 and Style5, you could run the following code:

summary(glht(model.lm2, c(0,0,0,0,0,0,0,0,1,-1,0,0,0)))

What this will do is see if the 9th coefficient in the summary (11.61) minus the 10th coefficient (-26.83) is different from zero:

$H_0$: $b_9$ - $b_{10}$ = 0

Which can be re-written as:

$H_0$: $b_9$ = $b_{10}$

This tests if there is a difference between levels 4 and 5 of Style. How? Think of what the beta weights represent:

$b_9$ = Style4 - Style1

$b_{10}$ = Style5 - Style1

Plug this into the null hypothesis and you have:

$H_0$: Style4 - Style1 = Style5 - Style1

When you add Style1 to both, you get:

$H_0$: Style4 = Style5

And bingo, that tells you if the difference between levels 4 and 5 of Style is statistically significant.

So no, do not recode the insignificant levels into the same category. You are (a) implicitly treating those levels as if they were conceptually the same (which they likely are not) and (b) it is very likely that some of the pairwise comparisons between levels 2, 3, 4, and 5 are significantly different from one another, meaning you wouldn't want to collapse across those anyways.

$\endgroup$

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.