• R语言
  • 如何批量对线性回归的参数估计值进行转换

我需要对很多个线性模型的参数估计值进行这个转换: coefficient = ecoefficient - 1. 截距不用转换.
我写了一个函数,不知道是哪里写得不对,run完函数后coefficients还是原来的值.
下面code是以iris数据集为例做线性回归. 函数返回的 coefficients 是转换了的,但是最终 test_lm$coefficients 的值并没有被覆盖.
请各位大神指教是哪里出错了, 感谢!

test_lm <- lm(Petal.Length ~ Sepal.Length + Sepal.Width + Petal.Width, data = iris)
test_lm$coefficients

coef_transform <- function(lm_name){
  lm_name$coefficients[-1] <- exp(lm_name$coefficients[-1]) - 1
  lm_name$coefficients
}

coef_transform(test_lm)

test_lm$coefficients
10 个月 后