Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to use R in Ruby

I want to visualize some of my statistical caluclations in Ruby.

My problem is, that I can't find the right gem for that.

rsruby doesn't seem to be up-to-date and I can't install it in Ruby 1.9.2.

Do you know a way how to run the R commands in Ruby?

like image 359
jeffrey Avatar asked Apr 10 '12 09:04

jeffrey


People also ask

What does \r do in Ruby?

The \r character is a carriage-return (CR). The \n character is a line-feed (LF). The HTTP request protocol requires that parts of the request be terminated with CRLF pairs.

Is Ruby like R?

No, not at all! They instead are completely different from each other. R Programming Language is a programming language that is developed by statisticians for the Data Science domain. It is a statistical language that is used in Data Science and Machine Learning, etc.


1 Answers

I just saw this post and thought I should comment since I use R pretty extensively. If you are coming from an R background the best gem I have found is Rinruby. The reason it is fantastic is because you don't interpret the commands in ruby, you use actual R code. For example:

require "rinruby"      
#Set all your variables in Ruby
n = 10
beta_0 = 1
beta_1 = 0.25
alpha = 0.05
seed = 23423
R.x = (1..n).entries
#Use actual R code to perform the analysis
R.eval <<EOF
  set.seed(#{seed})
  y <- #{beta_0} + #{beta_1}*x + rnorm(#{n})
  fit <- lm( y ~ x )
  est <- round(coef(fit),3)
  pvalue <- summary(fit)$coefficients[2,4]
EOF

On the Rinruby website I listed above there are some fantastic examples to get you started. Hope this helped.

-Sean

like image 66
Sean Avatar answered Sep 22 '22 01:09

Sean