R Statistical Package Gem for a Rails Application

R Statistical Package Gem For A Rails Application

RSRuby takes the approach of embedding the R interpreter into Ruby as a C extension. It only works on specific versions of ruby, so if you are using JRuby or Rubinius this is not really an option for you. It is definitely the fastest, although some class conversions get a little weird.

RinRuby and Rserve Ruby both use TCP/IP sockets, although Rserve claims to be 5-10 times faster.

I would giving RSRuby a try, and if you encounter problems with your ruby version or such, switching to Rserve. I am not familiar with Gauss.

Heads up- as far as I know, none of these solutions support multi threading, largely because R doesn't play nice with other instances of itself.

Integrating Rserve Into A Rails Application

To answer your questions:

  1. Yes. I integrated rserve into a rails application. I served it successfully on my own server. I did have some issues when trying to use Heroku to serve my app (using the r buildpack). While debugging I switched to rinruby to match the examples for the buildpack.

  2. The performance of rserve was good on my server. Rinruby also performs well.

  3. I do not use any packages in my app. However it is easy to do so. If you are deploying to Heroku, see the init.r file in the example for the r buildpack.

  4. For an app with little traffic, Heroku will serve the app for free. The main difference between rserve and rinruby is that with rserve you will start up your own instance of R that ruby will then communicate with. Rinruby starts its own instance of R from within ruby.

integrating R with Rsruby

I use Rserve with a wrapper which simplifies the interface, called Rserve-simpler.

http://rubygems.org/gems/rserve-simpler . It makes my life easier. I end up using R and Ruby together quite often.

Here is a question where I've explained some usage. How to pass a ts object to R via RSRuby

Can Ruby interface with r?

See RSRuby for accessing R functionality through Ruby.

As for a beginner's tutorial, try looking at "R For Beginners". I found it helpful when I had to learn some basic R for a statistics course.

Best way to use R in Ruby

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

Calculate statistics on arrays

If you really need a full statistics library, take a look at statsample. Otherwise you may find descriptive_statistics to be a nice, lightweight alternative.



Related Topics



Leave a reply



Submit