メイン poisson-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="fac.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 = new Array()
  var expectation = new Array()
  var lines, nc, i, mean, variance, n, sd, 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
  for (i = 0; i < nc; i++) {
    f[i] = parseFloat(lines[i])
    if (isNaN(f[i]) || f[i] != Math.floor(f[i])) {
      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]
  }
  mean /= n
  variance = variance/n-mean*mean
  sd = Math.sqrt(variance)
  cum = sum1 = sum2 = sum0 = 0
  printf("★ ポアソン分布へのあてはめ ★\n\n")
  printf(" 平均値 = %g\n", mean)
  printf("  分散 = %g\n", variance)
  printf("標準偏差 = %g\n\n", sd)
  printf("ポアソン定数 λ = %g\n\n", mean)
  sep(47)
  printf("%4s%10s%10s%10s%13s\n", "X", "観察度数", "相対度数", "理論比", "期待値")
  sep(47)
  for (i = 0; i < nc; i++) {
    tp = (i == nc-1) ? 1-sum1 : Math.exp(-mean)*Math.pow(mean, i)/fac(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("%4s%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-1; up >= 0; up--) {
    chk += expectation[up]
    if (chk >= 1.0) break
  }
  if (low != nc && 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 -1) {
      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("カイ二乗値 = %.5f\n", chi_sq)
    printf("  自由度 = %i\n", df)
    printf(" 有意確率 = %.5f\n\n", xxp(chi_sq, df))
  }
  printf("=====================================================\n\n")
      
}
//-->
</script>
</head>

<body bgcolor="#ffffff">
<font size="+2"><b>ポアソン分布へのあてはめ・適合度の検定</b></font> <a  href="src/poisson-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/poisson-fit.html">使用法</a></td>
</tr></table>

<p>
観察度数 <input name="data" size=70 value="27,61,77,71,54,35,20,11,6,2,1"><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/GoodnessOfFitness/poissondist.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>

サブ fac.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
サブ fixed.js   Last modified: Mar 25, 2004

・ 直前のページへ戻る  ・ E-mail to Shigenobu AOKI

Made with Macintosh