メイン bin-fit.html Last modified: Sep 01, 2009
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=EUC-JP">
<link rel="shortcut icon" href="../favicon.ico">
<title>JavaScript</title>
<script src="com.js">document.write("com.js ファイルが見つかりません??<br>")</script>
<script src="gxp.js">document.write("gxp.js ファイルが見つかりません??<br>")</script>
<script src="xxp.js">document.write("xxp.js ファイルが見つかりません??<br>")</script>
<script src="io.js">document.write("io.js ファイルが見つかりません??<br>")</script>
<script language="JavaScript">
<!--
function calc(data_string)
{
var f, expectation
var lines, nc, i, mean, variance, n, sd, p, cum, tp, sum0, sum1, sum2, chi_sq, up, low, df, delimiter = ","
if (data_string.indexOf(delimiter) == -1) {
if (data_string.indexOf("\t") != -1) {
delimiter = "\t"
}
else {
delimiter = " "
}
}
lines = data_string.split(delimiter)
nc = lines.length-1
f = new Array(lines.length)
expectation = new Array(lines.length)
for (i = 0; i <= nc; i++) {
f[i] = parseFloat(lines[i])
if (isNaN(f[i]) || Math.floor(f[i]) != f[i] || f[i] < 0) {
printf("観察度数の指定が変です。度数 = %s ???\n", lines[i])
return
}
}
n = mean = variance = 0
for (i = 0; i <= nc; i++) {
n += f[i]
mean += i*f[i]
variance += i*i*f[i]
}
if (n == 0) {
printf("観察度数の合計が0です\n")
return
}
mean /= n
variance = variance/n-mean*mean
sd = Math.sqrt(variance)
p = mean/nc
cum = sum1 = sum2 = sum0 = 0
printf("★ 二項分布へのあてはめ ★\n\n")
printf(" 平均値 = %g\n", mean)
printf(" 分散 = %g\n", variance)
printf("標準偏差 = %g\n\n", sd)
printf("母比率の推定値 = %g\n", p)
sep(47)
printf("%4s%10s%10s%10s%13s\n", "X", "観察度数", "相対度数", "理論比", "期待値")
sep(47)
for (i = 0; i <= nc; i++) {
tp = com(nc, i)*Math.pow(p, i)*Math.pow(1-p, nc-i)
expectation[i] = n*tp
printf("%4i%10i%10.5f%10.5f%13.5f\n", i, f[i], f[i]/n, tp, expectation[i])
sum0 += f[i]/n
sum1 += tp
sum2 += expectation[i]
}
sep(47)
printf("合計%10i%10.5f%10.5f%13.5f\n", n, sum0, sum1, sum2)
sep(47)
printf("\n")
chk = 0
for (low = 0; low <= nc; low++) {
chk += expectation[low]
if (chk >= 1.0) break
}
chk = 0
for (up = nc; up >= 0; up--) {
chk += expectation[up]
if (chk >= 1.0) break
}
if (low != nc+1 && up-low >= 2) {
printf("★ 適合度の検定 ★\n\n")
if (low > 0) {
printf("0 〜 %i のカテゴリーを併合した\n", low)
}
for (i = 0; i < low; i++) {
expectation[low] += expectation[i]
f[low] += f[i]
}
if (up != nc) {
printf("%i 〜 %i のカテゴリーを併合した\n", up, nc-1)
}
for (i = up+1; i <= nc; i++) {
expectation[up] += expectation[i]
f[up] += f[i]
}
chi_sq = 0
for (i = low; i <= up; i++) {
chi_sq += Math.pow(f[i]-expectation[i], 2.0)/expectation[i]
}
df = up-low-1
printf("カイ二乗値 = %10.5f\n", chi_sq)
printf(" 自由度 = %10i\n", df)
printf(" 有意確率 = %10.5f\n\n", xxp(chi_sq, df))
}
printf("=====================================================\n\n")
}
//-->
</script>
</head>
<body bgcolor="#ffffff">
<font size="+2"><b>二項分布へのあてはめ・適合度の検定</b></font> <a href="src/bin-fit.html"><img src="png/src.png" width=35 height=11 alt="src" align=top></a><br> Last modified: Jun 01, 2006<hr noshade><p>
<font color="#ff0000" size="+2">以下のプログラムのサポートは終了しました。自己責任でお使い下さい。</font>
<form name=Result>
<script language="JavaScript">
<!--
//-->JavaScript がサポートされていないブラウザですか?
</script>
<table><tr>
<td><input type="button" name="calcurate" value="計算開始" onClick="calc(this.form.data.value)"> </td>
<td><input type="button" name="clear" value="入力欄クリア" onClick="this.form.data.value=''"> </td>
<td><input type="button" name="clear" value="出力欄クリア" onClick="this.form.result.value=''"> </td>
<td><img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="exa/bin-fit.html">使用法</a></td>
</tr></table>
<p>
観察度数 <input name="data" size=70 value="2,14,20,34,22,8"><p>
出力欄<br><textarea name="result" ROWS=26 COLS=80></textarea>
</form>
<p><hr noshade>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../lecture/Bunpu/nikou.html">手法の解説</a><br>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <A HREF="javascript:history.go(-1)">直前のページへ戻る</A> <img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../mail.html">E-mail to Shigenobu AOKI</a>
<p><center><IMG SRC="../gra/ume5.png" width=121 height=37 ALT="Made with Macintosh"></center>
</body>
</html>
サブ com.js Last modified: Mar 25, 2004
サブ gxp.js Last modified: Mar 25, 2004
サブ xxp.js Last modified: Mar 25, 2004
サブ io.js Last modified: Mar 25, 2004
直前のページへ戻る E-mail to Shigenobu AOKI