简体   繁体   English

Ruby实现t分布

[英]Ruby implementation of t distribution

I'm trying to find a ruby implementation of the t-distribution so I can draw a graph with a certain mean, standard deviation and degrees of freedom. 我正在尝试找到t分布的红宝石实现方式,以便可以绘制具有一定平均值,标准偏差和自由度的图形。 Not totally sure if that makes sense, any help would be much appreciated. 不能完全确定这是否有意义,将不胜感激。

I have to second DGM's comments about using R and Rinruby. 我必须附上DGM关于使用R和Rinruby的评论。 Rinruby is fantastic because you can type R commands right into ruby :) You just need to make sure you have R installed on your system before you use it. Rinruby非常棒,因为您可以在ruby中直接输入R命令:)使用前,只需确保已在系统上安装了R。 If you want to see a T-Distribution in action (after installing R and the Rinruby gem) just the paste the following into irb: 如果要查看运行中的T分布(在安装R和Rinruby gem之后),只需将以下内容粘贴到irb中:

require 'rinruby'

R.eval <<EOF
x <- seq(-4, 4, length=100)
hx <- dnorm(x)

degf <- c(1, 3, 8, 30)
colors <- c("red", "blue", "darkgreen", "gold", "black")
labels <- c("df=1", "df=3", "df=8", "df=30", "normal")

plot(x, hx, type="l", lty=2, xlab="x value",
  ylab="Density", main="Comparison of t Distributions")

for (i in 1:4){
  lines(x, dt(x,degf[i]), lwd=2, col=colors[i])
}

legend("topright", inset=.05, title="Distributions",
  labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
EOF

Hope this helps you get started. 希望这可以帮助您入门。 I should note that I haven't needed to do a t-distribution recently so I shamelessly stole the R code from some R documentation. 我应该注意,我最近不需要做t分布,所以我无耻地偷了一些R文档中的R代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM