I know R is a very powerful tool for data mining and predictive model building. However, I'm finding it difficult to extract an equation from any sort of modeling that I do. For example, using something like:

model <- lm(y~var1+var2+var3)

For data mining, I can use something like:

analysis <- rpart(y~var1+var2+var3)

to understand my data. However, it would be nice if R had the capability of displaying the model it uses, whether it is linear or something much more complicated. There is a program called Eureka from Nutonian that is able to take data and try and fit an equation to it. Is R able to do this?

  • 3
    $\begingroup$ Displaying the model and fitting it are two different things. Your examples are precisely what you require, given the data equation is fitted. Blindly fitting the model without domain knowledge is usually not advised, as the resulting model might be spurious. $\endgroup$ – mpiktas Sep 23 '13 at 7:03
  • 1
    $\begingroup$ What do you mean by 'display the model' exactly? $\endgroup$ – Glen_b -Reinstate Monica Sep 23 '13 at 10:17

There is a big difference between representing and fitting a model.

  • If you want to display/represent the variable analysis you just make plot(analysis) in R and then you will see a representation of your model.
  • If you want a explicit formula for your model you must (1) know (or assume) a specific model for your data (linear, quadratic, etc...) (2) fit your parameters model. Nonetheless there are very few problems that can be expressed as a formula, unless it is linear/quadratic.

The idea of machine learning is to provide a solution which makes possible to predict without the necessity of using an explicit formula.

  • $\begingroup$ Thanks for the response. I have a couple of follow up questions to your response. For plot(analysis) I'm able to see residuals vs. fitted, a q-q plot, etc. Is this what you are referring to by "representation of your model"? Also, assuming I know my model is quadratic, could I do something like: lm(y ~ x + I(x^2) + I(x^3)), or is there another way I could do it assuming I have used nlm(y~x^3+x^2)? $\endgroup$ – GK89 Sep 23 '13 at 14:06

So after doing a bit more research, I found out that the topic I'm look at is called symbolic regression. It is the process of fitting data into suitable mathematical formula. An overview of the topic can be found here.

In R, it looks as if there is only one package that can conduct symbolic regression. The RGP package can do this with user specified functions to include. Documentation on the package can be found here.

Some sample code on how to make a basic function in RGP can be seen below:

#Symbolic Regression
newFuncSet <- functionSet("+","-","*","/","sqrt","exp","ln")
result1 <- symbolicRegression(Y~Var1+Var2+Var3+Var4,
                              data=dataset, functionSet=newFuncSet,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.