重新设定R log(Y + 1) [英] Reformulate in R log(Y+1)

查看:147
本文介绍了重新设定R log(Y + 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个数据集,其中我必须生成要动态传递给lm的公式.因此,我正在使用重新编写格式来执行此操作.

I am working on a data set where I have to generate formula to be passed to lm dynamically. So, I am using reformulate to do this.

formula = reformulate(termlabels = c('feature1', 'feature2', 'feature3'), response="y")

y是连续的.

这使我得到的公式为y ~ feature1+feature2+feature3

但是我希望公式为log(y+1) ~ feature1+feature2+feature3

我该如何使用重新配制配方?

How do I do this using reformulate?

推荐答案

以带引号的表达式传递响应:

Pass in the response as a quoted expression:

x <- c("feature1", "feature2", "feature3")
reformulate(x, response=quote(log(y+1)))

或者您也可以手动构造公式.这是reformulate在后台执行的操作.

Or you could just construct the formula manually. This is what reformulate does under the hood.

formula(paste("log(y + 1) ~", paste(x, collapse="+"))) 

这篇关于重新设定R log(Y + 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