楼主: 彭艳琼
14228 5

[原创博文] SAS中如何求多元回归分析的残差,保存残差并画出直方图? [推广有奖]

  • 0关注
  • 1粉丝

博士生

46%

还不是VIP/贵宾

-

威望
0
论坛币
1246 个
通用积分
4.4500
学术水平
0 点
热心指数
5 点
信用等级
0 点
经验
1173 点
帖子
105
精华
0
在线时间
488 小时
注册时间
2009-4-16
最后登录
2023-8-3

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
请教各位高手,SAS中如何求多元回归分析的残差,保存残差并画出直方图?最好把能写出程序。非常感谢!
二维码

扫码加我 拉你入群

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

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

关键词:多元回归分析 回归分析 多元回归 直方图 非常感谢 回归分析 直方图 如何 程序 最好 主成分分析法 spss主成分分析 逐步回归分析 多元回归分析 因子分析法 应用时间序列分析

回帖推荐

crackman 发表于2楼  查看完整内容

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 1 ...

彭艳琼 发表于4楼  查看完整内容

谢谢大家的建议!经过摸索,我已经找到解决办法了。 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 ...

本帖被以下文库推荐

沙发
crackman 发表于 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;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

使用道具

藤椅
crackman 发表于 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;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

使用道具

报纸
jingju11 发表于 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;

  1. fit wage/ols out=resid outresid;
复制代码


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教程吗?

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 05:06