用于数据统计的R语言及RPy

类似于Matlab的统计模块,R语言是一种用于数据统计的开源免费语言(软件)。它是从贝尔实验室在70年代开发的S语言演变而来的,是成熟、通用的统计计算用工具,同时具有很强的绘图功能。IBM DW上的这篇文章介绍得很好。

R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, …). 所以,R语言在数据挖掘中也可以得到应用。

r demo
r demo

针对R语言定期发布的一系列通讯,编辑得很好,对理解统计技术及应是很有帮助的,值得去读。

R语言可以通过RPy嵌入到Python环境中。这使得整合复杂的开发环境和工具成为可能。

摘录一段例子,应用RPy进行最小二乘线性拟合以及绘图的过程。

from rpy import r
my_x = [5.05, 6.75, 3.21, 2.66]
my_y = [1.65, 26.5, -5.93, 7.96]
linear_model = r.lm(r("y ~ x"), data = r.data_frame(x=my_x, y=my_y))
gradient = linear_model['coefficients']['x']
yintercept= linear_model['coefficients']['(Intercept)']

r.png("scatter_regression.png", width=400, height=350)
r.plot(x=my_x, y=my_y, xlab="x", ylab="y", xlim=(0,7), ylim=(-16,27),
           main="Example Scatter with regression")
r.abline(a=yintercept, b=gradient, col="red")
r.dev_off()

一个PNG图片输出出来

No comments yet. Be the first.

Leave a reply

Random posts

  • 囚徒困境问题图解及变形
  • 一些厂商提供的数据仓库工具
  • 晨雾回龙观
  • SQL Server企业管理器生成的奇怪代码
  • 下载Google App Engine站点的代码