メイン qt3.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="eigen.js">document.write("eigen.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 "0000000000000".substring(0, ww)+i
}
function names(str, i)
{
return str+zfi(2, i+1)
}
function n_sol(m, ne)
{
var i
if (isNaN(i = parseFloat(ne)) || i < 1 || i > m) {
return m
}
else {
return i
}
}
var ITEM = 1, CATEGORY = 2
var itemnum, itemnum2, varno
function sort(x, n, ip)
{
var min, minp, i, j, temp
for (i = 0; i < n-1; i++) {
min = x[i][ip]
minp = i
for (j = i+1; j < n; j++) {
if (x[j][ip] < min) {
min = x[j][ip]
minp = j
}
}
if (i != minp) {
temp = x[i][ip]
x[i][ip] = min
x[minp][ip] = temp
}
}
for (i = 0; i < n; i++) {
if (x[i][ip] != i+1) {
return 0
}
}
return 1
}
function itemno(item, cat, junjo, data, nc, value)
{
var i, j, k, nobe, flag0 = 0, flag, work, catj
for (j = 0; j < item; j++) {
catj = flag = 0
for (i = 0; i < nc; i++) {
work = data[i][j]
if (Math.floor(work) != work) {
if (flag == 0) {
printf("\nアイテム変数 %s の値が正整数値ではありません。\n", names("Var", j))
flag = flag0 = 1
}
}
value[catj][j] = work
for (k = 0; k <= catj; k++) {
if (value[k][j] == work) {
break
}
}
if (k == catj) {
catj++
if (catj > 100) {
printf("アイテム変数 %s の取る値の種類が多すぎます。\n", names("Var", j))
}
}
}
cat[j] = catj
if (catj == 1) {
printf("アイテム変数 %s は,一種類の値しか取りません。この変数は分析に使用しないでください。\n", names("Var", j))
flag0 = 1
}
else if (sort(value, catj, j) == 0) {
for (i = 0; i < nc; i++) {
work = data[i][j]
for (k = 0; k < catj; k++) {
if (work != k+1 && work == value[k][j]) {
data[i][j] = k+1
break
}
}
}
}
}
if (flag0) {
return -99
}
else {
nobe = 0
for (i = 0; i < item; i++) {
junjo[i] = nobe
nobe += cat[i]
}
return nobe
}
}
function eig000(r, vec, val, n, fnorm, ne0)
{
var i, j, naxis, temp
naxis = 0
eigen(r, n, n, 1e-10 , val, vec)
for (j = 0; j < n-1; j++) {
val[j] = val[j+1]
if (val[j] > 1e-5) {
naxis++
}
temp = 0.0
for (i = 0; i < n; i++) {
temp += vec[j+1][i]*vec[j+1][i]
}
temp = Math.sqrt(fnorm/temp)
for (i = 0; i < n; i++) {
vec[j][i] = vec[j+1][i]*temp
}
}
printf("\n 解 固有値 相関係数\n")
for (i = 0; i < naxis; i++) {
printf("%4i%13.5f%13.5f\n", i+1, val[i], Math.sqrt(val[i]))
}
return n_sol(naxis, ne0)
}
function part1(nc, caseno, nobe, ncc, ni, datamat, r, fnorm, val, vec, scr, ne0)
{
var num, i, ie, is, j, k, naxis, naxis2, sum, temp
for (j = 0; j < nobe; j++) {
for (k = 0; k <= j; k++) {
r[k][j] = 0
}
}
for (i = 0; i < nc; i++) {
temp = 1.0/ncc[i]
for (j = 0; j < nobe; j++) {
if (datamat[i][j] == 1) {
for (k = 0; k <= j; k++) {
if (datamat[i][k] == 1) {
r[k][j] += temp
}
}
}
}
}
for (j = 0; j < nobe; j++) {
for (k = 0; k <= j; k++) {
r[j][k] = r[k][j] /= Math.sqrt(ni[j]*ni[k])
}
}
naxis = eig000(r, vec, val, nobe, fnorm, ne0)
for (i = 0; i < nobe; i++) {
temp = 1.0/Math.sqrt(ni[i])
for (j = 0; j < naxis; j++) {
vec[j][i] *= temp
}
}
printf("\n***** カテゴリースコア *****\n")
for (is = ie = 0; ie != naxis; is = ie) {
ie = (ie+Math.floor((80-13)/10) < naxis ? ie+Math.floor((80-13)/10) : naxis)
printf("\nアイテム-カテゴリー")
for (i = is; i < ie; i++) {
printf("%"+(i == is ? 9 : 10)+"s", names("Axis", i))
}
printf((itemnum[0] == 0) ? "\n\n" : "\n")
for (i = 0; i < nobe; i++) {
if (itemnum[i] == 0) {
printf(" %8s ", names("Var", varno[i]))
for (j = is; j < ie; j++) {
printf("%10.5f", vec[j][i])
}
printf("\n")
}
else if (itemnum[i] == 1) {
printf("\n%3i %8s %3s ", i+1, names("Var", varno[i]), itemnum2[i])
for (j = is; j < ie; j++) {
printf("%10.5f", vec[j][i])
}
printf("\n")
}
else {
printf("%3i %3s ",
i+1, itemnum2[i])
for (j = is; j < ie; j++) {
printf("%10.5f", vec[j][i])
}
printf("\n")
}
}
}
naxis2 = (naxis < 5 ? naxis : 5)
num = 0
printf("\n***** サンプルスコア *****\n")
for (is = ie = 0; ie != naxis; is = ie) {
ie = ((ie+Math.floor((80-7)/10)) < naxis ? (ie+Math.floor((80-7)/10)) : naxis)
printf("\nケース ")
for (i = is; i < ie; i++) {
printf("%10s", names("Axis", i))
}
printf("\n\n")
for (i = 0; i < nc; i++) {
for (j = is; j < ie; j++) {
sum = 0.0
for (k = 0; k < nobe; k++) {
if (datamat[i][k] == 1) {
sum += datamat[i][k]*vec[j][k]
}
}
scr[j] = sum/(Math.sqrt(val[j])*ncc[i])
}
printf("%6i ", caseno[i]+1)
for (j = is; j < ie; j++) {
printf("%10.5f", scr[j])
}
printf("\n")
}
}
}
function part2(nc, caseno, nobe, ncc, ni, datamat, r, fnorm, val, vec, scr, ne0)
{
var num, i, ie, is, j, k, naxis, naxis2, sum, temp
for (j = 0; j < nc; j++) {
for (k = 0; k <= j; k++) {
r[k][j] = 0
}
}
for (i = 0; i < nobe; i++) {
temp = 1.0/ni[i]
for (j = 0; j < nc; j++) {
if (datamat[j][i] == 1) {
for (k = 0; k <= j; k++) {
if (datamat[k][i] == 1) {
r[k][j] += temp
}
}
}
}
}
for (j = 0; j < nc; j++) {
for (k = 0; k <= j; k++) {
r[j][k] = r[k][j] /= Math.sqrt(ncc[j]*ncc[k])
}
}
naxis = eig000(r, vec, val, nc, fnorm, ne0)
for (i = 0; i < nc; i++) {
temp = 1.0/Math.sqrt(ncc[i])
for (j = 0; j < naxis; j++) {
vec[j][i] *= temp
}
}
naxis2 = (naxis < 5 ? naxis : 5)
num = 0
printf("\n***** サンプルスコア *****\n")
ie = 0
for (is = ie = 0; ie != naxis; is = ie) {
ie = ((ie+Math.floor((80-7)/10)) < naxis ? (ie+Math.floor((80-7)/10)) : naxis)
printf("\nケース ")
for (i = is; i < ie; i++) {
printf("%10s", names("Axis", i))
}
printf("\n\n")
for (i = 0; i < nc; i++) {
printf("%6i ", caseno[i]+1)
for (j = is; j < ie; j++) {
printf("%10.5f", vec[j][i])
}
printf("\n")
}
}
printf("\n***** カテゴリースコア *****\n")
for (is = ie = 0; ie != naxis; is = ie) {
ie = (ie+Math.floor((80-13)/10) < naxis ? ie+Math.floor((80-13)/10) : naxis)
printf("\nアイテム-カテゴリー")
for (i = is; i < ie; i++) {
printf("%"+(i == is ? 9 : 10)+"s", names("Axis", i))
}
printf((itemnum[0] == 0) ? "\n\n" : "\n")
for (i = 0; i < nobe; i++) {
for (j = is; j < ie; j++) {
sum = 0.0
for (k = 0; k < nc; k++) {
if (datamat[k][i] == 1) {
sum += datamat[k][i]*vec[j][k]
}
}
scr[j] = sum/(Math.sqrt(val[j])*ni[i])
}
if (itemnum[i] == 0) {
printf(" %8s ", names("Var", varno[i]))
for (j = is; j < ie; j++) {
printf("%10.5f", scr[j])
}
printf("\n")
}
else if (itemnum[i] == 1) {
printf("\n%3i %8s %3s ", i+1, names("Var", varno[i]), itemnum2[i])
for (j = is; j < ie; j++) {
printf("%10.5f", scr[j])
}
printf("\n")
}
else {
printf("%3i %3s ", i+1, itemnum2[i])
for (j = is; j < ie; j++) {
printf("%10.5f", scr[j])
}
printf("\n")
}
}
}
}
function calc(data_string, ne0)
{
var datamat, cat, junjo, ncc, ni, caseno, i, ierr, iswdf = ITEM
var value, item, xx, j, nccat, nobe, ncase = 0, r, vec, scr, val, fnorm, work
var nc, nv, data
printf("★ 数量化 III 類 ★\n\n")
if ((data = getdata(data_string, 0)) == false) return
nc = data.length
nv = data[0].length
if (nc < 2) {
printf("ケース数が1以下です\n")
return
}
item = nv
ncc = makeVector(nc)
for (i = 0; i < nc; i++) {
ncc[i] = 0
}
iswdf = CATEGORY
for (i = 0; i < nc; i++) {
for (j = 0; j < item; j++) {
work = data[i][j]
if (Math.floor(work) != work) {
printf("整数値でないデータがあります\n")
return
}
if (work != 0 && work != 1) {
iswdf = ITEM
break
}
}
if (iswdf == ITEM) {
break
}
}
if (iswdf == ITEM) {
cat = makeVector(item)
junjo = makeVector(item)
value = makeMatrix(100, item)
nobe = itemno(item, cat, junjo, data, nc, value)
if (nobe <= 0) {
printf("データをチェックしてください\n")
return
}
else if (nobe > 500) {
printf("延べカテゴリー数が多すぎます\n")
return;
}
}
else {
nobe = item
}
varno = makeVector(nobe)
itemnum = makeVector(nobe)
itemnum2 = makeVector(nobe)
ni = makeVector(nobe)
datamat = makeMatrix(nc, nobe)
val = makeVector(nobe)
scr = makeVector(nobe)
r = makeMatrix(nobe, nobe)
vec = makeMatrix(nobe, nobe)
caseno = makeVector(nc)
for (i = 0; i < nobe; i++) {
ni[i] = 0
}
for (i = 0; i < nc; i++) {
if (iswdf == ITEM) {
for (j = 0; j < nobe; j++) {
datamat[ncase][j] = 0
}
for (j = 0; j < item; j++) {
xx = data[i][j]
datamat[ncase][junjo[j]+xx-1] = 1
}
}
else {
for (j = 0; j < nobe; j++) {
xx = data[i][j]
if (xx != 1 && xx != 0) {
printf("0・1以外の数値がありました\n")
return
}
datamat[ncase][j] = xx
}
}
caseno[ncase] = i
ncase++
}
printf("有効ケース数: %i\n", ncase)
if (iswdf == ITEM) {
printf("延べカテゴリー数: %d\n\n", nobe)
printf("アイテム カテゴリー数\n")
for (i = 0; i < item; i++) {
printf("%8s %9d\n", names("Var", i), cat[i])
}
}
if (iswdf == ITEM) {
nccat = 0
for (i = 0; i < item; i++) {
for (j = 0; j < cat[i]; j++) {
itemnum[nccat] = j+1
itemnum2[nccat] = value[j][i]
varno[nccat] = i
nccat++
}
}
}
else {
for (i = 0; i < nobe; i++) {
itemnum[i] = 0
varno[i] = i
}
}
for (i = 0; i < ncase; i++) {
for (j = 0; j < nobe; j++) {
if (datamat[i][j] == 1) {
ncc[i]++
ni[j]++
}
}
}
ierr = false
if (iswdf == CATEGORY) {
for (i = 0; i < nobe; i++) {
if (ni[i] == 0) {
printf("\nカテゴリー変数 %s への反応がゼロです。\n", names("Var", i))
ierr = true
}
}
}
for (i = 0; i < ncase; i++) {
if (ncc[i] == 0) {
printf("\nケース %i の反応がゼロです。\n", i+1)
ierr = true
}
}
if (ierr == true) {
return
}
fnorm = 0.0
for (i = 0; i < nobe; i++) {
fnorm += ni[i]
}
if (nc > nobe) {
part1(ncase, caseno, nobe, ncc, ni, datamat, r, fnorm, val, vec, scr, ne0)
}
else {
part2(ncase, caseno, nobe, ncc, ni, datamat, r, fnorm, val, vec, scr, ne0)
}
}
//-->
</script>
</head>
<body bgcolor="#ffffff">
<font size="+2"><b>数量化 III 類</b></font> <a href="src/qt3.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>
<table><tr>
<td><input type="button" name="calcurate" value="計算開始" onClick="calc(this.form.data.value, this.form.ne.value)"> </td>
<td><input type="button" name="clear" value="入力欄クリア" onClick="this.form.data.value=this.form.ne.value=''"> </td>
<td><input type="button" name="clear" value="出力欄クリア" onClick="this.form.result.value=''"> </td>
<td nowrap><img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="exa/qt3.html">使用法</a></td>
</tr></table>
<p>
求める解の個数<input name="ne" value="" size=5>(省略時は理論的に可能なだけ全部)<br>
入力欄<br><textarea name="data" ROWS=20 COLS=80></textarea><p>
出力欄<br><textarea name="result" ROWS=30 COLS=80></textarea>
</form>
<p><hr noshade>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../lecture/Qt/qt3.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>
サブ eigen.js Last modified: Mar 25, 2004
サブ io.js Last modified: Mar 25, 2004
直前のページへ戻る E-mail to Shigenobu AOKI