メイン cross.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="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 zfi(w, i)
{
  var ww = (""+i).length
  ww = ww > w ? 0 : w-ww
  return "000000000000000".substring(0, ww)+i
}

function vname(i, str)
{
  return "第"+zfi(2, i+1)+str
}

function cross(t, nr, nc)
{
  var i, j, expectation, chisq, df, p, one, five

  for (i = 0; i < nr; i++) {
    for (j = 0; j < nc; j++) {
      t[i][nc] += t[i][j]
    }
    for (j = 0; j <= nc; j++) {
      t[nr][j] += t[i][j]
    }
  }

  printf("★ 独立性の検定 ★\n      ")
  for (j = 0; j < nc; j++) {
    printf(" %6s", vname(j, "列"))
  }
  printf(" %6s\n", "合計")
  for (i = 0; i < nr; i++) {
    printf("%6s", vname(i, "行"))
    for (j = 0; j < nc; j++) {
      printf(" %6i", t[i][j])
    }
    printf(" %6i\n", t[i][j])
  }
  printf("%6s", "合計 ")
  for (j = 0; j < nc; j++) {
    printf(" %6i", t[i][j])
  }
  printf(" %6i\n\n", t[i][j])

  chisq = one = five = 0
  for (i = 0; i < nr; i++) {
    for (j = 0; j < nc; j++) {
      expectation = t[i][nc]*t[nr][j]/t[nr][nc]
      chisq += Math.pow(t[i][j]-expectation, 2)/expectation
      if (expectation < 5) {
        five++
        if (expectation < 1) {
          one++
        }
      }
    }
  }
  df = (nr-1)*(nc-1)
  p = xxp(chisq, df)
  printf("カイ二乗値 = %.5f\n", chisq)
  printf("    自由度 = %i\n", df)
  printf("      P 値 = %.5f\n", p)
  if (one > 0) {
    printf("期待値が1未満のセルがあります。検定結果は慎重に解釈すべきです。\n")
  }
  if (five >= nr*nc*0.2) {
    printf("期待値が5未満のセルが,全体のセルの20%%以上あります。検定結果は慎重に解釈すべきです。\n")
  }

  
}

function calc(data_string)
{
  var i, j, t0, t, nr, nc

  if ((t0 = getdata(data_string, 0)) != false) {
  
    if ((nr = t0.length) == 0) {
      printf("分割表が入力されていません\n")
      return
    }
    nc = t0[0].length
    if (nr < 2 || nc < 2) {
      printf("2行2列以上の大きさの分割表を対象にします\n")
      return
    }
    t = new Array(nr+1)
    for (i = 0; i <= nr; i++) {
      t[i] = new Array(nc+1)
      for (j = 0; j <= nc; j++) {
        t[i][j] = 0
      }
    }
    for (i = 0; i < nr; i++) {
      for (j = 0; j < nc; j++) {
        t[i][j] = t0[i][j]
      }
    }
    cross(t, nr, nc)
  }
  sep(40)
}
//-->
</script>
</head>

<body bgcolor="#ffffff">
<font size="+2"><b>独立性の検定</b></font> <a  href="src/cross.html"><img src="png/src.png" width=35 height=11 alt="src" align=top></a>     Last modified: Jun 01, 2006<hr noshade><p>
<font color="#ff0000" size="+2">以下のプログラムのサポートは終了しました。自己責任でお使い下さい。</font>

<form name=Result>
<script language="JavaScript">
<!--
//-->JavaScript がサポートされていないブラウザですか?
</script>
集計済みのクロス集計を入力し,独立性の検定を行う。<br>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../lecture/Cross/cross.html">手法の解説</a> <img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="exa/cross.html">使用法</a>
<hr>
<input type="button" name="calcurate" value="計算開始" onClick="calc(this.form.data.value)">  
<input type="button" name="clear" value="入力欄クリア" onClick="this.form.data.value=''">  
<input type="button" name="clear" value="出力欄クリア" onClick="this.form.result.value=''"><p>

<table><tr>
<td>入力欄<br><textarea name="data" ROWS=20 COLS=20></textarea></td>
<td>出力欄<br><textarea name="result" ROWS=20 COLS=80></textarea></td>
</tr></table>
</form>

<p><hr noshade>
<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><IMG SRC="../gra/ume5.png" width=121 height=37 ALT="Made with Macintosh">
</body>
</html>

サブ 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

Made with Macintosh