I’m applying a simple linear model with a 3 levels treatment factor ("no", "one", "three")
model<-lm(response variable~treatment, data)
I obtain the following summary:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 41.163 3.715 11.082 1.82e-13 ***
treatment one 11.731 5.158 2.274 0.0287 *
treatment three 5.315 5.158 1.030 0.3094
in which, obviously, the reference level (in alphabetical order) is "no".
Now I want to change the reference level from "no" to "one" and I apply:
data$treatment <- relevel(data$treatment, ref="one")
It seems to work because if I ask to see the level sequence
levels(data$treatment)
I know get:
[1] "one" "no" "three"
However, if I know run again the model with this new reference level I get exactly the same summary and the reference level is still the first “no”
Estimate Std. Error t value Pr(>|t|)
(Intercept) 41.163 3.715 11.082 1.82e-13 ***
treatment one 11.731 5.158 2.274 0.0287 *
treatment three 5.315 5.158 1.030 0.3094
Of course I know I could manually modify the levels' name to change their alphabetical order in a way that my level "one" becomes the first in alphabetical order and so will be used as reference. But I would anyway be interested to understand why the "relevel" function I am applying is not working. Any idea? Thanks