# Why does the model change when using relevel?

When computing regression models with R, I regularly use the relevel function to get my model to give me results for the other level, too. I noticed that sometimes, but not often, this changed the model in the sense that levels of other factors that were significant before the relevelling are not any more. Is this inherent to relevelling or exceptional and maybe due to some problem with my data? Does it show that my data likely does not meet one of the prerequisites of linear models?

Related to that, is it alright if I use relevel, recompute my model, and then report significance values from both models in my article? If significance differs between the two models for a certain factor, I suppose I should then go with one that is less optimistic?

I suppose my question betrays that I don't know enough about lm to grasp the need for a base level. I thought I understood it pretty well ;) Somehow none of the introductions I read explained that point, or I was too daft to grasp it. So if someone could direct me to a site where the point of having base levels in lm is explained or explain it themselves, that would be great, too!

Edit: Here's a minimal example:

library(datasets)
sprays<-OrchardSprays
model<-lm(decrease~treatment+rowpos+colpos,data=sprays)
summary(model)


Part of the summary says

treatmentC    20.625      9.731   2.120  0.03866 *


So if treatment == C this has significant positive influence on 'decrease'. Now I relevel 'treatment' to B to find out what influence treatment == A has:

sprays$treatment<-relevel(sprays$treatment,"B")
summary(model)


And now treatment == C is not significant in this new model:

treatmentC    17.625      9.731   1.811  0.07567 .


Sorry for posting in the wrong place! Can I move my question to stats statexchange or should I open a new one there?

## migrated from stackoverflow.comAug 1 '12 at 23:59

This question came from our site for professional and enthusiast programmers.

• Welcome to SO. Do you think you can make a small reproducible example that illustrates this? – Andrie Aug 1 '12 at 20:55
• It sounds like you don't actually know what the model is fitting and how to interpret the parameters in your model. This is probably more appropriate for the stats stackexchange site. – Dason Aug 1 '12 at 20:59
• Both of the previous comments are right on target. Something as simple as d <- data.frame(y=runif(300),f=factor(rep(LETTERS[1:3],each=100)); lm(y~f,data=d) will give you a start, although of course there will be no significant changes in that case (although the parameter estimates and p-values will certainly change when you relevel). – Ben Bolker Aug 1 '12 at 21:02
• Maybe you might want to see pages 74-75 of this book springer.com/economics/econometrics/book/978-0-387-77316-2. This is clearly an econometric problem concerning dummy variables. Changing your baseline does not change the expected value of your estimation, but changes the parameter estimation. Any basic econometrics book will help you on this issue. – Jilber Aug 1 '12 at 21:59
• ... This really isn't an "econometrics" issue as much as it is a model parameterization issue which is an issue in any field of statistics. – Dason Aug 1 '12 at 22:22

Suppose the factor conditions has levels A,B,C and you regress your response variable y on conditions using mod <- lm(y ~ conditions). Now summary(mod) returns the mean of the reference level of conditions (say A) and the difference in means between conditions B and A and the difference between conditions C and A (reported respectively as (Intercept), conditions:B, and conditions:C). If you conditions <- relevel(conditions, ref = 'B') and re-reun the linear model, now you'll get the mean of B, the difference between A and B, and the difference between C and A. Naturally, p-values might change. It does not mean there is a problem with your data. It does not mean your data necessarily fail an assumption of the linear model. The fit is the same and you have simply changed what information gets printed out because you have changed the reference level and are using treatment contrasts. You can get the same linear hypothesis tests using the original mod.
As far as what to report, in many fields, it is customary to report whether there was a statistically significant effect of conditions (using the output of anova(mod)) and to report to the full regression output in a table (using whatever reference levels you'd like). Norms for how and whether to report tests of A vs. B (for example) vary by field. Take a close look at good papers in your field.