対応のある2標本の差の検定、クラスター分析、幾つかのTips

統計モデル解析特論I/II : 第13回 (01/14/20)

  前回 はグループごとの平均値に差があるかの比較方法(検定)を幾つか説明した。 非常に持って回ったような論理展開で判断したが、ご理解いただけただろうか? 今回は患者への投薬の前後等、処置の前後での変化を比較する際に用いられる サンプルに対応のある2標本の差の検定について紹介する。
 また、Q3 では取り扱わなかった多変量解析の手法からクラスター分析を紹介し、 後半では、クロス集計の際の便利なコマンドや 実用時に知っておくと重宝するファイルとの読み書きのテクニックについて 幾つか紹介する。
  1. 対応のある 2群の検定

    1. プログラム : Lesson 13-01 : les1301.sas
       /* Lesson 13-01 */
       /*    File Name = les1301.sas  02/01/18   */
      
      options nocenter linesize=78 pagesize=30;
      proc printto print = 'Kougi19/les1301_Results.txt' new;
      
      data pair;
        input x y @@;                                : 改行せずに続けて読むことの指定
        dif=y-x;                                     : 前後の差を計算
      cards;
        5.1 4.7  6.2 6.1  6.8 7.2  7.4 7.3  3.9 3.6  : 2つ1組みでデータを列挙
        3.5 3.7  5.3 4.8  4.5 4.4  5.9 5.5  4.8 4.6  : 
      ;
      
      proc print data=pair;
      run;
                                           : Stem and Leaf を表示させるには
      ods listing;                         : 以下の plot オプション用に指定。
      ods graphics off;                    : 以下の plot オプション用に指定。
      proc univariate data=pair plot;      : 基礎統計量の算出。plot オプションを指定。
        var dif;                           : 指定した変量について
      run;
      

    2. 出力
      • html 形式: les1301-Results.html
      • pdf 形式: les1301-Results.pdf
      • テキストファイル: les1301-Results.txt : 漢字コードがUTF-8で記述されているため、(ブラウザに依るが)そのままだと文字化けする

      • 処置の前後の変化が統計的に意味のあるものかを判断する。
      • 両者の差がゼロかどうかを観る。
      • 判断のロジックは前週と同じ。
                                            Monday, January 13, 2020 09:56:55 PM  11
      Obs     x      y      dif
        1    5.1    4.7    -0.4
        2    6.2    6.1    -0.1
        3    6.8    7.2     0.4
        4    7.4    7.3    -0.1
        5    3.9    3.6    -0.3
        6    3.5    3.7     0.2
        7    5.3    4.8    -0.5
        8    4.5    4.4    -0.1
        9    5.9    5.5    -0.4
       10    4.8    4.6    -0.2
      
                                            Monday, January 13, 2020 09:56:55 PM  12
      The UNIVARIATE Procedure
      Variable:  dif
                                  Moments
      
      N                          10    Sum Weights                 10
      Mean                    -0.15    Sum Observations          -1.5
      Std Deviation      0.27988093    Variance            0.07833333
      Skewness           0.83622187    Kurtosis             0.2797646
      Uncorrected SS           0.93    Corrected SS             0.705
      Coeff Variation    -186.58728    Std Error Mean      0.08850612
      
                    Basic Statistical Measures
          Location                    Variability
      Mean     -0.15000     Std Deviation            0.27988
      Median   -0.15000     Variance                 0.07833
      Mode     -0.10000     Range                    0.90000
                            Interquartile Range      0.30000
      
                                            Monday, January 13, 2020 09:56:55 PM  13
      The UNIVARIATE Procedure
      Variable:  dif
                 Tests for Location: Mu0=0
       
      Test           -Statistic-    -----p Value------
      Student's t    t   -1.6948    Pr > |t|    0.1244
      Sign           M        -3    Pr >= |M|   0.1094
      Signed Rank    S     -15.5    Pr >= |S|   0.1211
      
      Quantiles (Definition 5)
       
      Level         Quantile
      100% Max          0.40
      99%               0.40
      95%               0.40
      90%               0.30
      75% Q3           -0.10
      50% Median       -0.15
      25% Q1           -0.40
      10%              -0.45
      5%               -0.50
      1%               -0.50
      0% Min           -0.50
      
                                            Monday, January 13, 2020 09:56:55 PM  14
      The UNIVARIATE Procedure
      Variable:  dif
      
              Extreme Observations
      ----Lowest----        ----Highest---
      Value      Obs        Value      Obs
       -0.5        7         -0.1        2
       -0.4        9         -0.1        4
       -0.4        1         -0.1        8
       -0.3        5          0.2        6
       -0.2       10          0.4        3
      
         Stem Leaf                     #  Boxplot
            4 0                        1     0
            2 0                        1     |
            0                                |
           -0 000                      3  +--+--+
           -2 00                       2  |     |
           -4 000                      3  +-----+
              ----+----+----+----+
          Multiply Stem.Leaf by 10**-1
      
      ≪後略≫
      

    3. 結果の見方 : Prob>|t|
      • 「Student's t(Studentのt検定)」の「Pr > |t|」の「p Value」の項を見る。
      • 今回の2群に対して差が無い(ゼロ)と言える確率は12.4% で、5%(or 1%) よりも大きい(稀なことではない)ので前後に差があるとは言えない。つまり、処理に効果があったとは言えない、と結論付けられる。

  2. クラスター分析

  3. 計算結果のファイルへの書き出し
      計算結果をSAS 以外の別のソフトウェアで利用するには、計算結果を外部の データファイルに書き出して流用するのが手軽である。 これまで出力結果として書き出してきたが、 テキストファイルやCSV ファイルに書き出すテクニックも知っておくと便利である。

    ≪前略≫
    proc print data=outclust(obs=20);         : 計算結果の出力(形式1)
    run;
    
    /* Output to text file */                 : 計算結果をテキストファイルに書き出す(形式2)
    data _null_;                              : ファイルに書き出す
      set outclust;                           : 書き出すデータセットを指定
      file 'Kougi19/les1302-OutValue.txt';           : ファイル名を指定
      put shintyou taijyuu kyoui cluster distance;   : 書き出す変量を指定
    run;
    
    /* Output to CSV file */                  : 計算結果をCSVファイルに書き出す(形式3)
    proc export data=outclust                 : 書き出すデータセットを指定
                outfile= "Kougi19/les1302-OutCSV.csv"  : ファイル名を指定
                dbms=CSV replace;
    run;
    

  4. [おまけ: Tips] データをファイルから読み込む際に便利なコマンド: デリミタの指定等
     Excel 等で入力したデータを SAS に読み込ませる方法として、 csv 形式で保存してからSASで読み込む方法を紹介した。 これ以外にタブ区切り(*.txt)の形式のファイルや 固定長と呼ばれるファイルも読み込むことができ、 これらを読み込む際の、幾つかの便利なコマンドをまとめて紹介しておく。

    1. カンマ区切り(csv 形式)のファイルを読む場合 : *.csv
        CSV 形式のファイルを読み込む場合、文字列の長さを指定しないと、 8文字(8バイト)しか読み込んでくれない。しかし、かと言って、input 文に 単に文字数を指定すると、カンマを超えて読み込もうとする。 また、欠損値が続くとそれ等を一つの欠損値として読み込んでしまう。 それらの欠点を一挙に解決するには以下の様式のプログラムを用いる。 続く欠損値を個々にバラして読ませ(infile 中の dsd)、 デリミタが出現するところまでの任意の長さの文字列を読み込む(input 中の : )ように指定する。
      data example2019;
        infile 'Kougi19/foo1.csv'
          firstobs=2 
          dlm=',' dsd
          missover truncover
          encoding=sjis termstr=crlf 
      ;
        input No $ Univ : $30. SName : $40. Faculty : $50. Dept : $50.
              Center1 : $8. Center2 : $8. Sel1 : $8. Sel2 : $8.
              Book1 : $10. Book2 : $10.
              Vol0  VolS  VolT
              ZenKou $ ScoreS  ScoreT  KoKouSi
      ;
      

    2. タブ区切りのファイルを読む場合 : *.txt, タブコードは十六進数で"09"
      data example2019;
        infile 'Kougi19/foo2.txt'
          firstobs=2
          dlm='09'x
          missover truncover
          encoding=sjis termstr=crlf
      ;
      

    3. 1レコード(1行)のレコード長が長い場合 : 一行の長さの指定、例えば 230バイトだと(logical record length)
      data math;
        infile 'Kougi19/foo3.csv'
          firstobs=2
          dlm=',' dsd
          lrecl=230
      ;
      

    4. 行末がそろってないデータの読み込み : 一行の長さを指定し、揃ってないことを明示
      data math;
        infile 'Kougi19/foo4.csv'
          firstobs=2
          dlm=',' dsd
          lrecl=230 truncover
      ;
      

    5. 固定長データの読み込み : カラム位置を指定して読み込む
      input
            UketsukeID     1-  6
            JyukenID       7- 11
            BirthDay      13- 20
            Area       $  32- 41
            s_scor01     103-104
            s_scor02     105-106
            s_scor03     107-108
      ;
      

  5. 頻度集計の便利なオプション

    1. プログラム : Lesson 13-3 : les1303.sas
       /* Lesson 13-03 */
       /*    File Name = les1303.sas  01/14/20   */
      
      options nocenter linesize=78 pagesize=30;
      options locale='en_US';
      /* options locale='ja_JP'; */
      proc printto print = 'Kougi19/les1303-Results.txt' new;
      
      data gakusei;
        infile 'Kougi19/all19b.csv'
          firstobs=2 dlm=',' dsd missover 
          encoding=sjis termstr=crlf;
        input sex $ shintyou taijyuu kyoui 
              jitaku $ kodukai carryer $ tsuuwa;
              
      /* if shintyou="." or taijyuu="." or kyoui="." then delete; */
      if carryer="DoCoMo"   then carryer="docomo";
      if carryer="DoCoMo+w"   then carryer="docomo+W";
      if carryer="vodafone" then carryer="Vodafone";
      if carryer="au+willc" then carryer="au+Willc";
      
      proc print data=gakusei(obs=5);
      run;
      
      title '*** 通常の頻度集計、クロス集計(アルファベット順になる) ***';
      proc freq data=gakusei;
        tables sex jitaku carryer;
      run;
      proc freq data=gakusei;
        tables sex*jitaku;
        tables sex*carryer;
        tables jitaku*carryer;
      run;
      
      title '*** 頻度の大きい順に表示 ***';
      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;
      
      title '*** 頻度の大きい順に表示(頻度のみ) ***';
      proc freq data=gakusei order=freq;
        tables sex jitaku carryer / nopercent norow nocol;
      run;
      proc freq data=gakusei order=freq;
        tables sex*jitaku     / nopercent norow nocol;
        tables sex*carryer    / nopercent norow nocol;
        tables jitaku*carryer / nopercent norow nocol;
      run;

    2. 出力
      • html 形式: les1303-Results.html
      • pdf 形式: les1303-Results.pdf
      • テキストファイル: les1303-Results.txt

      • 自宅生/下宿生の人数、自宅生/下宿生の人数。これらの組合わせの人数。
      • 頻度、割合(%)、累積頻度、累積割合(%)
      • 頻度、全体割合、縦割合、横割合
      *** 通常の頻度集計、クロス集計(アルファベット順にな 334
                                               Tuesday, January 14, 2020 12:55:00 PM
      The FREQ Procedure
                                      Cumulative    Cumulative
      sex    Frequency     Percent     Frequency      Percent
      --------------------------------------------------------
      F           124       33.51           124        33.51  
      M           246       66.49           370       100.00  
                       Frequency Missing = 29
      
                                         Cumulative    Cumulative
      jitaku    Frequency     Percent     Frequency      Percent
      -----------------------------------------------------------
      G              128       37.10           128        37.10  
      J              217       62.90           345       100.00  
                        Frequency Missing = 54
      
      *** 通常の頻度集計、クロス集計(アルファベット順にな 335
                                               Tuesday, January 14, 2020 12:55:00 PM
      The FREQ Procedure
                                           Cumulative    Cumulative
      carryer     Frequency     Percent     Frequency      Percent
      -------------------------------------------------------------
      DDIp               2        1.34             2         1.34  
      J-PHONE           10        6.71            12         8.05  
      KDDI               1        0.67            13         8.72  
      No                 5        3.36            18        12.08  
      OCN                1        0.67            19        12.75  
      UQ-mobil           1        0.67            20        13.42  
      Vodafone          21       14.09            41        27.52  
      Willcom            1        0.67            42        28.19  
      au                39       26.17            81        54.36  
      au+Willc           1        0.67            82        55.03  
      docomo            65       43.62           147        98.66  
      docomo+w           1        0.67           148        99.33  
      softbank           1        0.67           149       100.00  
                         Frequency Missing = 250
      
      *** 通常の頻度集計、クロス集計(アルファベット順にな 336
                                               Tuesday, January 14, 2020 12:55:00 PM
      The FREQ Procedure
      Table of sex by jitaku
      sex       jitaku
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |G       |J       |  Total
      ---------+--------+--------+
      F        |     36 |     70 |    106
               |  11.29 |  21.94 |  33.23
               |  33.96 |  66.04 |
               |  30.25 |  35.00 |
      ---------+--------+--------+
      M        |     83 |    130 |    213
               |  26.02 |  40.75 |  66.77
               |  38.97 |  61.03 |
               |  69.75 |  65.00 |
      ---------+--------+--------+
      Total         119      200      319
                  37.30    62.70   100.00
      Frequency Missing = 80
      
      *** 通常の頻度集計、クロス集計(アルファベット順にな 337
                                               Tuesday, January 14, 2020 12:55:00 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |DDIp    |J-PHONE |KDDI    |No      |OCN     |  Total
      ---------+--------+--------+--------+--------+--------+
      F        |      1 |      4 |      0 |      1 |      0 |     56
               |   0.68 |   2.74 |   0.00 |   0.68 |   0.00 |  38.36
               |   1.79 |   7.14 |   0.00 |   1.79 |   0.00 |
               |  50.00 |  44.44 |   0.00 |  20.00 |      . |
      ---------+--------+--------+--------+--------+--------+
      M        |      1 |      5 |      1 |      4 |      0 |     90
               |   0.68 |   3.42 |   0.68 |   2.74 |   0.00 |  61.64
               |   1.11 |   5.56 |   1.11 |   4.44 |   0.00 |
               |  50.00 |  55.56 | 100.00 |  80.00 |      . |
      ---------+--------+--------+--------+--------+--------+
      Total           2        9        1        5        0      146
                   1.37     6.16     0.68     3.42     0.00   100.00
      (Continued)
      
      *** 通常の頻度集計、クロス集計(アルファベット順にな 338
                                               Tuesday, January 14, 2020 12:55:00 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |UQ-mobil|Vodafone|Willcom |au      |au+Willc|  Total
      ---------+--------+--------+--------+--------+--------+
      F        |      0 |      9 |      1 |     12 |      1 |     56
               |   0.00 |   6.16 |   0.68 |   8.22 |   0.68 |  38.36
               |   0.00 |  16.07 |   1.79 |  21.43 |   1.79 |
               |      . |  42.86 | 100.00 |  30.77 | 100.00 |
      ---------+--------+--------+--------+--------+--------+
      M        |      0 |     12 |      0 |     27 |      0 |     90
               |   0.00 |   8.22 |   0.00 |  18.49 |   0.00 |  61.64
               |   0.00 |  13.33 |   0.00 |  30.00 |   0.00 |
               |      . |  57.14 |   0.00 |  69.23 |   0.00 |
      ---------+--------+--------+--------+--------+--------+
      Total           0       21        1       39        1      146
                   0.00    14.38     0.68    26.71     0.68   100.00
      (Continued)
      
      *** 通常の頻度集計、クロス集計(アルファベット順にな 339
                                               Tuesday, January 14, 2020 12:55:00 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |docomo  |docomo+w|softbank|  Total
      ---------+--------+--------+--------+
      F        |     26 |      0 |      1 |     56
               |  17.81 |   0.00 |   0.68 |  38.36
               |  46.43 |   0.00 |   1.79 |
               |  40.00 |   0.00 | 100.00 |
      ---------+--------+--------+--------+
      M        |     39 |      1 |      0 |     90
               |  26.71 |   0.68 |   0.00 |  61.64
               |  43.33 |   1.11 |   0.00 |
               |  60.00 | 100.00 |   0.00 |
      ---------+--------+--------+--------+
      Total          65        1        1      146
                  44.52     0.68     0.68   100.00
      Frequency Missing = 253
      
      ≪中略≫
      
      *** 頻度の大きい順に表示 ***                                     343
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
                                      Cumulative    Cumulative
      sex    Frequency     Percent     Frequency      Percent
      --------------------------------------------------------
      M           246       66.49           246        66.49  
      F           124       33.51           370       100.00  
                       Frequency Missing = 29
      
                                         Cumulative    Cumulative
      jitaku    Frequency     Percent     Frequency      Percent
      -----------------------------------------------------------
      J              217       62.90           217        62.90  
      G              128       37.10           345       100.00  
                        Frequency Missing = 54
      
      *** 頻度の大きい順に表示 ***                                     344
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
                                           Cumulative    Cumulative
      carryer     Frequency     Percent     Frequency      Percent
      -------------------------------------------------------------
      docomo            65       43.62            65        43.62  
      au                39       26.17           104        69.80  
      Vodafone          21       14.09           125        83.89  
      J-PHONE           10        6.71           135        90.60  
      No                 5        3.36           140        93.96  
      DDIp               2        1.34           142        95.30  
      KDDI               1        0.67           143        95.97  
      OCN                1        0.67           144        96.64  
      UQ-mobil           1        0.67           145        97.32  
      Willcom            1        0.67           146        97.99  
      au+Willc           1        0.67           147        98.66  
      docomo+w           1        0.67           148        99.33  
      softbank           1        0.67           149       100.00  
                         Frequency Missing = 250
      
      *** 頻度の大きい順に表示 ***                                     345
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by jitaku
      sex       jitaku
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |J       |G       |  Total
      ---------+--------+--------+
      M        |    130 |     83 |    213
               |  40.75 |  26.02 |  66.77
               |  61.03 |  38.97 |
               |  65.00 |  69.75 |
      ---------+--------+--------+
      F        |     70 |     36 |    106
               |  21.94 |  11.29 |  33.23
               |  66.04 |  33.96 |
               |  35.00 |  30.25 |
      ---------+--------+--------+
      Total         200      119      319
                  62.70    37.30   100.00
      Frequency Missing = 80
      
      *** 頻度の大きい順に表示 ***                                     346
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |docomo  |au      |Vodafone|J-PHONE |No      |  Total
      ---------+--------+--------+--------+--------+--------+
      M        |     39 |     27 |     12 |      5 |      4 |     90
               |  26.71 |  18.49 |   8.22 |   3.42 |   2.74 |  61.64
               |  43.33 |  30.00 |  13.33 |   5.56 |   4.44 |
               |  60.00 |  69.23 |  57.14 |  55.56 |  80.00 |
      ---------+--------+--------+--------+--------+--------+
      F        |     26 |     12 |      9 |      4 |      1 |     56
               |  17.81 |   8.22 |   6.16 |   2.74 |   0.68 |  38.36
               |  46.43 |  21.43 |  16.07 |   7.14 |   1.79 |
               |  40.00 |  30.77 |  42.86 |  44.44 |  20.00 |
      ---------+--------+--------+--------+--------+--------+
      Total          65       39       21        9        5      146
                  44.52    26.71    14.38     6.16     3.42   100.00
      (Continued)
      
      *** 頻度の大きい順に表示 ***                                     347
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |DDIp    |KDDI    |OCN     |UQ-mobil|Willcom |  Total
      ---------+--------+--------+--------+--------+--------+
      M        |      1 |      1 |      0 |      0 |      0 |     90
               |   0.68 |   0.68 |   0.00 |   0.00 |   0.00 |  61.64
               |   1.11 |   1.11 |   0.00 |   0.00 |   0.00 |
               |  50.00 | 100.00 |      . |      . |   0.00 |
      ---------+--------+--------+--------+--------+--------+
      F        |      1 |      0 |      0 |      0 |      1 |     56
               |   0.68 |   0.00 |   0.00 |   0.00 |   0.68 |  38.36
               |   1.79 |   0.00 |   0.00 |   0.00 |   1.79 |
               |  50.00 |   0.00 |      . |      . | 100.00 |
      ---------+--------+--------+--------+--------+--------+
      Total           2        1        0        0        1      146
                   1.37     0.68     0.00     0.00     0.68   100.00
      (Continued)
      
      *** 頻度の大きい順に表示 ***                                     348
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|
      Percent  |
      Row Pct  |
      Col Pct  |au+Willc|docomo+w|softbank|  Total
      ---------+--------+--------+--------+
      M        |      0 |      1 |      0 |     90
               |   0.00 |   0.68 |   0.00 |  61.64
               |   0.00 |   1.11 |   0.00 |
               |   0.00 | 100.00 |   0.00 |
      ---------+--------+--------+--------+
      F        |      1 |      0 |      1 |     56
               |   0.68 |   0.00 |   0.68 |  38.36
               |   1.79 |   0.00 |   1.79 |
               | 100.00 |   0.00 | 100.00 |
      ---------+--------+--------+--------+
      Total           1        1        1      146
                   0.68     0.68     0.68   100.00
      Frequency Missing = 253
      
      ≪中略≫
      
      *** 頻度の大きい順に表示(頻度のみ) ***                       352
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
                          Cumulative
      sex    Frequency     Frequency
      ------------------------------
      M           246           246 
      F           124           370 
          Frequency Missing = 29
      
                             Cumulative
      jitaku    Frequency     Frequency
      ---------------------------------
      J              217           217 
      G              128           345 
           Frequency Missing = 54
      
      *** 頻度の大きい順に表示(頻度のみ) ***                       353
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
                               Cumulative
      carryer     Frequency     Frequency
      -----------------------------------
      docomo            65            65 
      au                39           104 
      Vodafone          21           125 
      J-PHONE           10           135 
      No                 5           140 
      DDIp               2           142 
      KDDI               1           143 
      OCN                1           144 
      UQ-mobil           1           145 
      Willcom            1           146 
      au+Willc           1           147 
      docomo+w           1           148 
      softbank           1           149 
            Frequency Missing = 250
      
      *** 頻度の大きい順に表示(頻度のみ) ***                       354
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by jitaku
      sex       jitaku
      Frequency|J       |G       |  Total
      ---------+--------+--------+
      M        |    130 |     83 |    213
      ---------+--------+--------+
      F        |     70 |     36 |    106
      ---------+--------+--------+
      Total         200      119      319
      Frequency Missing = 80
      
      *** 頻度の大きい順に表示(頻度のみ) ***                       355
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|docomo  |au      |Vodafone|J-PHONE |No      |  Total
      ---------+--------+--------+--------+--------+--------+
      M        |     39 |     27 |     12 |      5 |      4 |     90
      ---------+--------+--------+--------+--------+--------+
      F        |     26 |     12 |      9 |      4 |      1 |     56
      ---------+--------+--------+--------+--------+--------+
      Total          65       39       21        9        5      146
      (Continued)
      
      *** 頻度の大きい順に表示(頻度のみ) ***                       356
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|DDIp    |KDDI    |OCN     |UQ-mobil|Willcom |  Total
      ---------+--------+--------+--------+--------+--------+
      M        |      1 |      1 |      0 |      0 |      0 |     90
      ---------+--------+--------+--------+--------+--------+
      F        |      1 |      0 |      0 |      0 |      1 |     56
      ---------+--------+--------+--------+--------+--------+
      Total           2        1        0        0        1      146
      (Continued)
      
      *** 頻度の大きい順に表示(頻度のみ) ***                       357
                                               Tuesday, January 14, 2020 12:55:01 PM
      The FREQ Procedure
      Table of sex by carryer
      sex       carryer
      Frequency|au+Willc|docomo+w|softbank|  Total
      ---------+--------+--------+--------+
      M        |      0 |      1 |      0 |     90
      ---------+--------+--------+--------+
      F        |      1 |      0 |      1 |     56
      ---------+--------+--------+--------+
      Total           1        1        1      146
      Frequency Missing = 253
      
      ≪後略≫
      

    3. [補足1] アンケート回収時には回答者の表記により 携帯電話会社の名前が大文字のものと小文字のものが混在していることも多い。 本来であれば同じ会社を指すと考えられるので、そのような場合は、再定義すれば良い。 データパートに以下の再定義文を挿入する。 なお、社名や経営母体を変更した会社について、 どのように取り扱うかは別に検討する必要がある。
      ≪前略≫
      if carryer="DoCoMo"   then carryer="docomo";
      if carryer="DoCoMo+w"   then carryer="docomo+W";
      if carryer="vodafone" then carryer="Vodafone";
      if carryer="au+willc" then carryer="au+Willc";
      ≪後略≫
      

    4. [補足2] SAS の出力の内、「proc printto print = 'Kougi19/les1303-Results.txt' new;」で 指定したファイルには「options nocenter linesize=78 pagesize=30;」 で表示エリアサイズに収まるように出力される (今回の場合で言えば一行78文字、一ページ30行)。 上記の出力でも、「SEX x JITAKU」のクロス表は、縦に分断されたように表示される。 これは、縦方向の行数が少ないので、クロス表が「小出し」に表示されるためである。 間にある 15行程の不要部分を削除すると、視覚的にも理解しやすい クロス表を得ることができ、配布資料はそのような編集作業後のものである。 皆さんもレポート作成時にはこの様な編集作業を行うと見易くなる。

    5. [補足3] 累積頻度の使い方の一つとして、頻度の高いもの順(降順)と言う指定もでき、 「上位 50% までのパターンを知りたい」と言うような時に使うことができる。 デフォルトではアルファベット順。 並び替えのオプションとしては、 freq(頻度の高い順) 以外に data(データセットに格納されている順)がある。
      ≪前略≫
      title '*** 頻度の大きい順に表示 ***';
      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;
      ≪後略≫
      

    6. [補足4] 頻度集計を行う際に、割合や周辺割合等が不要な場合は、 必要に応じて nopercent, norow, nocol を指定すれば良い。
      ≪前略≫
      title '*** 頻度の大きい順に表示(頻度のみ) ***';
      proc freq data=gakusei order=freq;
        tables sex jitaku carryer / nopercent norow nocol;
      run;
      proc freq data=gakusei order=freq;
        tables sex*jitaku     / nopercent norow nocol;
        tables sex*carryer    / nopercent norow nocol;
        tables jitaku*carryer / nopercent norow nocol;
      run;
      ≪後略≫
      

    7. [演習1] 上記の例では 二変量の組合わせまでを行ったが、 三変量以上の組合わせを行うことも可能である。 その際の出力はどのようになるかを予想し、その後実際に実行してみよ。 出力結果は何を表現し、また、予想は正しかったか?

      1. プログラム : Lesson 13-4 : les1304.sas
        ≪前略≫
        title '*** 3重クロス集計 ***';
        proc freq data=gakusei;
          tables sex*jitaku*carryer;
        run;
        

      2. 出力

  6. [レポート課題] : Q3, Q4(次回も含む) を通して講義で紹介した SAS の手法(プロシジャー)を利用して、 各自が収集したデータに対して統計解析を行ってみよ。 解析結果だけでなく、データ自身の説明や、 どういうところに興味を持って対象に選んだかの理由等も報告する事。
    1. 対象データ :
      • 各自で収集した興味あるデータ(個人ごとに異なる) : 複数でも可

    2. 作業内容 : 以下の点に注意しながらレポートを作成しよう。
      1. 解析対象とするデータの数に制限は設けない。いくつでも可。
      2. 解析結果だけでなく、データ自身の説明やどういうところに興味を持って 解析対象に選んだかの理由等も報告する事。 加えて、特に得られた知見からの考察は大事。
      3. レポートは他人への、もの事の説明のための文書である!!
      4. 手入力を少なくして SAS の出力を最大限有効利用せよ。 しかし、不要な部分はカットせよ。だらだらと引用しないこと。
      5. 興味を持つ点や得られた知見に対する考察は人によって個々異なるもので あるので、他人と相談することなく自分の力で解析しレポートを作成すること。

    3. 必要事項 : 以下に挙げるような項目を含めて作成すること。
      • 所属専攻名、学籍番号、氏名
      • 使ったデータ内容の説明
      • どのような点に興味を持ったか
      • 自分の解析目的
      • 何を知りたいためにどのような手法を使ったのか
      • 得られた知見と考察
      • その他、気付いたこと

      • (講義の進め方や内容等について、感想や意見も。)

    4. メールの題名(Subject)は「Report19Q4: Ukai」のように、 2019年クオーター4のレポート提出であることと、 提出者名が判るようなタイトルを 付けるようにしてください。また学籍番号も記載して下さい。

    5. 提出期限は「2月12日(水)(講義時に相談)」とします。 「不達事故」を避けたいので、受け取ったら確認のために提出者の学籍番号は 連絡のページ に掲載します(なるべく受領後3日以内に)ので、確認下さい。 なお、期限までに提出しなかった者には単位の認定を行いませんので、ご了承下さい。

    6. メモ : 01月16日02時から03時(EST, 17日04時から05時 JST)まで定期保守があるようです。ご注意ください。

  7. 次回は、... : 01月28日 16:20-17:50 (講義としての最終回)
[DIR]講義のホームページへ戻ります