0
是否可以替换lm对象中的系数?替换[r]中的lm系数
我以为以下会工作
# sample data
set.seed(2157010)
x1 <- 1998:2011
x2 <- x1 + rnorm(length(x1))
y <- 3*x1 + rnorm(length(x1))
fit <- lm(y ~ x1 + x2)
# view origional coefficeints
coef(fit)
# replace coefficent with new values
fit$coef(fit$coef[2:3]) <- c(5, 1)
# view new coefficents
coef(fit)
任何援助将不胜感激
我很好奇为什么有人会想这样做。 – ndoogan 2013-03-14 18:52:22
我也是,我的第一个虽然也是“为什么??” – 2013-03-14 18:55:17
在我的情况下,我按照区域循环了线性模型,并且我的一些区域没有与其他区域相同数量的解释变量。在这种情况下,lm为模型系数返回NA,我想用零替换它,因为我的代码的其他下游元素取决于每个解释变量槽中的数值。 – MikeTP 2013-03-14 18:59:51