LoginSignup
2
1

More than 1 year has passed since last update.

信頼区間、信頼係数の算出

Posted at

はじめに

標準正規分布の信頼区間、信頼係数(信頼度)の算出処理を実装した際のまとめになります。

用語解説

StandardNormalDistribution0.png

使用したD言語の標準ライブラリ関数

normalDistribution関数、normalDistributionInverse関数を使用しました。

normalDistribution関数は、$normalDistribution(x)=\frac{1}{\sqrt{2 \pi}} \int_{-\infty}^{x} \exp(-{\frac{t^2}{2}})dt $ です。
下のグラフでの横軸の値xを引数とした場合に、水色部分の面積がnormalDistribution(x)になります。

StandardNormalDistribution1x.png

normalDistributionInverse関数は、normalDistribution関数とは逆に、水色部分の面積をxとした場合の横軸の値を返します。

StandardNormalDistribution2x.png

ソースコード

標準正規分布の信頼区間、信頼係数(信頼度)の算出処理を実装しました。
normalDistribution関数、normalDistributionInverse関数を使用しました。

sample1.d
import std.stdio;
import std.mathspecial;

real getConfidenceCoefficient(real ci)
in ( ci >= 0.0 )				// Confidence interval
{
	auto y = normalDistribution(ci);
	return ( y * 2.0 - 1.0 );
}

real getConfidenceInterval(real cc)
in ( cc >= 0.0 && cc <= 1.0 )	// Confidence coefficient
{
	auto y = cc / 2.0 + 0.5;
	return ( normalDistributionInverse(y) );
}

void main()
{
	for ( auto ci = 1; ci <= 3; ci++ ){
		writefln("%.2f : %.4f", cast(real)ci, getConfidenceCoefficient(ci));
	}
	writeln();
	
	auto arr = [0.85, 0.90, 0.95];
	foreach ( cc; arr ){
		writefln("%.2f : %.4f", cc, getConfidenceInterval(cc));
	}
}

getConfidenceCoefficient

getConfidenceCoefficient関数は、横軸の値xに対する水色部分の面積を算出します。
言い換えると、信頼区間から、信頼係数(信頼度)を算出することができます。

StandardNormalDistribution1.png

getConfidenceInterval

getConfidenceCoefficient関数は、水色部分の面積xに対する横軸の値を算出します。
言い換えると、信頼係数(信頼度)から、信頼区間を算出することができます。

StandardNormalDistribution2.png

コンパイル、実行結果

実行結果は、以下について算出しています。

  • 信頼区間を-1.0~1.0、-2.0~2.0、-3.0~3.0とした場合の信頼係数はいくらか。
  • 信頼係数が、85%(0.85)、90%(0.90)、95%(0.95)となる信頼区間の上限はいくらか。
コマンドプロンプト
D:\Dev> dmd sample1.d

D:\Dev> sample1
1.00 : 0.6827
2.00 : 0.9545
3.00 : 0.9973

0.85 : 1.4395
0.90 : 1.6449
0.95 : 1.9600
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1