我正在处理一个数据集,我必须生成要动态传递给 lm 的公式。所以,我正在使用重新配制来做到这一点。
formula = reformulate(termlabels = c('feature1', 'feature2', 'feature3'), response="y")
y 是连续的。
这让我得到的公式为y ~ feature1+feature2+feature3
不过我希望公式是log(y+1) ~ feature1+feature2+feature3
如何使用重新配制来做到这一点?
将响应作为引用表达式传递:
x <- c("feature1", "feature2", "feature3")
reformulate(x, response=quote(log(y+1)))
或者您可以手动构建公式。这是什么reformulate
在幕后做的。
formula(paste("log(y + 1) ~", paste(x, collapse="+")))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)