I'm doing the statistical analysis for my thesis with a linear mixed model, using the nlme
package. Now I work with several orientations (west, east, north), and R takes the estimate as the alphabetically first value. However, I want the estimate to be the lowest value. Does somebody know how to do this?
Asked
Active
Viewed 131 times
-3

Ben Bolker
- 211,554
- 25
- 370
- 453

Babette
- 1
-
4Welcome to SO. Please read how to ask a good question **[here](https://stackoverflow.com/help/how-to-ask) ** – KoenV May 24 '17 at 13:03
-
By "lowest value" do you mean the orientation in which the expected value of the response variable is lowest? – Ben Bolker May 24 '17 at 13:20
-
I have an idea for how to do what I *think* you want, but you should clarify your question first please ... – Ben Bolker May 24 '17 at 14:26
1 Answers
1
Like @BenBolker, I think I know what you have in mind.
First, simulating some toy data...
site <- rep(1:3, each=6)
orientation <- rep(c("west","east","north"), 6)
x <- rnorm(18)
x[orientation=="north"] <- x[orientation=="north"] + 1
x[orientation=="east"] <- x[orientation=="east"] + 2
df <- data.frame(site, orientation, x)
df
# site orientation x
# 1 1 west 0.9554461
# 2 1 east 4.1742621
# 3 1 north 0.8901404
# 4 1 west -0.5998719
# 5 1 east 1.8279064
# 6 1 north 1.0984336
# 7 2 west 1.1020786
# 8 2 east 2.7994980
# 9 2 north 0.9158762
# 10 2 west 1.2512472
# 11 2 east 0.1200988
# 12 2 north 1.3584406
# 13 3 west 0.6602157
# 14 3 east 0.6226468
# 15 3 north 0.9409308
# 16 3 west -1.8992221
# 17 3 east 2.0386123
# 18 3 north 2.3562818
Running lme()
yields...
library(nlme)
summary(lme(x~orientation, random=~1|site, data=df))
# .... just looking at fixed effects ...
# Fixed effects: x ~ factor(orientation)
# Value Std.Error DF t-value p-value
# (Intercept) 1.9305041 0.4729373 13 4.081945 0.0013
# orientationnorth -0.6704868 0.6688344 13 -1.002471 0.3344
# orientationwest -1.6855218 0.6688344 13 -2.520088 0.0256
... and you'd like west
to be the reference level instead of east
, since it's got the lowest effect.
One possible solution: use a factor version of your orientation variable, with the levels in the order you'd like them to be in.
df$orientation1 <- factor(df$orientation, levels=c("west","north","east"))
summary(lme(x~orientation1, random=~1|site, data=df))
# ... again just looking at fixed effects ...
# Value Std.Error DF t-value p-value
# (Intercept) 0.2449823 0.4729373 13 0.5180016 0.6132
# orientation1north 1.0150350 0.6688344 13 1.5176178 0.1530
# orientation1east 1.6855218 0.6688344 13 2.5200884 0.0256

Matt Tyers
- 2,125
- 1
- 14
- 23