全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
15354 5
2010-03-27
请教各位高手,SAS中如何求多元回归分析的残差,保存残差并画出直方图?最好把能写出程序。非常感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-3-27 20:33:05
title '模型诊断统计量---全模型的标准化删减残差对观测个数的散点图';
data crackman;
input x1 x2 x3 x4 y@@;
cards;
13 7 26 19 11.5 16 6 19 14 10.2 15 11 40 34 19.8 24 10 32 26 19.8
21 8 29 17 13.7 22 11 39 38 25.3 19 12 15 33 21.6 10 7 17 20 9.7
27 11 13 27 22.3 18 8 34 22 14.8 32 10 21 15 19.1 29 11 28 21 20.7
17 8 18 16 11.7 18 11 16 32 19.6 26 10 35 23 19.4 16 10 15 34 20.3
14 6 14 18 10.6 18 7 23 14 11.1 28 13 21 34 25.5 23 11 29 29 20.7
19 9 13 29 18.7 25 13 41 40 28.9 12 10 19 38 19.3 32 9 12 15 18.3
23 8 25 17 15.6 36 11 37 18 21.5 28 11 33 32 24.7 31 9 25 14 17.7
21 9 18 19 15.3 29 13 14 38 28.3 35 14 24 34 29.8 18 10 11 35 21.6
;
proc reg;
model y=x1 x2 x3 x4/selection=stepwise sle=0.15 sls=0.14 details;
plot rstudent. *obs./vref=-1.714 1.714 cvref=blue lvref=1 href=0 to 30 by 5 chref=red;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-3-27 20:33:59

模型诊断统计量---全模型的标准化删减残差对观测个数的散点图

模型诊断统计量---全模型的标准化删减残差对观测个数的散点图                                   5
                                                                                           2010年03月27日 星期六 下午08时25分57秒
                                                        The REG Procedure
                                                          Model: MODEL1
                                                     Dependent Variable: y
                                             Number of Observations Read          32
                                             Number of Observations Used          32
                                                   Stepwise Selection: Step 1

                                                      Statistics for Entry
                                                           DF = 1,30
                                                                    Model
                                  Variable        Tolerance      R-Square    F Value    Pr > F
                                  x1               1.000000        0.3653      17.27    0.0002
                                  x2               1.000000        0.9151     323.44    <.0001
                                  x3               1.000000        0.0519       1.64    0.2098
                                  x4               1.000000        0.5860      42.46    <.0001

                                   Variable x2 Entered: R-Square = 0.9151 and C(p) = 354.7377

                                                      Analysis of Variance
                                                             Sum of           Mean
                         Source                   DF        Squares         Square    F Value    Pr > F
                         Model                     1      855.87895      855.87895     323.44    <.0001
                         Error                    30       79.38573        2.64619
                         Corrected Total          31      935.26469

                                             Parameter     Standard
                                Variable      Estimate        Error   Type II SS  F Value  Pr > F
                                Intercept     -5.93184      1.41428     46.55076    17.59  0.0002
                                x2             2.53796      0.14112    855.87895   323.44  <.0001
                                                Bounds on condition number: 1, 1
---------------------------------------------------------------------------------------------------------------------------------
                                                   Stepwise Selection: Step 2

                                                      Statistics for Entry
                                                           DF = 1,29
                                                                    Model
                                  Variable        Tolerance      R-Square    F Value    Pr > F
                                  x1               0.678487        0.9208       2.07    0.1607
                                  x3               0.956858        0.9160       0.31    0.5845
                                  x4               0.450191        0.9221       2.61    0.1169

                                   Variable x4 Entered: R-Square = 0.9221 and C(p) = 325.1238


                                    模型诊断统计量---全模型的标准化删减残差对观测个数的散点图                                   6
                                                                                           2010年03月27日 星期六 下午08时25分57秒
                                                        The REG Procedure
                                                          Model: MODEL1
                                                     Dependent Variable: y
                                                   Stepwise Selection: Step 2
                                                      Analysis of Variance
                                                             Sum of           Mean
                         Source                   DF        Squares         Square    F Value    Pr > F
                         Model                     2      862.43617      431.21809     171.71    <.0001
                         Error                    29       72.82852        2.51133
                         Corrected Total          31      935.26469

                                             Parameter     Standard
                                Variable      Estimate        Error   Type II SS  F Value  Pr > F
                                Intercept     -5.53058      1.39997     39.19267    15.61  0.0005
                                x2             2.29246      0.20490    314.37206   125.18  <.0001
                                x4             0.07883      0.04878      6.55722     2.61  0.1169
                                           Bounds on condition number: 2.2213, 8.8851
