0

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

bhavya_karia
  • 760
  • 1
  • 6
  • 12
L.Loc
  • 1
  • 2
  • 1
    Hi L.Loc, you did it correctly, unless there's something else. can you do dput(data) ? – StupidWolf Nov 15 '19 at 14:20
  • Agree - and in addition to showing your data, also can you edit your question with your `lm` statement exactly as used? – Ben Nov 15 '19 at 15:17
  • I got it, I was not recalling the data set name (data=dataset name) in the lm statement. Now it works. Thanks @Ben for your suggestion to get a look at this – L.Loc Nov 18 '19 at 09:51

0 Answers0