前回までに分布特性を把握するためのいくつかの指標を説明し、 その使い方や注意点を喚起した。 今回は、単純集計としてよく利用される頻度集計(クロス集計)の方法を紹介する。
/* Lesson 09-1 */ /* File Name = les0901.sas 06/17/04 */ data gakusei; infile 'all04a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; proc print data=gakusei(obs=5); run; : proc freq data=gakusei; : 頻度を算出 tables sex jitaku carryer; : 一変量ごとに run; : proc freq data=gakusei; : 頻度を算出 tables sex*jitaku; : 二変量の組み合わせで tables sex*carryer; : tables jitaku*carryer; : run; :
SAS システム 1 15:19 Tuesday, June 15, 2004 OBS SEX SHINTYOU TAIJYUU KYOUI JITAKU KODUKAI CARRYER TSUUWA 1 F 145.0 38 . J 10000 . 2 F 148.0 42 . J 50000 . 3 F 148.0 43 80 J 50000 DoCoMo 4000 4 F 148.9 . . J 60000 . 5 F 149.0 45 . G 60000 . SAS システム 2 15:19 Tuesday, June 15, 2004 Cumulative Cumulative SEX Frequency Percent Frequency Percent ------------------------------------------------- F 99 33.8 99 33.8 M 194 66.2 293 100.0 Frequency Missing = 3 Cumulative Cumulative JITAKU Frequency Percent Frequency Percent ---------------------------------------------------- G 96 36.6 96 36.6 J 166 63.4 262 100.0 Frequency Missing = 34 Cumulative Cumulative CARRYER Frequency Percent Frequency Percent ------------------------------------------------------ DDIp 2 2.6 2 2.6 DoCoMo 36 46.8 38 49.4 J-PHONE 10 13.0 48 62.3 No 3 3.9 51 66.2 Vodafone 8 10.4 59 76.6 au 18 23.4 77 100.0 Frequency Missing = 219 SAS システム 4 15:19 Tuesday, June 15, 2004 TABLE OF SEX BY JITAKU SEX JITAKU Frequency| Percent | Row Pct | Col Pct |G |J | Total ---------+--------+--------+ F | 29 | 60 | 89 | 11.15 | 23.08 | 34.23 | 32.58 | 67.42 | | 30.53 | 36.36 | ---------+--------+--------+ M | 66 | 105 | 171 | 25.38 | 40.38 | 65.77 | 38.60 | 61.40 | | 69.47 | 63.64 | ---------+--------+--------+ Total 95 165 260 36.54 63.46 100.00 Frequency Missing = 36 SAS システム 7 15:19 Tuesday, June 15, 2004 TABLE OF SEX BY CARRYER SEX CARRYER Frequency| Percent | Row Pct | Col Pct |DDIp |DoCoMo |J-PHONE |No |Vodafone|au | Total ---------+--------+--------+--------+--------+--------+--------+ F | 1 | 16 | 4 | 1 | 5 | 7 | 34 | 1.32 | 21.05 | 5.26 | 1.32 | 6.58 | 9.21 | 44.74 | 2.94 | 47.06 | 11.76 | 2.94 | 14.71 | 20.59 | | 50.00 | 44.44 | 44.44 | 33.33 | 62.50 | 38.89 | ---------+--------+--------+--------+--------+--------+--------+ M | 1 | 20 | 5 | 2 | 3 | 11 | 42 | 1.32 | 26.32 | 6.58 | 2.63 | 3.95 | 14.47 | 55.26 | 2.38 | 47.62 | 11.90 | 4.76 | 7.14 | 26.19 | | 50.00 | 55.56 | 55.56 | 66.67 | 37.50 | 61.11 | ---------+--------+--------+--------+--------+--------+--------+ Total 2 36 9 3 8 18 76 2.63 47.37 11.84 3.95 10.53 23.68 100.00 Frequency Missing = 220 SAS システム 10 15:19 Tuesday, June 15, 2004 TABLE OF JITAKU BY CARRYER JITAKU CARRYER Frequency| Percent | Row Pct | Col Pct |DDIp |DoCoMo |J-PHONE |No |Vodafone|au | Total ---------+--------+--------+--------+--------+--------+--------+ G | 1 | 13 | 4 | 0 | 3 | 5 | 26 | 1.41 | 18.31 | 5.63 | 0.00 | 4.23 | 7.04 | 36.62 | 3.85 | 50.00 | 15.38 | 0.00 | 11.54 | 19.23 | | 100.00 | 38.24 | 44.44 | 0.00 | 42.86 | 29.41 | ---------+--------+--------+--------+--------+--------+--------+ J | 0 | 21 | 5 | 3 | 4 | 12 | 45 | 0.00 | 29.58 | 7.04 | 4.23 | 5.63 | 16.90 | 63.38 | 0.00 | 46.67 | 11.11 | 6.67 | 8.89 | 26.67 | | 0.00 | 61.76 | 55.56 | 100.00 | 57.14 | 70.59 | ---------+--------+--------+--------+--------+--------+--------+ Total 1 34 9 3 7 17 71 1.41 47.89 12.68 4.23 9.86 23.94 100.00 Frequency Missing = 225
/* Lesson 09-4 */ /* File Name = les0904.sas 06/17/04 */ data gakusei; infile 'all04a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; proc format; : 階級を作る。class shintyou の意 value clshint low-<150=' -149' : 階級の定義 1 150-<160='150-159' : 2 160-<170='160-169' : 3 170-<180='170-179' : 4 180-high='180- ' : 5 other ='missing'; : 6 run; : proc print data=gakusei(obs=5); run; proc freq data=gakusei; : 頻度を算出 tables shintyou; : 一変量ごとに format shintyou clshint.; : 連続変量をグループ化することの指定 run; : : proc freq data=gakusei; : 頻度を算出 tables sex*shintyou; : 二変量の組合わせで format shintyou clshint.; : 連続変量をグループ化することの指定 run; : : proc sort data=gakusei; : 今までの方法で実現しようとすると by sex; : run; : proc freq data=gakusei; : tables shintyou; : format shintyou clshint.; : 連続変量をグループ化することの指定 by sex; : 性別ごとに run; :
SAS システム 2 15:19 Tuesday, June 15, 2004 Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ -149 5 1.8 5 1.8 150-159 41 14.4 46 16.1 160-169 102 35.8 148 51.9 170-179 117 41.1 265 93.0 180- 20 7.0 285 100.0 Frequency Missing = 11 SAS システム 3 15:19 Tuesday, June 15, 2004 TABLE OF SEX BY SHINTYOU SEX SHINTYOU Frequency| Percent | Row Pct | Col Pct | -149 |150-159 |160-169 |170-179 |180- | Total ---------+--------+--------+--------+--------+--------+ F | 5 | 40 | 47 | 2 | 0 | 94 | 1.76 | 14.08 | 16.55 | 0.70 | 0.00 | 33.10 | 5.32 | 42.55 | 50.00 | 2.13 | 0.00 | | 100.00 | 97.56 | 46.53 | 1.71 | 0.00 | ---------+--------+--------+--------+--------+--------+ M | 0 | 1 | 54 | 115 | 20 | 190 | 0.00 | 0.35 | 19.01 | 40.49 | 7.04 | 66.90 | 0.00 | 0.53 | 28.42 | 60.53 | 10.53 | | 0.00 | 2.44 | 53.47 | 98.29 | 100.00 | ---------+--------+--------+--------+--------+--------+ Total 5 41 101 117 20 284 1.76 14.44 35.56 41.20 7.04 100.00 Frequency Missing = 12 SAS システム 6 15:19 Tuesday, June 15, 2004 ------------------------------- SEX=' ' -------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ 160-169 1 100.0 1 100.0 Frequency Missing = 2 SAS システム 7 15:19 Tuesday, June 15, 2004 -------------------------------- SEX=F --------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ -149 5 5.3 5 5.3 150-159 40 42.6 45 47.9 160-169 47 50.0 92 97.9 170-179 2 2.1 94 100.0 Frequency Missing = 5 SAS システム 8 15:19 Tuesday, June 15, 2004 -------------------------------- SEX=M --------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ 150-159 1 0.5 1 0.5 160-169 54 28.4 55 28.9 170-179 115 60.5 170 89.5 180- 20 10.5 190 100.0 Frequency Missing = 4
/* Lesson 09-5 */ /* File Name = les0905.sas 06/17/04 */ data gakusei; infile 'all04a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; proc format; value clshint low-<150=' -149' 150-<160='150-159' 160-<170='160-169' 170-<180='170-179' 180-high='180- ' other ='missing'; run; proc print data=gakusei(obs=5); run; proc tabulate data=gakusei; : 要約統計量の表の作成 class sex jitaku; : 特性変数であることの宣言 var kodukai; : 集計する変量名 tables kodukai*(n mean std),sex*jitaku; : 表示内容、分類変量名 run; : proc tabulate data=gakusei; : class shintyou sex; : var taijyuu; : tables taijyuu*(n mean std),shintyou*sex; : format shintyou clshint.; : 連続変量をグループ化することの指定 run; :
SAS システム 2 15:19 Tuesday, June 15, 2004 ---------------------------------------------------------------------- | | SEX | | |---------------------------------------------------| | | F | M | | |-------------------------+-------------------------| | | JITAKU | JITAKU | | |-------------------------+-------------------------| | | G | J | G | J | |----------------+------------+------------+------------+------------| |KODUKAI|N | 27.00| 58.00| 65.00| 102.00| | |--------+------------+------------+------------+------------| | |MEAN | 83518.52| 36163.79| 85738.46| 27137.25| | |--------+------------+------------+------------+------------| | |STD | 63742.49| 31883.75| 54907.39| 35913.55| ---------------------------------------------------------------------- SAS システム 3 15:19 Tuesday, June 15, 2004 ---------------------------------------------------------------------- | | SHINTYOU | | |---------------------------------------------------| | | -149 | 150-159 | 160-169 | | |------------+-------------------------+------------| | | SEX | SEX | SEX | | |------------+-------------------------+------------| | | F | F | M | F | |----------------+------------+------------+------------+------------| |TAIJYUU|N | 4.00| 30.00| 1.00| 29.00| | |--------+------------+------------+------------+------------| | |MEAN | 42.00| 47.02| 61.00| 50.78| | |--------+------------+------------+------------+------------| | |STD | 2.94| 4.65| .| 3.27| ---------------------------------------------------------------------- (CONTINUED) SAS システム 4 15:19 Tuesday, June 15, 2004 ---------------------------------------------------------------------- | | SHINTYOU | | |---------------------------------------------------| | | 160-169 | 170-179 | 180- | | |------------+-------------------------+------------| | | SEX | SEX | SEX | | |------------+-------------------------+------------| | | M | F | M | M | |----------------+------------+------------+------------+------------| |TAIJYUU|N | 54.00| 0.00| 115.00| 20.00| | |--------+------------+------------+------------+------------| | |MEAN | 58.69| .| 62.82| 67.58| | |--------+------------+------------+------------+------------| | |STD | 7.88| .| 6.95| 7.95| ----------------------------------------------------------------------
/* Lesson 09-6 */ /* File Name = les0906.sas 06/17/04 */ data gakusei; infile 'all04a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; if sex^='M' & sex^='F' then delete; : 性別不明は除外する proc print data=gakusei(obs=5); run; proc sort data=gakusei; by sex; run; proc univariate data=gakusei plot; var shintyou taijyuu kyoui kodukai; by sex; run;
SAS システム 8 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=F --------------------------------- Univariate Procedure Variable=SHINTYOU Normal Probability Plot 172.5+ +*+++* | *****+*+*+* | **********+ | ********++ | ********+ 147.5+*+++*++** +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2 SAS システム 15 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=F --------------------------------- Univariate Procedure Variable=TAIJYUU Normal Probability Plot 57.5+ +**+*+++*+ | **********+**+ 47.5+ *********+++ | +***+*+***+ 37.5+++*+++* +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2 SAS システム 22 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=F --------------------------------- Univariate Procedure Variable=KYOUI Normal Probability Plot 92.5+ ++++*++++ | *******++**+++* 82.5+ ****+*+*+*++++ | ++*+*+**++++ 72.5+++++*++ +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2 SAS システム 29 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=F --------------------------------- Univariate Procedure Variable=KODUKAI Normal Probability Plot 325000+ * | | * 175000+ ** * +++++ | *****+++++ | ++********* 25000+* * * ******************* +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2 SAS システム 36 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=M --------------------------------- Univariate Procedure Variable=SHINTYOU Normal Probability Plot 187.5+ ** | *****+*+**+ | ********++ 172.5+ *********** | *********++ | * ********+ 157.5+*++ +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2 SAS システム 43 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=M --------------------------------- Univariate Procedure Variable=TAIJYUU Normal Probability Plot 105+ * | * | ** ++ 75+ *******+*++++ | *************** | ** **************+ 45+**++*+++++ +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2 SAS システム 50 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=M --------------------------------- Univariate Procedure Variable=KYOUI Normal Probability Plot 115+ * * + | **+**+++++++ | **********+**+ 85+ *************++ | ++*+**+*+++ |++++ 55+ * +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2 SAS システム 57 16:50 Tuesday, June 15, 2004 -------------------------------- SEX=M --------------------------------- Univariate Procedure Variable=KODUKAI Normal Probability Plot 325000+ * | | * 175000+ **** *+**+++ | ******++++++ | ++******+ 25000+** ************************** +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2
data gakusei; infile 'all04a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; dekasa=shintyou+taijyuu+kyoui; : 変量間の加減乗除 kyo_2=kyoui**2; : 二乗 kyo_sr=sqrt(kyoui); : ルート
[算術演算子]
[数値関数]