*評定段階尺度データの情報量計算マクロ. define infofreq (var=!charend('/') /type=!default(1)!charend('/') /* 1=全評定尺度の最大値がカテゴリ数 else=各項目の最大値 */ /freq=!default(1)!charend('/') /* 1=頻度 else=% */ /sort=!default(2)!charend('/') /* 1=ソートする else=ソートしない */ ). preserve. set mxloop= 2000. matrix. get x /file=*/variables=!var/missing=omit/sysmis=omit/names=nx. *type 1 すべての変数のカテゴリ数が同じ。既定値。. *compute type=1. compute type=!type. !if (!type=1) !then print type/title="すべての変数のカテゴリ数が同じ(すべての変数における最大カテゴリ数)". !else print type/title="個々の変数の最大カテゴリ数". !ifend. *tbl 1 頻度表 2=パーセンテージ表。. compute tbl=!freq. !if (!freq=1) !then print tbl/title="頻度表". !else print tbl/title="パーセンテージ表". !ifend. *sort 1 ソートする 2=ソートしない. compute srt=!sort. !if (!sort=1) !then print srt/title="相対情報量順". !else print srt/title="出現変数順". !ifend. print nx/format=a8. *design の出力を1,2,3...とするため num. compute num={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22, 23,24,25,26,27,28,29,30}. compute num=t(num). compute vnum={"v1","v2","v3","v4","v5","v6","v7","v8","v9","v10","v11","v12","v13","v14","v15"}. *print vnum/format a8. compute #nvar=ncol(nx). compute nsample=nrow(x). print nsample/title="サンプルサイズ". *全データの最大カテゴリ数 maxcat. compute maxcat=mmax(x). compute mx=make(1,(1+maxcat),0). compute icat=make(1,1,0). *カテゴリの1,0展開 結果を d に 反応変数. compute x1=x(:,(#nvar)). compute gmax=cmax(x1). compute x1={num(1:gmax,1);x1}. compute #row1=nsample+gmax. compute d=design(x1). compute d=d((gmax+1):#row1,:). compute ncat=ncol(d). *print ncat. *合成変数のダミー変数. loop c = 1 to #nvar. *compute c=1. compute aa=make(nsample,1,0). compute aa=aa+x(:,c). compute #nnum=mmax(num). compute #mxaa=mmax(aa). do if (#mxaa>#nnum). loop inum=(#nnum+1) to #mxaa. compute num={num;inum}. end loop. end if. *カテゴリの1,0展開 結果を z に. compute cmaxs=cmax(aa). compute x1=aa. * compute x1={num(1:cmaxs,1);x1}. compute x1={num(1:maxcat,1);x1}. compute z=design(x1). * compute #row1=nsample+cmaxs. * compute z=z((cmaxs+1):#row1,:). compute #row1=nsample+maxcat. compute z=z((maxcat+1):#row1,:). *個々の計算. compute freq=csum(z). * print freq. *print nx(c)/format a8. ********************************. compute as=0. do if (cmaxs0). * print freq(1,cmaxs+1). compute as=1. end if. end if. do if ((ncol(freq)>maxcat) or (as=1)). print nx(c)/title="0以下の値が入ってます。要データチェック。この処理は暫定です。"/format= a8. print freq/cnames=vnum. compute freq=freq(1,1:maxcat). end if. ********************************. *クロス表内に0がある場合. compute freq0=freq. compute zero=.50. do if (all(freq)=0). * compute z0=freq1). compute freq0=freq0&/rsum(freq0)*100. end if. compute mm={info,freq0}. compute mx={mx;mm}. compute icat={icat;kend}. end loop. compute mx=mx(2:(ncol(nx)+1),:). *print mx. compute icat=icat(2:(ncol(nx)+1),:). *print icat. compute vname={"name","info",vnum(1:maxcat),"icat"}. save {t(nx),mx,icat}/outfile=*/names=vname/string="name". end matrix. ***********************************. compute poinit=2**info. compute rinfo=info/(ln(icat)/ln(2)). !let !ttl= "評定の分布(". **********************. !if (!freq=1) !then format info to icat(f6.0). !let !ttl=!concat(!ttl,"頻度) と情報量("). !else format info to icat(f6.1). format icat(f6.0). !let !ttl=!concat(!ttl,"パーセンテージ) と情報量("). !ifend. **********************. *sort 1 ソートする 2=ソートしない. compute srt=!sort. !if (!sort=1) !then sort case by rinfo. !let !ttl=!quote(!concat(!ttl,"相対情報量順)")). !else !let !ttl=!quote(!concat(!ttl,"出現変数順)")). !ifend **********************. format info rinfo poinit(f8.2). var labels name "変数名"/ poinit "実質使用評定段階"/ rinfo "相対情報量"/ info "情報量"/ icat "総評定段階数". set ovar=labels. SUMMARIZE /TABLES=name poinit rinfo info to icat /FORMAT=VALIDLIST NOCASENUM noTOTAL /TITLE=!ttl /MISSING=VARIABLE /CELLS=NONE. restore. !enddefine. /* infofreq var=helpful to gentle/type=1/freq=1/sort=2. */.