---------------------------------------------------------------------------------------------------------------------------------
                                                   Stepwise Selection: Step 3

                                                     Statistics for Removal
                                                           DF = 1,29
                                                   Partial         Model
                                   Variable       R-Square      R-Square    F Value    Pr > F
                                   x2               0.3361        0.5860     125.18    <.0001
                                   x4               0.0070        0.9151       2.61    0.1169

                                                      Statistics for Entry
                                                           DF = 1,28
                                                                    Model
                                  Variable        Tolerance      R-Square    F Value    Pr > F
                                  x1               0.200444        0.9938     324.02    <.0001
                                  x3               0.950423        0.9235       0.49    0.4878

                                    Variable x1 Entered: R-Square = 0.9938 and C(p) = 3.9291

                                                      Analysis of Variance
                                                             Sum of           Mean
                         Source                   DF        Squares         Square    F Value    Pr > F
                         Model                     3      929.47177      309.82392    1497.53    <.0001
                         Error                    28        5.79292        0.20689
                         Corrected Total          31      935.26469

                                    模型诊断统计量---全模型的标准化删减残差对观测个数的散点图                                   7
                                                                                           2010年03月27日 星期六 下午08时25分57秒
                                                        The REG Procedure
                                                          Model: MODEL1
                                                     Dependent Variable: y
                                                   Stepwise Selection: Step 3
                                             Parameter     Standard
                                Variable      Estimate        Error   Type II SS  F Value  Pr > F
                                Intercept     -5.31781      0.40200     36.20377   174.99  <.0001
                                x1             0.47421      0.02634     67.03560   324.02  <.0001
                                x2             0.18069      0.13123      0.39220     1.90  0.1795
                                x4             0.46807      0.02576     68.29932   330.12  <.0001
                                           Bounds on condition number: 11.061, 70.706
---------------------------------------------------------------------------------------------------------------------------------
                                                   Stepwise Selection: Step 4

                                                     Statistics for Removal
                                                           DF = 1,28
                                                   Partial         Model
                                   Variable       R-Square      R-Square    F Value    Pr > F
                                   x1               0.0717        0.9221     324.02    <.0001
                                   x2               0.0004        0.9934       1.90    0.1795
                                   x4               0.0730        0.9208     330.12    <.0001

                                                      Statistics for Entry
                                                           DF = 1,27
                                                                    Model
                                  Variable        Tolerance      R-Square    F Value    Pr > F
                                  x3               0.943739        0.9940       0.93    0.3437

                                    Variable x2 Removed: R-Square = 0.9934 and C(p) = 3.8200

                                                      Analysis of Variance
                                                             Sum of           Mean
                         Source                   DF        Squares         Square    F Value    Pr > F
                         Model                     2      929.07957      464.53978    2178.07    <.0001
                         Error                    29        6.18512        0.21328
                         Corrected Total          31      935.26469

                                             Parameter     Standard
                                Variable      Estimate        Error   Type II SS  F Value  Pr > F
                                Intercept     -5.11036      0.37841     38.89867   182.38  <.0001
                                x1             0.50663      0.01199    381.01546  1786.46  <.0001
                                x4             0.50109      0.00955    587.43702  2754.30  <.0001
                                           Bounds on condition number: 1.0019, 4.0076
