スチューデントt分布サンプリング; Student's t Distribution Sampling
概要
スチューデントt分布とは以下の式で表現される確率分布。 平均\(\mu\)、分散\(\sigma^2\)の正規分布に従う\(n\)個の確率変数があるとき、その標本平均を\(\overline{X}\)、不偏分散を\(S^2\)とする。 このとき\(T= \frac{\overline{X}-\mu}{S / \sqrt{n}}\)はスチューデントt分布に従う。
$$f(x)= \frac{\Gamma(\frac{\nu+1}{2})}{\sqrt{\nu \pi} \Gamma(\frac{\nu}{2})} \left( 1 + \frac{x^2}{\nu} \right)^{-\frac{\nu+1}{2}} $$
ここで\( \nu = n - 1 \)であり、スチューデントt分布の唯一のパラメータである。元の正規分布の平均と分散に依存しない。
ソースコード
namespace ExRandom.Continuous {
public class StudentsTRandom : Random{
readonly NormalRandom nd;
readonly ChiSquaredRandom cd;
readonly double inv_nu;
public StudentsTRandom(MT19937 mt, uint nu = 2) {
if(mt == null) {
throw new ArgumentNullException();
}
if(nu < 1) {
throw new ArgumentException();
}
this.nd = new NormalRandom(mt);
this.cd = new ChiSquaredRandom(mt, k : nu);
this.inv_nu = 1.0 / (double)nu;
}
public override double Next() {
double c = cd.Next(), z = nd.Next();
return z / Math.Max(Math.Sqrt(c * inv_nu), Double.Epsilon);
}
}
}
関連項目
メルセンヌ・ツイスタ
各種確率分布サンプリング基本クラス
正規分布サンプリング
カイ二乗分布サンプリング