【发布时间】:2017-05-05 14:08:47
【问题描述】:
我正在测试 lmer 模型中的一些固定系数,但需要在进一步的过程中使用该模型(计算每个变量的贡献),因此需要更改 lmerMod 模型的某些部分。
由于以下错误消息,我正在努力更改 object@pp$X
错误:无效替换:引用类字段“X”是只读的
下面的可重现示例:
#Load package and data
library(lme4)
data(iris)
#build the model
mod<-lmer(Sepal.Length~Petal.Length + offset(Petal.Width*1) + (1|Species),data=iris)
fixef(mod) #not showing the offset coefficient
#apply changes to mod to get fixef(mod) to work with new coefficient
mod@beta <- c(mod@beta,1) #because model was offset by 1*Petal.Width
mod@pp$X <- matrix(data.frame(mod@pp$X, iris["Petal.Width"])) #causes the error
#check fixef:
fixef(mod) # should have Petal.Width at the end with a value of 1
注意:
[fixef]:(https://github.com/lme4/lme4/blob/master/R/lmer.R#L876)!在它的函数中有两个调用:
- 是object@beta(已经改成功了);
- 是getME(object,"X"):(https://github.com/lme4/lme4/blob/master/R/lmer.R#L1932)。
我对使用变量名称获取 fixef 系数的替代方法持开放态度(能够直接调整 lmerMod)
提前致谢!
【问题讨论】: