Reformulate in R log(Y+1)

情到浓时终转凉″ 提交于 2019-12-11 02:31:19

问题


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 is continuous.

This gets me the formula as y ~ feature1+feature2+feature3

However I want the formula to be log(y+1) ~ feature1+feature2+feature3

How do I do this using reformulate?


回答1:


Pass in the response as a quoted expression:

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

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

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


来源:https://stackoverflow.com/questions/26374106/reformulate-in-r-logy1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!