【问题标题】:How to extract the formula from a biglm object?如何从 biglm 对象中提取公式?
【发布时间】:2014-02-21 17:15:41
【问题描述】:

如何从biglm 对象中提取公式?我已经尝试过函数as.formula(),但它没有返回我所期望的。示例:

m1 = lm(Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality, data=swiss)
as.formula(m1) # returns only the formula expression (that's what I want!)
# returns: Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality

library(biglm)
m2 = biglm(Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality, data=swiss)
as.formula(m2) # returns many things, but I want only the formula expression

【问题讨论】:

  • 提示:看str(m2)
  • str(m2) 列出的biglm 属性中,call 是更接近我想要的属性。但它仍然没有返回我期望的结果。

标签: r formula


【解决方案1】:

这应该为你做:

m2$call

【讨论】:

  • m2$call 返回:biglm(Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality, data = swiss),但我希望它返回:Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality
【解决方案2】:

你可以使用termsformula

formula(terms(m2))

Fertility ~ Agriculture + Examination + Education + Catholic + 
    Infant.Mortality

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    相关资源
    最近更新 更多