且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从lm中提取具有系数(R)的公式

更新时间:2023-12-02 13:46:58

as.formula(
  paste0("y ~ ", round(coefficients(model)[1],2), " + ", 
    paste(sprintf("%.2f * %s", 
                  coefficients(model)[-1],  
                  names(coefficients(model)[-1])), 
          collapse=" + ")
  )
)
# y ~ -5.33 + 0.51 * b