获取 nlme 或 lme4 中固定效应的广义最小二乘均值
可以使用 model.tables 函数获得 aov
对象的最小二乘均值及其标准误差:
npk.aov <- aov(yield ~ block + N*P*K, npk)
model.tables(npk.aov, "means", se = TRUE)
我想知道如何从 中获取广义最小二乘均值及其标准误差>nlme
或 lme4
对象:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
lme 和 nlme 通过最大似然或受限最大似然进行拟合(后者是默认值),因此您的结果将基于这两种方法中的任何一种
summary(fm1Machine)
将为您提供包含以下内容的输出:均值和标准误:由于您已使用截距拟合固定效应,因此您会在固定效应结果中得到截距项,而不是 MachineA 的结果。 MachineB 和 MachineC 的结果与截距进行对比,因此要获得 MachineB 和 MachineC 的均值,请将每个值添加到截距均值。但标准错误不是您想要的。
要获取您想要的信息,请拟合模型,使其在固定效应中没有截距项(请参阅固定效应末尾的
-1
:这将为您提供您想要的意思和标准错误输出:
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: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:This will then give you the means and standard error output you want:
引用
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."