获取 nlme 或 lme4 中固定效应的广义最小二乘均值

发布于 2024-12-19 12:14:16 字数 418 浏览 1 评论 0原文

可以使用 model.tables 函数获得 aov 对象的最小二乘均值及其标准误差:

npk.aov <- aov(yield ~ block + N*P*K, npk)
model.tables(npk.aov, "means", se = TRUE)

我想知道如何从 中获取广义最小二乘均值及其标准误差>nlmelme4 对象:

library(nlme)
data(Machines)
fm1Machine <- lme(score ~ Machine, data = Machines, random = ~ 1 | Worker )

任何评论和提示都将受到高度赞赏。谢谢

Least Squares Means with their standard errors for aov object can be obtained with model.tables function:

npk.aov <- aov(yield ~ block + N*P*K, npk)
model.tables(npk.aov, "means", se = TRUE)

I wonder how to get the generalized least squares means with their standard errors from nlme or lme4 objects:

library(nlme)
data(Machines)
fm1Machine <- lme(score ~ Machine, data = Machines, random = ~ 1 | Worker )

Any comment and hint will be highly appreciated. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

债姬 2024-12-26 12:14:16

lme 和 nlme 通过最大似然或受限最大似然进行拟合(后者是默认值),因此您的结果将基于这两种方法中的任何一种

summary(fm1Machine) 将为您提供包含以下内容的输出:均值和标准误:

....irrelevant output deleted
Fixed effects: score ~ Machine 
               Value Std.Error DF  t-value p-value
(Intercept) 52.35556  2.229312 46 23.48507       0
MachineB     7.96667  1.053883 46  7.55935       0
MachineC    13.91667  1.053883 46 13.20514       0
 Correlation: 
....irrelevant output deleted

由于您已使用截距拟合固定效应,因此您会在固定效应结果中得到截距项,而不是 MachineA 的结果。 MachineB 和 MachineC 的结果与截距进行对比,因此要获得 MachineB 和 MachineC 的均值,请将每个值添加到截距均值。但标准错误不是您想要的。

要获取您想要的信息,请拟合模型,使其在固定效应中没有截距项(请参阅固定效应末尾的 -1

fm1Machine <- lme(score ~ Machine-1, data = Machines, random = ~ 1 | Worker )

这将为您提供您想要的意思和标准错误输出:

....irrelevant output deleted
Fixed effects: score ~ Machine - 1 
            Value Std.Error DF  t-value p-value
MachineA 52.35556  2.229312 46 23.48507       0
MachineB 60.32222  2.229312 46 27.05867       0
MachineC 66.27222  2.229312 46 29.72765       0
....irrelevant output deleted

lme and nlme fit through maximum likelihood or restricted maximum likelihood (the latter is the default), so your results will be based on either of those methods

summary(fm1Machine) will provide you with the output that includes the means and standard errors:

....irrelevant output deleted
Fixed effects: score ~ Machine 
               Value Std.Error DF  t-value p-value
(Intercept) 52.35556  2.229312 46 23.48507       0
MachineB     7.96667  1.053883 46  7.55935       0
MachineC    13.91667  1.053883 46 13.20514       0
 Correlation: 
....irrelevant output deleted

Because you have fitted the fixed effects with an intercept, you get an intercept term in the fixed effects result instead of a result for MachineA. The results for MachineB and MachineC are contrasts with the intercept, so to get the means for MachineB and MachineC, add the value of each to the intercept mean. But the standard errors are not the ones you would like.

To get the information you are after, fit the model so it doesn't have an intercept term in the fixed effects (see the -1 at the end of the fixed effects:

fm1Machine <- lme(score ~ Machine-1, data = Machines, random = ~ 1 | Worker )

This will then give you the means and standard error output you want:

....irrelevant output deleted
Fixed effects: score ~ Machine - 1 
            Value Std.Error DF  t-value p-value
MachineA 52.35556  2.229312 46 23.48507       0
MachineB 60.32222  2.229312 46 27.05867       0
MachineC 66.27222  2.229312 46 29.72765       0
....irrelevant output deleted
小矜持 2024-12-26 12:14:16

引用

http://markmail.org/message/dqpk6ftztpbzgekm

中的Douglas Bates “我强烈怀疑对于大多数用户来说,lsmeans 的定义是“当我使用 lsmeans 语句时我从 SAS 获得的数字”。数字是购买 SAS 许可证并使用 SAS 来适合您的模型。”

To quote Douglas Bates from

http://markmail.org/message/dqpk6ftztpbzgekm

"I have a strong suspicion that, for most users, the definition of lsmeans is "the numbers that I get from SAS when I use an lsmeans statement". My suggestion for obtaining such numbers is to buy a SAS license and use SAS to fit your models."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文