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