Extract Formula From lm with Coefficients (R)

后端 未结 4 1082
迷失自我
迷失自我 2021-01-13 06:43

I have an lm object and want to get the formula extracted with coefficients. I know how to extract the formula without coefficients, and how to get the coefficients without

4条回答
  •  情歌与酒
    2021-01-13 07:09

    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
    

提交回复
热议问题