前回までに分布特性を把握するためのいくつかの指標を説明し、 その使い方や注意点を喚起した。 今回は、単純集計としてよく利用される頻度集計やクロス集計の方法を紹介する。
iv. 統計関連
/* Lesson 09-1 */ /* File Name = les0901.sas 12/08/05 */ data gakusei; infile 'all05be.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 09:54 Wednesday, December 7, 2005 OBS SEX SHINTYOU TAIJYUU KYOUI JITAKU KODUKAI CARRYER TSUUWA 1 F 145.0 38 . J 10000 . 2 F 146.7 41 85 J 10000 Vodafone 6000 3 F 148.0 42 . J 50000 . 4 F 148.0 43 80 J 50000 DoCoMo 4000 5 F 148.9 . . J 60000 . SAS システム 2 09:54 Wednesday, December 7, 2005 Cumulative Cumulative SEX Frequency Percent Frequency Percent ------------------------------------------------- F 115 34.0 115 34.0 M 223 66.0 338 100.0 Frequency Missing = 5 Cumulative Cumulative JITAKU Frequency Percent Frequency Percent ---------------------------------------------------- G 109 36.8 109 36.8 J 187 63.2 296 100.0 Frequency Missing = 47 Cumulative Cumulative CARRYER Frequency Percent Frequency Percent ------------------------------------------------------ DDIp 2 1.7 2 1.7 DoCoMo 54 44.6 56 46.3 J-PHONE 10 8.3 66 54.5 No 5 4.1 71 58.7 Vodafone 17 14.0 88 72.7 Willcom 1 0.8 89 73.6 au 32 26.4 121 100.0 Frequency Missing = 222 SAS システム 4 09:54 Wednesday, December 7, 2005 TABLE OF SEX BY JITAKU SEX JITAKU Frequency| Percent | Row Pct | Col Pct |G |J | Total ---------+--------+--------+ F | 34 | 66 | 100 | 11.56 | 22.45 | 34.01 | 34.00 | 66.00 | | 31.48 | 35.48 | ---------+--------+--------+ M | 74 | 120 | 194 | 25.17 | 40.82 | 65.99 | 38.14 | 61.86 | | 68.52 | 64.52 | ---------+--------+--------+ Total 108 186 294 36.73 63.27 100.00 Frequency Missing = 49 SAS システム 7 09:54 Wednesday, December 7, 2005 TABLE OF SEX BY CARRYER SEX CARRYER Frequency| Percent | Row Pct | Col Pct |DDIp |DoCoMo |J-PHONE |No | Total ---------+--------+--------+--------+--------+ F | 1 | 22 | 4 | 1 | 50 | 0.83 | 18.33 | 3.33 | 0.83 | 41.67 | 2.00 | 44.00 | 8.00 | 2.00 | | 50.00 | 40.74 | 44.44 | 20.00 | ---------+--------+--------+--------+--------+ M | 1 | 32 | 5 | 4 | 70 | 0.83 | 26.67 | 4.17 | 3.33 | 58.33 | 1.43 | 45.71 | 7.14 | 5.71 | | 50.00 | 59.26 | 55.56 | 80.00 | ---------+--------+--------+--------+--------+ Total 2 54 9 5 120 1.67 45.00 7.50 4.17 100.00 (Continued) SAS システム 9 09:54 Wednesday, December 7, 2005 TABLE OF SEX BY CARRYER SEX CARRYER Frequency| Percent | Row Pct | Col Pct |Vodafone|Willcom |au | Total ---------+--------+--------+--------+ F | 9 | 1 | 12 | 50 | 7.50 | 0.83 | 10.00 | 41.67 | 18.00 | 2.00 | 24.00 | | 52.94 | 100.00 | 37.50 | ---------+--------+--------+--------+ M | 8 | 0 | 20 | 70 | 6.67 | 0.00 | 16.67 | 58.33 | 11.43 | 0.00 | 28.57 | | 47.06 | 0.00 | 62.50 | ---------+--------+--------+--------+ Total 17 1 32 120 14.17 0.83 26.67 100.00 Frequency Missing = 223
≪前略≫ proc freq data=gakusei order=freq; : 頻度の高いもの順 tables sex jitaku carryer; run; proc freq data=gakusei order=freq; : 頻度の高いもの順 tables sex*jitaku; tables sex*carryer; tables jitaku*carryer; run; ≪後略≫
/* Lesson 09-4 */ /* File Name = les0904.sas 12/08/05 */ data gakusei; infile 'all05be.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 09:55 Wednesday, December 7, 2005 Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ -149 6 1.8 6 1.8 150-159 49 14.9 55 16.8 160-169 114 34.8 169 51.5 170-179 137 41.8 306 93.3 180- 22 6.7 328 100.0 Frequency Missing = 15 SAS システム 3 09:55 Wednesday, December 7, 2005 TABLE OF SEX BY SHINTYOU SEX SHINTYOU Frequency| Percent | Row Pct | Col Pct | -149 |150-159 |160-169 |170-179 |180- | Total ---------+--------+--------+--------+--------+--------+ F | 6 | 47 | 53 | 2 | 0 | 108 | 1.83 | 14.37 | 16.21 | 0.61 | 0.00 | 33.03 | 5.56 | 43.52 | 49.07 | 1.85 | 0.00 | | 100.00 | 95.92 | 46.90 | 1.46 | 0.00 | ---------+--------+--------+--------+--------+--------+ M | 0 | 2 | 60 | 135 | 22 | 219 | 0.00 | 0.61 | 18.35 | 41.28 | 6.73 | 66.97 | 0.00 | 0.91 | 27.40 | 61.64 | 10.05 | | 0.00 | 4.08 | 53.10 | 98.54 | 100.00 | ---------+--------+--------+--------+--------+--------+ Total 6 49 113 137 22 327 1.83 14.98 34.56 41.90 6.73 100.00 Frequency Missing = 16 SAS システム 6 09:55 Wednesday, December 7, 2005 ------------------------------- SEX=' ' -------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ 160-169 1 100.0 1 100.0 Frequency Missing = 4 SAS システム 7 09:55 Wednesday, December 7, 2005 -------------------------------- SEX=F --------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ -149 6 5.6 6 5.6 150-159 47 43.5 53 49.1 160-169 53 49.1 106 98.1 170-179 2 1.9 108 100.0 Frequency Missing = 7 SAS システム 8 09:55 Wednesday, December 7, 2005 -------------------------------- SEX=M --------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ 150-159 2 0.9 2 0.9 160-169 60 27.4 62 28.3 170-179 135 61.6 197 90.0 180- 22 10.0 219 100.0 Frequency Missing = 4
/* Lesson 09-5 */ /* File Name = les0905.sas 12/08/05 */ data gakusei; infile 'all05be.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 09:55 Wednesday, December 7, 2005 ---------------------------------------------------------------------- | | SEX | | |---------------------------------------------------| | | F | M | | |-------------------------+-------------------------| | | JITAKU | JITAKU | | |-------------------------+-------------------------| | | G | J | G | J | |----------------+------------+------------+------------+------------| |KODUKAI|N | 32.00| 64.00| 73.00| 117.00| | |--------+------------+------------+------------+------------| | |MEAN | 78437.50| 35117.19| 84424.66| 25666.67| | |--------+------------+------------+------------+------------| | |STD | 60032.75| 30802.07| 53587.91| 34023.57| ---------------------------------------------------------------------- SAS システム 3 09:55 Wednesday, December 7, 2005 ---------------------------------------------------------------------- | | SHINTYOU | | |---------------------------------------------------| | | -149 | 150-159 | 160-169 | | |------------+-------------------------+------------| | | SEX | SEX | SEX | | |------------+-------------------------+------------| | | F | F | M | F | |----------------+------------+------------+------------+------------| |TAIJYUU|N | 5.00| 37.00| 2.00| 35.00| | |--------+------------+------------+------------+------------| | |MEAN | 41.80| 46.99| 54.50| 51.21| | |--------+------------+------------+------------+------------| | |STD | 2.59| 4.27| 9.19| 3.50| ---------------------------------------------------------------------- (CONTINUED) SAS システム 4 09:55 Wednesday, December 7, 2005 ---------------------------------------------------------------------- | | SHINTYOU | | |---------------------------------------------------| | | 160-169 | 170-179 | 180- | | |------------+-------------------------+------------| | | SEX | SEX | SEX | | |------------+-------------------------+------------| | | M | F | M | M | |----------------+------------+------------+------------+------------| |TAIJYUU|N | 60.00| 0.00| 135.00| 22.00| | |--------+------------+------------+------------+------------| | |MEAN | 58.59| .| 62.80| 67.25| | |--------+------------+------------+------------+------------| | |STD | 7.60| .| 7.49| 7.64| ----------------------------------------------------------------------
data math; infile 'foo.dat' lrecl=230;
data math; infile 'foo.dat' lrecl=230 truncover;
input kamoku $ 2 kesseki $ 3 k_code $ 10-11 t_score 12-14 s_scor01 103-104 s_scor02 105-106 s_scor03 107-108 s_scor04 109-110 ;
data math; infile 'foo.dat' firstobs=4;