use Math::Cephes qw(gamma incbet); # スチューデントのt分布 Student's T-Distribution # 引数 変数 自由度 ($X, $DegreesOfDreedom) # 戻り値 スチューデントのt分布 (@StudentsTDistribution) sub STUDENTSTDISTRIBUTION{ my ($X, $DegreesOfDreedom) = @_; my @StudentsTDistribution = (); my $IncompleteBetaFunction = 0; my $t = 0; # 変数,自由度の確認 if(($X < 0) || ($DegreesOfDreedom <= 0)){ return 0; } # 確率密度関数 Frequency Function $StudentsTDistribution[0] = &FREQUENCYFUNCTION($X, $DegreesOfDreedom); $t = ($X + sqrt(($X * $X) + $DegreesOfDreedom)) / (2 * sqrt(($X * $X) + $DegreesOfDreedom)); # 累積分布関数 正則不完全ベータ関数 Regularized Incomplete Beta Function $IncompleteBetaFunction = &incbet(($DegreesOfDreedom / 2), ($DegreesOfDreedom / 2), $t); # 下側累積確率 Lower Cumulative Distribution $StudentsTDistribution[1] = $IncompleteBetaFunction; # 上側累積確率 Upper Cumulative Distribution $StudentsTDistribution[2] = 1 - $IncompleteBetaFunction; return @StudentsTDistribution; } # 確率密度関数 Frequency Function # 引数 変数 自由度 ($X, $DegreesOfDreedom) # 戻り値 確率密度関数 ($FrequencyFunction) sub FREQUENCYFUNCTION{ my ($X, $DegreesOfDreedom) = @_; my $FrequencyFunction = 0; my $Pi = atan2(1, 1) * 4; my $Num = 0; my $Den = 0; # 分子 $Num = gamma(($DegreesOfDreedom + 1) / 2); # 分母 $Den = sqrt($DegreesOfDreedom * $Pi) * gamma($DegreesOfDreedom / 2); # スチューデントのt分布 Frequency Function $FrequencyFunction = ($Num / $Den) * ((1 + (($X * $X) / $DegreesOfDreedom)) ** (-(($DegreesOfDreedom + 1) / 2))); return $FrequencyFunction; }