<div dir="ltr"><div dir="ltr"><div>Hello...</div><div><br></div><div>I've being working on coupling Ruby and R for some time now (since rc1) and I think a have managed to advance quite a bit, thanks in great part to the help from people here, specially Chris and Stepan: thanks!! So, now, instead of posting a question, this post is tho show where I'm at and see if you have any suggestions, opinions, feedback, etc. <br></div><div><br></div><div><div>Bellow two examples of how the coupling works. The first is a scatter plot extracted from <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__r-2Dstatistics.co_Top50-2DGgplot2-2DVisualizations-2DMasterList-2DR-2DCode.html&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=V4perA7MCLoMrUH-4v2X9TEXm7WzhucqB9Quklf-V8g&s=EuFjHNgCyBdxBylfpIDxJFydO57YqQEr4t1YIYHh-YE&e=">http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html</a> and the second a 5th degree polynomial regression. The idea of the coupling is to use Ruby syntax, but
emulate R as closely as possible in order to make it trivial to
use for an R developer. <br></div><div><br></div><div><div>====================================================================</div><div>require 'cantata'</div><div>require 'ggplot'</div><div><br></div><div># set options<br></div><div>R.options(scipen: 999) # turn-off scientific notation like 1e+48<br>R.theme_set(R.theme_bw) # pre-set the bw theme.<br></div><div><br></div><div># read the R 'midwest' dataset onto the 'midwest' variable <br></div><div>midwest = ~:midwest<br><br>R.awt<br><br># Scatterplot<br>gg = midwest.ggplot(E.aes(x: :area, y: :poptotal)) + <br> R.geom_point(E.aes(col: :state, size: :popdensity)) + <br> R.geom_smooth(method: "loess", se: false) + <br> R.xlim(R.c(0, 0.1)) + <br> R.ylim(R.c(0, 500000)) + <br> R.labs(subtitle: "Area Vs Population", <br> y: "Population", <br> x: "Area", <br> title: "Scatterplot", <br> caption: "Source: midwest")<br><br>puts gg<br></div><div><br></div><div><div><img src="cid:ii_jm9atwwi0" alt="image.png" class="gmail-m_5035975053183130821gmail-m_6622705263619746008gmail-m_-52141512756857294gmail-CToWUd gmail-m_5035975053183130821gmail-m_6622705263619746008gmail-m_-52141512756857294gmail-a6T gmail-m_5035975053183130821gmail-m_6622705263619746008gmail-CToWUd gmail-m_5035975053183130821gmail-m_6622705263619746008gmail-a6T gmail-m_5035975053183130821gmail-CToWUd gmail-m_5035975053183130821gmail-a6T gmail-CToWUd gmail-a6T" style="outline: currentcolor none 0px;" tabindex="0" width="524" height="549"></div></div></div><div><div><div><div><br></div></div><div><br></div><div>===================================================================</div></div><div><br></div><div>As another example, here is how to get a polynomial regression using the Boston data from R package ISLR. <br></div><div><br></div><div>require 'cantata'<br>R.require 'MASS'<br>R.require 'ISLR'<br><br>lm_fit5 = R.lm(R.formula("medv ~ poly(lstat, 5)"), data: :Boston)<br>puts lm_fit5.summary<br></div><div><br></div>[This output was cut from the total print...]<br><div><br></div><div>Residuals:<br> Min 1Q Median 3Q Max <br>-13.5433 -3.1039 -0.7052 2.0844 27.1153 <br><br>Coefficients:<br> Estimate Std. Error t value Pr(>|t|) <br>(Intercept) 22.5328 0.2318 97.197 < 2e-16 ***<br>poly(lstat, 5)1 -152.4595 5.2148 -29.236 < 2e-16 ***<br>poly(lstat, 5)2 64.2272 5.2148 12.316 < 2e-16 ***<br>poly(lstat, 5)3 -27.0511 5.2148 -5.187 3.10e-07 ***<br>poly(lstat, 5)4 25.4517 5.2148 4.881 1.42e-06 ***<br>poly(lstat, 5)5 -19.2524 5.2148 -3.692 0.000247 ***<br>---<br>Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br><br>Residual standard error: 5.215 on 500 degrees of freedom<br>Multiple R-squared: 0,6817, Adjusted R-squared: 0,6785 <br>F-statistic: 214,2 on 5 and 500 DF, p-value: < 2.2e-16<br><br></div><div><div>===================================================================</div><div><br></div><div>In order to test this:</div><div><br></div><div>* Install GraalVM (rc6)</div><div>* Install TruffleRuby (follow the simple instructions)</div><div>* Install FastR</div><div>* Clone the git repo: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_rbotafogo_cantata.git&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=V4perA7MCLoMrUH-4v2X9TEXm7WzhucqB9Quklf-V8g&s=JMJtiz_aw-o6IW_FMB8solXtUJwYRuh6nzsv02v5g_E&e=" target="_blank">https://github.com/rbotafogo/cantata.git</a></div><div>* gem install rspec</div><div>* Use rake to run the tests ('rake -T' shows all available tasks)</div><div><br></div><div>Doing:</div><div><br></div><div>* rake specs:all -- Runs all the specs. Reading the specs shows much of how to use the language</div><div>* rake sthda:all -- Runs a slideshow with over 80 plots</div><div>* rake islr:all -- Runs some 'labs' from the Introduction to Statistical Learning book</div></div></div><div><br></div> </div><div><br>-- <br><div dir="ltr" class="gmail_signature">Rodrigo Botafogo<br><br></div></div></div></div>