首页 > 解决方案 > 将常数定义为 r 回归的系数

问题描述

我正在尝试将常数定义为 r 回归的系数。即试图将弹性定义为您在照片中看到的数字 -1.64431。

在此处输入图像描述

reg <- lm(ln_q ~ ln_price, data=df) 
elasticity <- reg[["coefficients","ln_price"]]
print(elasticity)

我得到错误:

Error in reg[["coefficients", "ln_price"]] : 
  incorrect number of subscripts

非常感谢任何帮助!:)

标签: rregressionconstantscoefficients

解决方案


elasticity <- reg$coefficients[names(reg$coefficients)=="ln_price"]

推荐阅读