估计线性模型的R的变化

时间:2017-05-24 13:00:41

标签: r statistics mixed-models

我正在使用nlme包使用线性混合模型对我的论文进行统计分析。现在我使用多个方向(西,东,北),R将估计值作为按字母顺序排列的第一个值。但是,我希望估算值是最低值。有人知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

和@BenBolker一样,我想我知道你的想法。

首先,模拟一些玩具数据......

NSThread

运行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 会产生......

lme()

...并且您希望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 成为参考级别而不是west,因为它的影响最小。

一种可能的解决方案:使用方向变量的因子版本,其级别按您喜欢的顺序排列。

east