---------------------------------------------------------------------------------------------------------------------------------
                                                   Stepwise Selection: Step 5

                                    模型诊断统计量---全模型的标准化删减残差对观测个数的散点图                                   8
                                                                                           2010年03月27日 星期六 下午08时25分57秒
                                                        The REG Procedure
                                                          Model: MODEL1
                                                     Dependent Variable: y
                                                   Stepwise Selection: Step 5
                                                     Statistics for Removal
                                                           DF = 1,29
                                                   Partial         Model
                                   Variable       R-Square      R-Square    F Value    Pr > F
                                   x1               0.4074        0.5860    1786.46    <.0001
                                   x4               0.6281        0.3653    2754.30    <.0001

                                                      Statistics for Entry
                                                           DF = 1,28
                                                                    Model
                                  Variable        Tolerance      R-Square    F Value    Pr > F
                                  x2               0.090409        0.9938       1.90    0.1795
                                  x3               0.943996        0.9936       0.94    0.3395
                              All variables left in the model are significant at the 0.1400 level.
                          No other variable met the 0.1500 significance level for entry into the model.

                                                  Summary of Stepwise Selection
                        Variable     Variable     Number     Partial      Model
                Step    Entered      Removed      Vars In    R-Square    R-Square     C(p)      F Value    Pr > F
                  1     x2                            1       0.9151      0.9151     354.738     323.44    <.0001
                  2     x4                            2       0.0070      0.9221     325.124       2.61    0.1169
                  3     x1                            3       0.0717      0.9938      3.9291     324.02    <.0001
                  4                  x2               2       0.0004      0.9934      3.8200       1.90    0.1795
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-3-27 21:12:32
谢谢大家的建议!经过摸索,我已经找到解决办法了。

data wage1;
infile "E:\WAGE1.RAW";
input wage      educ      exper     tenure    nonwhite  female    married   numdep   
smsa      northcen  south     west      construc  ndurman   trcommpu  trade   
services  profserv  profocc   clerocc   servocc   lwage     expersq   tenursq  ;
run;
title "normal model";
proc model data=wage1 ;
wage=b0+b1*educ+b2*exper+b3*tenure;
fit wage/ols;
run;
/*可以求出线性模型,然后再把系数代入,程序继续:*/
data wage1;
set wage1;
uhat=wage+2.87-0.599*educ-0.022*exper-0.169*tenure;/*求出残差*/
run;

proc univariate data=wage1;
var uhat;
histogram uhat;/*画出直方图*/
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-3-28 02:08:17
彭艳琼 发表于 2010-3-27 21:12
谢谢大家的建议!经过摸索,我已经找到解决办法了。

data wage1;
infile "E:\WAGE1.RAW";
input wage      educ      exper     tenure    nonwhite  female    married   numdep   
smsa      northcen  south     west      construc  ndurman   trcommpu  trade   
services  profserv  profocc   clerocc   servocc   lwage     expersq   tenursq  ;
run;
title "normal model";
proc model data=wage1 ;
wage=b0+b1*educ+b2*exper+b3*tenure;
fit wage/ols;
run;
/*可以求出线性模型,然后再把系数代入,程序继续:*/
data wage1;
set wage1;
uhat=wage+2.87-0.599*educ-0.022*exper-0.169*tenure;/*求出残差*/
run;

proc univariate data=wage1;
var uhat;
histogram uhat;/*画出直方图*/
run;
复制代码


I don’t think you need to calculate the residuals by hand. Usually the residual is given from the model since it is so important on model diagnostic. JingJu
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-3-28 13:24:55
5# jingju11

非常感谢!用你的方法我得到了结果。我是初学SAS,好多东西不懂,希望您能多多指导。请问您能推荐一本比较好的中文版的SAS教程吗?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群