【问题标题】:How to create formula object from strings for "rlm"如何从“rlm”的字符串创建公式对象
【发布时间】:2014-07-28 11:43:39
【问题描述】:

我需要从字符串创建一个公式,现在的标准方法是

f <- paste(var1, var2, sep="~")
lm(f, data=<some data.frame> ...)

但这对于“rlm”来说出人意料地失败了,它也应该接受公式//存在于 MASS 包中

rlm(formula, data, weights, ..., subset, na.action,
    method = c("M", "MM", "model.frame"),
    wt.method = c("inv.var", "case"),
    model = TRUE, x.ret = TRUE, y.ret = FALSE, contrasts = NULL)

这是我遇到的错误

Na/NaN/Inf in foreign function call

PS:如果我只是硬编码公式而不是使用 f,这很好用

【问题讨论】:

  • 您在寻找as.formula吗?
  • rlm 接受 formula 对象,但不接受“角色”对象

标签: r lm


【解决方案1】:

使用as.formula 使f 成为论坛对象:

f <- as.formula(paste("stack.loss",".",sep="~"))
rlm(f, stackloss, psi = psi.bisquare)
Call:
rlm(formula = f, data = stackloss, psi = psi.bisquare)
Converged in 11 iterations

Coefficients:
(Intercept)    Air.Flow  Water.Temp  Acid.Conc. 
-42.2852537   0.9275471   0.6507322  -0.1123310 

Degrees of freedom: 21 total; 17 residual
Scale estimate: 2.28  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多