頻度集計とグループ内統計量

統計処理 01 クラス : 第10回(06/21/01)

前回までに分布特性を把握するためのいくつかの指標を説明し、 これらを各自のデータで実践してもらった。 今回は、単純集計としてよく利用される頻度集計(クロス集計)の方法を紹介する。
  1. レポートを拝見して : 電子メール分 : 25通 : 要確認

  2. 使用データ : 5年間の学生のアンケートデータ(all01.prn)

  3. 頻度集計(離散変量の場合) : 度数の把握、クロス表

    1. プログラム : Lesson 10-1 : les1001.sas
       /* Lesson 10-1 */
       /*    File Name = les1001.sas   06/21/01   */
      
      data gakusei;
        infile 'all01.prn';
        input seibetsu $ height weight chest jitaku $ kodukai;
      
      proc print data=gakusei(obs=10);          : きちんと読み込めたか確認のため
      run;                                      :
                                                :
      proc freq data=gakusei;                   : 頻度を算出
        tables seibetsu jitaku;                 : 一変量ごとで
      run;                                      :
      proc freq data=gakusei;                   : 頻度を算出
        tables seibetsu*jitaku;                 : 二変量の組み合わせで
      run;                                      :
      

    2. 出力結果 : les1001.lst :
      • 自宅生/下宿生の人数、自宅生/下宿生の人数。これらの組合わせの人数。
      • 頻度、割合(%)、累積頻度、累積割合(%)
      • 頻度、全体割合、縦割合、横割合
                                    SAS システム                             1
                                                10:08 Wednesday, June 20, 2001
      
         OBS    SEIBETSU    HEIGHT    WEIGHT    CHEST    JITAKU    KODUKAI
      
           1       F         145.0     38.0        .       J         10000
           2       F         148.0     42.0        .       J         50000
           3       F         148.9       .         .       J         60000
           4       F         149.0     45.0        .       G         60000
           5       F         150.0     46.0       86                 40000
           6       F         151.7     41.5       80       J         35000
           7       F         153.0     46.5       87       G         10000
           8       F         153.0     55.0       78       J         30000
           9       F         154.0     46.0        .                     .
          10       F         155.0     48.0       83       G        180000
      
                                    SAS システム                             2
                                                10:08 Wednesday, June 20, 2001
      
                                               Cumulative  Cumulative
               SEIBETSU   Frequency   Percent   Frequency    Percent 
               ------------------------------------------------------
               F                59      29.1          59       29.1  
               M               144      70.9         203      100.0  
      
                               Frequency Missing = 2
      
                                              Cumulative  Cumulative
                JITAKU   Frequency   Percent   Frequency    Percent 
                ----------------------------------------------------
                G              63      35.2          63       35.2  
                J             116      64.8         179      100.0  
      
      
                               Frequency Missing = 26
      
                                    SAS システム                             4
                                                10:08 Wednesday, June 20, 2001
      
                            TABLE OF SEIBETSU BY JITAKU
      
                        SEIBETSU     JITAKU
      
                        Frequency|
                        Percent  |
                        Row Pct  |
                        Col Pct  |G       |J       |  Total
                        ---------+--------+--------+
                        F        |     15 |     36 |     51
                                 |   8.43 |  20.22 |  28.65
                                 |  29.41 |  70.59 |
                                 |  24.19 |  31.03 |
                        ---------+--------+--------+
      
                        M        |     47 |     80 |    127
                                 |  26.40 |  44.94 |  71.35
                                 |  37.01 |  62.99 |
                                 |  75.81 |  68.97 |
                        ---------+--------+--------+
                        Total          62      116      178
                                    34.83    65.17   100.00
      
      
                        Frequency Missing = 27
      

    3. [補足] SAS は、パソコン画面のサイズ(正確には出力エリアのサイズ)によっては、 出力の縦横幅が変るように設計されています。 上記の出力中、「SEIBETSU x JITAKU」のクロス表は、 デフォルトの画面サイズ(何も指定しない場合)では、 縦に分断されたように表示されます。 皆さんの画面では縦方向の行数が少ないので、 クロス表が「小出し」に表示されるためです。 間にある 20行弱の不要部分を削除すると、視覚的にも理解しやすい クロス表を得ることができ、配布資料はそのような編集作業後のものです。 皆さんもレポート作成時にはこの様な編集作業を行って 親切なレポート作成を心掛けてください。

    4. [演習] 上記の例では文字型変量を使って集計を行ったが、 height 等の連続変量を使っても実行できる。 その際の出力はどのようになるかを予想し、その後実際に実行してみよ。 出力結果は何を表現し、また、予想は正しかったか?

  4. 頻度集計(連続変量の場合) : 度数の把握、クロス表

    1. プログラム : Lesson 10-2 : les1002.sas
       /* Lesson 10-2 */
       /*    File Name = les1002.sas   06/21/01   */
      
      data gakusei;
        infile 'all01.prn';
        input seibetsu $ height weight chest jitaku $ kodukai;
      
      proc format;                           : 新しい階級(clheight)を作る
        value clheight 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=10);       :
      run;                                   :
                                             :
      proc freq data=gakusei;                : 頻度を算出
        tables height;                       : 一変量ごとで
        format height clheight.;             : 連続変量をグループ化
      run;                                   :
                                             :
      proc freq data=gakusei;                : 頻度を算出
        tables height*seibetsu;              : 二変量の組合わせで
        format height clheight.;             : 連続変量をグループ化
      run;                                   :
                                             :
      proc sort data=gakusei;                : 並べ替え
        by seibetsu;                         : 性別で
      run;                                   :
      proc freq data=gakusei;                : 頻度を算出 : 上記とほぼ同じ結果になる
        tables height;                       : 一変量ごとで
        format height clheight.;             : 連続変量をグループ化
        by seibetsu;                         : 性別で
      run;                                   :
      

    2. 出力結果 : les1002.lst : 階級ごとの頻度
      • 各階級ごとの頻度、割合(%)、累積頻度、累積割合(%)
      
                                    SAS システム                             2
                                                11:58 Wednesday, June 20, 2001
      
                                              Cumulative  Cumulative
                HEIGHT   Frequency   Percent   Frequency    Percent 
               -----------------------------------------------------
                  -149          4       2.0           4        2.0  
               150-159         22      11.2          26       13.3  
               160-169         68      34.7          94       48.0  
               170-179         87      44.4         181       92.3  
               180-            15       7.7         196      100.0  
      
                               Frequency Missing = 9
      
                                    SAS システム                             3
                                                11:58 Wednesday, June 20, 2001
      
                            TABLE OF HEIGHT BY SEIBETSU
      
                        HEIGHT     SEIBETSU
      
                        Frequency|
                        Percent  |
                        Row Pct  |
                        Col Pct  |F       |M       |  Total
                        ---------+--------+--------+
                           -149  |      4 |      0 |      4
                                 |   2.04 |   0.00 |   2.04
                                 | 100.00 |   0.00 |
                                 |   7.27 |   0.00 |
                        ---------+--------+--------+
      
                        150-159  |     21 |      1 |     22
                                 |  10.71 |   0.51 |  11.22
                                 |  95.45 |   4.55 |
                                 |  38.18 |   0.71 |
                        ---------+--------+--------+
      
                        160-169  |     29 |     39 |     68
                                 |  14.80 |  19.90 |  34.69
                                 |  42.65 |  57.35 |
                                 |  52.73 |  27.66 |
                        ---------+--------+--------+
      
                        170-179  |      1 |     86 |     87
                                 |   0.51 |  43.88 |  44.39
                                 |   1.15 |  98.85 |
                                 |   1.82 |  60.99 |
                        ---------+--------+--------+
      
                        180-     |      0 |     15 |     15
                                 |   0.00 |   7.65 |   7.65
                                 |   0.00 | 100.00 |
                                 |   0.00 |  10.64 |
                        ---------+--------+--------+
                        Total          55      141      196
                                    28.06    71.94   100.00
      
                        Frequency Missing = 9
      
                                    SAS システム                             9
                                                11:58 Wednesday, June 20, 2001
      
      ----------------------------- SEIBETSU=' ' -----------------------------
      
                                              Cumulative  Cumulative
                HEIGHT   Frequency   Percent   Frequency    Percent 
               -----------------------------------------------------
      
                               Frequency Missing = 2
      
                                    SAS システム                            10
                                                11:58 Wednesday, June 20, 2001
      
      ------------------------------ SEIBETSU=F ------------------------------
      
                                              Cumulative  Cumulative
                HEIGHT   Frequency   Percent   Frequency    Percent 
               -----------------------------------------------------
                  -149          4       7.3           4        7.3  
               150-159         21      38.2          25       45.5  
               160-169         29      52.7          54       98.2  
               170-179          1       1.8          55      100.0  
      
                               Frequency Missing = 4
      
                                    SAS システム                            11
                                                11:58 Wednesday, June 20, 2001
      
      ------------------------------ SEIBETSU=M ------------------------------
      
                                              Cumulative  Cumulative
                HEIGHT   Frequency   Percent   Frequency    Percent 
               -----------------------------------------------------
               150-159          1       0.7           1        0.7  
               160-169         39      27.7          40       28.4  
               170-179         86      61.0         126       89.4  
               180-            15      10.6         141      100.0  
      
                               Frequency Missing = 3
      




  5. 各グループごとでの集計、基礎統計量
    1. プログラム : les1003.sas
       /* Lesson 10-3 */
       /*    File Name = les1003.sas   06/21/01   */
      
      data gakusei;
        infile 'all01.prn';
        input seibetsu $ height weight chest jitaku $ kodukai;
      
      proc format;
        value clheight 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=10);
      run;
                                                      :
      proc tabulate data=gakusei;                     : 帳票の作成
        class height seibetsu;                        : 特性変数であることの宣言
        var weight;                                   : 集計する変量名
        tables weight*(n mean std),height*seibetsu;   : 表示内容、分類変量名
        format height clheight.;                      : 身長のクラス分けの定義
      run;                                            :
      
    2. 出力結果 : les1003.lst
      • 身長と性別によって区分される各グループごとの体重の傾向をつかむ
      • 各グループの体重に関する平均値と標準偏差
      
                                    SAS システム                             2
                                                09:40 Wednesday, June 20, 2001
      
       ----------------------------------------------------------------------
       |                |                      HEIGHT                       |
       |                |---------------------------------------------------|
       |                |    -149    |         150-159         |  160-169   |
       |                |------------+-------------------------+------------|
       |                |  SEIBETSU  |        SEIBETSU         |  SEIBETSU  |
       |                |------------+-------------------------+------------|
       |                |     F      |     F      |     M      |     F      |
       |----------------+------------+------------+------------+------------|
       |WEIGHT |N       |        3.00|       14.00|        1.00|       17.00|
       |       |--------+------------+------------+------------+------------|
       |       |MEAN    |       41.67|       48.79|       61.00|       51.53|
       |       |--------+------------+------------+------------+------------|
       |       |STD     |        3.51|        4.32|           .|        2.90|
       ----------------------------------------------------------------------
      
       (CONTINUED)
                                    SAS システム                             3
                                                09:40 Wednesday, June 20, 2001
      
       ----------------------------------------------------------------------
       |                |                      HEIGHT                       |
       |                |---------------------------------------------------|
       |                |  160-169   |         170-179         |    180-    |
       |                |------------+-------------------------+------------|
       |                |  SEIBETSU  |        SEIBETSU         |  SEIBETSU  |
       |                |------------+-------------------------+------------|
       |                |     M      |     F      |     M      |     M      |
       |----------------+------------+------------+------------+------------|
       |WEIGHT |N       |       39.00|        0.00|       86.00|       15.00|
       |       |--------+------------+------------+------------+------------|
       |       |MEAN    |       58.55|           .|       63.40|       66.87|
       |       |--------+------------+------------+------------+------------|
       |       |STD     |        7.03|           .|        7.26|        8.92|
       ----------------------------------------------------------------------
      

  6. 次回は、... : 6月28日 14:45
[DIR]講義のホームページへ戻ります