/* Lesson 11-1 */ /* File Name = les1101.sas 12/16/04 */ data gakusei; infile 'all04b.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; if sex^='M' & sex^='F' then delete; proc print data=gakusei(obs=10); run; proc reg data=gakusei; : 回帰分析 model taijyuu=shintyou kyoui; : 複数変量を指定 output out=outreg1 predicted=pred1 residual=resid1; : 結果項目の保存 run; : proc print data=outreg1(obs=15); run; : proc plot data=outreg1; : 散布図を描く where shintyou^=. and taijyuu^=. and kyoui^=.; : 解析に使ったデータのみ plot taijyuu*shintyou; : plot taijyuu*kyoui; : plot taijyuu*pred1; : 観測値と予測値 plot resid1*pred1 /vref=0; : 残差と予測値(残差解析) plot resid1*shintyou/vref=0; : 残差と説明変量(残差解析) plot resid1*kyoui /vref=0; : 残差と説明変量(残差解析) plot resid1*taijyuu /vref=0; : 残差と目的変量(残差解析) run; : : proc univariate data=outreg1 plot normal; : 残差を正規プロットして確かめる var resid1; : run; :
SAS システム 2 19:47 Tuesday, December 7, 2004 Model: MODEL1 Dependent Variable: TAIJYUU Analysis of Variance Sum of Mean Source DF Squares Square F Value Prob>F Model 2 8432.71135 4216.35567 119.383 0.0001 Error 99 3496.47532 35.31793 C Total 101 11929.18667 Root MSE 5.94289 R-square 0.7069 Dep Mean 58.86667 Adj R-sq 0.7010 C.V. 10.09551 SAS システム 3 19:47 Tuesday, December 7, 2004 Parameter Estimates Parameter Standard T for H0: Variable DF Estimate Error Parameter=0 Prob > |T| INTERCEP 1 -112.109751 11.52738966 -9.726 0.0001 SHINTYOU 1 0.694385 0.07197938 9.647 0.0001 KYOUI 1 0.632583 0.08287933 7.633 0.0001 SAS システム 4 19:47 Tuesday, December 7, 2004 S H T K C I A J O A T R N I K I D R S P E T J Y T U R U R S O S Y Y O A K Y U E I B E O U U K A E W D D S X U U I U I R A 1 1 1 F 145.0 38.0 . J 10000 . . . 2 F 146.7 41.0 85 J 10000 Vodafone 6000 43.5262 -2.52616 3 F 148.0 42.0 . J 50000 . . . 4 F 148.0 43.0 80 J 50000 DoCoMo 4000 41.2659 1.73405 5 F 148.9 . . J 60000 . . . 6 F 149.0 45.0 . G 60000 . . . 7 F 150.0 46.0 86 40000 . 46.4502 -0.45022 8 F 151.0 50.0 . G 60000 J-PHONE . . . 9 F 151.7 41.5 80 J 35000 . 43.8352 -2.33517 10 F 152.0 35.0 77 J 60000 DoCoMo 2000 42.1457 -7.14574 11 F 152.0 43.0 . J 20000 au 3500 . . 12 F 152.0 44.0 . 45000 DoCoMo 4000 . . 13 F 153.0 41.0 . J 125000 No . . . 14 F 153.0 42.0 . G 0 Vodafone 1000 . . 15 F 153.0 46.5 87 G 10000 . 49.1660 -2.66596 SAS システム 6 19:47 Tuesday, December 7, 2004 プロット : TAIJYUU*SHINTYOU. 凡例: A = 1 OBS, B = 2 OBS, ... 100 + A | A A TAIJYUU | A A A | B BABAB AACAA A B A AA | A A B A B ABA BAFBC ABA AABBA 50 + A A ADA BBE C BBACB A | A A B A A | | | 0 + --+-----------+-----------+-----------+-----------+-----------+- 140 150 160 170 180 190 SHINTYOU SAS システム 7 19:47 Tuesday, December 7, 2004 プロット : TAIJYUU*KYOUI. 凡例: A = 1 OBS, B = 2 OBS, ... 100 + A | A A TAIJYUU | AA A | A A C BBF BABA A A | A A C C AAE FBI AAA A 50 + A A AA B ICHBBA | A A B B | | | 0 + ---+-------+-------+-------+-------+-------+-------+-------+-- 50 60 70 80 90 100 110 120 KYOUI SAS システム 8 19:47 Tuesday, December 7, 2004 プロット : TAIJYUU*PRED1. 凡例: A = 1 OBS, B = 2 OBS, ... 100 + A | A A TAIJYUU | A A A | A B ACBB BA ABAABA A | A B BA BAA ABBAACFBABAA AB 50 + AA B CBBADCACDB B | ABAA A | | | 0 + --+-----------+-----------+-----------+-----------+-----------+- 40 50 60 70 80 90 Predicted Value of TAIJYUU SAS システム 9 19:47 Tuesday, December 7, 2004 プロット : RESID1*PRED1. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | A i 20 + A d | A A A A u | A B AA B A B BBA A A A a 0 +----AAAA--B-CBB-CCAAABA-ABBAACEB-AA--B-ABA---------A------------- l | A AAAA BCA B A AA BAAAAC A | A -20 + ---+-----------+-----------+-----------+-----------+-----------+-- 40 50 60 70 80 90 Predicted Value of TAIJYUU SAS システム 10 19:47 Tuesday, December 7, 2004 プロット : RESID1*SHINTYOU. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | A i 20 + A d | A A A A u | B B A BABAB ABAA a 0 +----------A-A-A-A-AAACA-BAD-B-BABBC-AACAB-BAC-A-C-A-A--A--------- l | A A AA B AA CB A BAA A ACAA A | A -20 + ---+-----------+-----------+-----------+-----------+-----------+-- 140 150 160 170 180 190 SHINTYOU SAS システム 11 19:47 Tuesday, December 7, 2004 プロット : RESID1*KYOUI. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | A i 20 + A d | A A A A u | B A B A C ABD B a 0 +-----------------------C-A-D-CCDKCBAG-A-BC---B--------A---------- l | AA B BA FACBC A B A | A -20 + -+--------+--------+--------+--------+--------+--------+--------+- 50 60 70 80 90 100 110 120 KYOUI SAS システム 12 19:47 Tuesday, December 7, 2004 プロット : RESID1*TAIJYUU. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | A i 20 + A d | AA A A u | A AAAAB B BBBA AA a 0 +----------------BAACCBFCAC-CFDBCAA-E----A---------------- l | A A BDABB A ADAAD A | A -20 + ---+------------+------------+------------+------------+-- 20 40 60 80 100 TAIJYUU SAS システム 13 19:47 Tuesday, December 7, 2004 Univariate Procedure Variable=RESID1 Residual Moments N 102 Sum Wgts 102 Mean 0 Sum 0 Std Dev 5.883755 Variance 34.61857 Skewness 1.217662 Kurtosis 2.157941 USS 3496.475 CSS 3496.475 CV . Std Mean 0.582579 T:Mean=0 0 Pr>|T| 1.0000 Num ^= 0 102 Num > 0 39 M(Sign) -12 Pr>=|M| 0.0223 Sgn Rank -341.5 Pr>=|S| 0.2563 W:Normal 0.922178 PrSAS システム 17 19:47 Tuesday, December 7, 2004 Univariate Procedure Variable=RESID1 Residual Stem Leaf # Boxplot 2 4 1 * 1 8 1 0 1 01224 5 0 0 5567777778888 13 | 0 0000111112223334444 19 +--+--+ -0 44444333333333332222222222222111111100000 41 *-----* -0 998777776666665555555 21 | -1 0 1 | ----+----+----+----+----+----+----+----+- Multiply Stem.Leaf by 10**+1 SAS システム 18 19:47 Tuesday, December 7, 2004 Univariate Procedure Variable=RESID1 Residual Normal Probability Plot 22.5+ * | * | ****++++++ | *******+ | +++******* | ************* | * *********** -12.5+*++++++++ +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2
/* Lesson 11-2 */ /* File Name = les1102.sas 12/16/04 */ data gakusei; infile 'all04b.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; if sex^='M' & sex^='F' then delete; : 性別不明は除外 if shintyou=. | taijyuu=. | kyoui=. then delete; : 欠損のあるデータは除外 proc print data=gakusei(obs=10); run; proc corr data=gakusei; : 相関係数 where sex='M'; : 男性について run; : : proc reg data=gakusei; : 回帰分析 model taijyuu=shintyou kyoui; : where sex='M'; : 男性について output out=outreg1 predicted=pred1 residual=resid1; : run; : proc print data=outreg1(obs=15); run; proc plot data=outreg1; where sex='M'; : 対象データについて plot taijyuu*shintyou; plot taijyuu*kyoui; plot taijyuu*pred1; plot resid1*(pred1 shintyou kyoui taijyuu)/vref=0; : まとめて記述 /* plot resid1*pred1 /vref=0; plot resid1*shintyou/vref=0; plot resid1*kyoui /vref=0; plot resid1*taijyuu /vref=0; */ run; proc univariate data=outreg1 plot normal; var resid1; run;
SAS システム 2 19:47 Tuesday, December 7, 2004 Correlation Analysis 5 'VAR' Variables: SHINTYOU TAIJYUU KYOUI KODUKAI TSUUWA Simple Statistics Variable N Mean Std Dev Sum Minimum Maximum SHINTYOU 64 172.5 6.1180 11041.1 156.0 185.0 TAIJYUU 64 64.6828 9.0923 4139.7 46.0000 100.0 KYOUI 64 88.5000 8.6189 5664.0 56.0000 112.0 KODUKAI 60 55100.0 57720.5 3306000 0 300000 TSUUWA 8 9250.0 3453.8 74000.0 5000.0 15000.0 SAS システム 3 19:47 Tuesday, December 7, 2004 Correlation Analysis Pearson Correlation Coefficients / Prob > |R| under Ho: Rho=0 / Number of Observations SHINTYOU TAIJYUU KYOUI KODUKAI TSUUWA SHINTYOU 1.00000 0.41073 0.19351 0.10468 -0.18380 0.0 0.0007 0.1255 0.4261 0.6631 64 64 64 60 8 TAIJYUU 0.41073 1.00000 0.66124 -0.05998 0.15571 0.0007 0.0 0.0001 0.6489 0.7127 64 64 64 60 8 KYOUI 0.19351 0.66124 1.00000 -0.12114 -0.16606 0.1255 0.0001 0.0 0.3565 0.6943 64 64 64 60 8 KODUKAI 0.10468 -0.05998 -0.12114 1.00000 0.39786 0.4261 0.6489 0.3565 0.0 0.3290 60 60 60 60 8 TSUUWA -0.18380 0.15571 -0.16606 0.39786 1.00000 0.6631 0.7127 0.6943 0.3290 0.0 8 8 8 8 8 SAS システム 6 19:47 Tuesday, December 7, 2004 Model: MODEL1 Dependent Variable: TAIJYUU Analysis of Variance Sum of Mean Source DF Squares Square F Value Prob>F Model 2 2709.84404 1354.92202 33.082 0.0001 Error 61 2498.32705 40.95618 C Total 63 5208.17109 Root MSE 6.39970 R-square 0.5203 Dep Mean 64.68281 Adj R-sq 0.5046 C.V. 9.89398 SAS システム 7 19:47 Tuesday, December 7, 2004 Parameter Estimates Parameter Standard T for H0: Variable DF Estimate Error Parameter=0 Prob > |T| INTERCEP 1 -67.062537 23.09102487 -2.904 0.0051 SHINTYOU 1 0.436590 0.13432815 3.250 0.0019 KYOUI 1 0.637583 0.09535081 6.687 0.0001 SAS システム 10 19:47 Tuesday, December 7, 2004 プロット : TAIJYUU*SHINTYOU. 凡例: A = 1 OBS, B = 2 OBS, ... TAIJYUU | 100 + A | A A | 75 + A A A A A AA | B B A C A A A C A A D A A A | A A A B A B A D B C A AAA A A AA A 50 + A B A | | 25 + --+---------+---------+---------+---------+---------+---------+- 155 160 165 170 175 180 185 SHINTYOU SAS システム 11 19:47 Tuesday, December 7, 2004 プロット : TAIJYUU*KYOUI. 凡例: A = 1 OBS, B = 2 OBS, ... TAIJYUU | 100 + A | A A | 75 + AA BA A A | A A C BAH BAAB A | A A B C AAC EBE AA A 50 + A A A A | | 25 + ---+-------+-------+-------+-------+-------+-------+-------+-- 50 60 70 80 90 100 110 120 KYOUI SAS システム 12 19:47 Tuesday, December 7, 2004 プロット : TAIJYUU*PRED1. 凡例: A = 1 OBS, B = 2 OBS, ... TAIJYUU | 100 + A | A A | 75 + AA AAAA A | AAAA DABBBABB AAA | A B AA CAAACDDAABA 50 + A A A A | | 25 + --+-----------+-----------+-----------+-----------+-----------+- 40 50 60 70 80 90 Predicted Value of TAIJYUU SAS システム 13 19:47 Tuesday, December 7, 2004 プロット : RESID1*PRED1. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | i 20 + A A d | A A u | A A AAAA CBA AA a 0 +---------------AA--A----A-BAA-BBBABB--B-BA---------A------------- l | A A A AADBAABBB AA | -20 + ---+-----------+-----------+-----------+-----------+-----------+-- 40 50 60 70 80 90 Predicted Value of TAIJYUU SAS システム 14 19:47 Tuesday, December 7, 2004 プロット : RESID1*SHINTYOU. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | i 20 + A A d | A A u | A B A B A B A B AA a 0 +----A-------A-----------A-B---A-C-A-A-A--AC---A-BA--B-A-A---A---- l | A B A A B C A B A A A BA A A | -20 + ---+---------+---------+---------+---------+---------+---------+-- 155 160 165 170 175 180 185 SHINTYOU SAS システム 15 19:47 Tuesday, December 7, 2004 プロット : RESID1*KYOUI. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | i 20 + A A d | A A u | A B A B BD B a 0 +------------------A----B-A-B---ABABAE-A-AC---A--------A---------- l | A B BBBAE AAB A A | -20 + -+--------+--------+--------+--------+--------+--------+--------+- 50 60 70 80 90 100 110 120 KYOUI SAS システム 16 19:47 Tuesday, December 7, 2004 プロット : RESID1*TAIJYUU. 凡例: A = 1 OBS, B = 2 OBS, ... | R 40 + e | s | i 20 + A A d | A A u | A A B AAAC A A AA a 0 +----------A------AA--ADACA-DA-A-CB------A------------------------ l | A A BA B FABABA A | -20 + ---+---------+---------+---------+---------+---------+---------+-- 40 50 60 70 80 90 100 TAIJYUU SAS システム 17 19:47 Tuesday, December 7, 2004 Univariate Procedure Variable=RESID1 Residual Moments N 64 Sum Wgts 64 Mean 0 Sum 0 Std Dev 6.2973 Variance 39.65598 Skewness 1.20336 Kurtosis 1.801302 USS 2498.327 CSS 2498.327 CV . Std Mean 0.787162 T:Mean=0 0 Pr>|T| 1.0000 Num ^= 0 64 Num > 0 26 M(Sign) -6 Pr>=|M| 0.1686 Sgn Rank -130 Pr>=|S| 0.3889 W:Normal 0.913681 PrSAS システム 20 19:47 Tuesday, December 7, 2004 Univariate Procedure Variable=RESID1 Residual Stem Leaf # Boxplot 2 2 1 0 1 8 1 0 1 24 2 | 0 55556677789 11 | 0 00001133344 11 +--+--+ -0 44433333322221111100 20 *-----* -0 998887665555555555 18 +-----+ ----+----+----+----+ Multiply Stem.Leaf by 10**+1 SAS システム 21 19:47 Tuesday, December 7, 2004 Univariate Procedure Variable=RESID1 Residual Normal Probability Plot 22.5+ * | * ++ | **++++++ 7.5+ ++****** | +++******* | ********** -7.5+ * * ********** +----+----+----+----+----+----+----+----+----+----+ -2 -1 0 +1 +2
where sex='M' and taijyuu<85;
kyo2=kyoui**2;
data gakusei; infile 'all04b.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; dekasa=shintyou+taijyuu+kyoui; : 変量間の加減乗除 kyo_2=kyoui**2; : 二乗 kyo_sr=sqrt(kyoui); : ルート
[算術演算子]
[数値関数]
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;
data rei01; do i=1 to 200; x=rannor(12345); output; end; run;