Using R from Python rpy2
Today I installed R (vesion2.11.1 2010.5.31) from mac installer.
R is an enviroment for statistical computing and graphics.
Python has some packages for R like rpy and rpy2.
Here is my install log.
install numpy and rpy2 via pip
pip install numpy pip install rpy2
import rpy2.robjects as robjects ctl = robjects.FloatVector([4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14]) trt = robjects.FloatVector([4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69]) correlation = robjects.r('function(x, y) cor.test(x, y)') print correlation(ctl, trt)
$ python Desktop/correlation_sample.py Pearson's product-moment correlation data: x and y t = -1.4559, df = 8, p-value = 0.1835 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.8440680 0.2415684 sample estimates: cor -0.4576683Posted: July 4th, 2010 | Author: yamakk | Filed under: 技術 | Tags: mac, math, python, rpy2, statistics | No Comments »
Leave a Reply