楼主: Isscaliu
8776 2

讨论:怎样做lack-of-fit test [推广有奖]

  • 0关注
  • 6粉丝

VIP

副教授

11%

还不是VIP/贵宾

-

威望
0
论坛币
5924 个
通用积分
0.4202
学术水平
34 点
热心指数
34 点
信用等级
15 点
经验
18238 点
帖子
474
精华
0
在线时间
961 小时
注册时间
2007-2-8
最后登录
2014-7-5

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
proc glm data=msexam.fall08reg outstat=backwardr;
model P= G_G GA_G FA_5_5 SA_G PP;
run;
proc glm data=msexam.fall08reg outstat=backward;
model P= G_G GA_G;
run;

%macro ftest (dataset1, dataset2);
/* this macro is counting on the data sets being created by proc glm's outdata*/
data ftest;
set &dataset1 &dataset2;
if _source_= "ERROR";
sse0=lag(ss);
dfe0=lag(df);
drop _name_ _type_;
f= ((sse0-ss)/(dfe0-df))/(min(of ss, sse0)/min(of df,dfe0));
prob =1 - cdf('F',f,abs(dfe0-df),min(of df,dfe0));
if f='.' then delete;
run;
proc print data=ftest;
var f prob;
run;
%mend;
%ftest(backward, backwardr);

以上是俺写过的一个macro。是检验linear regression下full model和nested model的F-test(model selection)。
听讲9.2的proc reg可以检验lack-of-fit,毕竟能用得上9.2的只是少数人。所以今天抛砖引玉,放出这一F-test的code,来换取高手做lack-of-fit的code。
二维码

扫码加我 拉你入群

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

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

关键词:lack-of-fit test lack Est fit 讨论 test

It was the best of times, it was the worst of times.
沙发
jingju11 发表于 2010-10-27 04:10:35 |只看作者 |坛友微信交流群
1# Isscaliu

  1. data have;
  2. missing A;
  3. input x y@@;
  4. c =(ranuni(11) >0.65);
  5. x2 =x*x; xc =x*c;
  6. datalines;
  7. 8.3 227 8.3 312
  8. 12.1 362 12.1 521
  9. 17.0 640 17.0 539 17.0 728
  10. 24.3 945 24.3 738 24.3 759
  11. 33.6 1263 33.6 A
  12. ;

  13. **lack of fit in rsreg directly-SAS9.2;
  14. proc rsreg data =have;
  15. model y =x c x2 xc/lackfit covar =4;
  16. run;
  17. ***compute our own lack of fit;
  18. ods listing close;
  19. proc means data =have nway vardef =df;
  20.   class x c;
  21.   var y;  
  22.   output out =_means_ css =_css N =_N;
  23. run;
  24. proc reg data =have;
  25. model y =x c x2 xc; ods output anova =_aa_;
  26. run;
  27. data _null_;
  28. if _n_ =1 then do i = 1 to nobs;
  29.   set _means_ nobs =nobs;
  30.   sum_css ++_css; m ++(_N >0); N ++_N;
  31. end;
  32. set _aa_ end =Eof;
  33.   array _dfss{3, 2} _temporary_;
  34.   _dfss[_n_, 1] =df; _dfss[_n_, 2] =ss;
  35.   if Eof then do;                        
  36.    p = _dfss[1, 1];  q =N;
  37.    sse =_dfss[2, 2]; ss_pe =sum_css; ss_lf =sse -ss_pe;
  38.    df_err =_dfss[2, 1]; df_pe =q -m; df_lf =df_err -df_pe;   
  39.    mse_err =sse/df_err; mse_pe =ss_pe/df_pe; mse_lf =ss_lf/df_lf;   
  40.    F =mse_lf/mse_pe;
  41.    p =sdf('F', F, df_lf, df_pe);
  42.    put @1 'Lack of Fit';
  43.    put @1 '------------------------------------------------------------------';
  44.    put @1 'Residual'    @15 'DF'    @20 'Sum of Squares' @35 'Mean Square' @50 'F Value' @60 'Pr > F';
  45.    put;
  46.    put @1 'Lack of Fit' @15 df_lf    @20 ss_lf   F10.2          @35 mse_lf    F10.2 @50 F F6.2 @60 p pvalue7.4;
  47.    put @1 'Pure Error'  @15 df_pe  @20 ss_pe F10.2          @35 mse_pe  F10.2;
  48.    put @1 'Total Error' @15 df_err @20 sse    F10.2           @35 mse_err F10.2;
  49.    put @1 '------------------------------------------------------------------';
  50.   end;  
  51. run;
  52. ods listing;
复制代码
Hi,
I am not worrying too much about lack of fit for my newest SAS version. That is just for my interest. It yields the matched results as from proc rsreg. On the other hand, I do believe you can compute it in a more direct way.
My question is, when no replicates in the data, there is obviously no pure error. How to deal with this for lack of fit test?
JingJu

使用道具

藤椅
Isscaliu 发表于 2010-10-27 16:46:30 |只看作者 |坛友微信交流群
厉害,受教了。对于你的问题,很乐意讨论。
Obviously, there is no pure error when there is no replicate observations available. The text book says we can conduct a approximate lack of fit by grouping similar vectors if there are the cases. However, in my point of view, this will be resulting loss of information in dealing with continuous data.  Another thing is, putting similar observations into pseudo-replicates are very subjective.
It was the best of times, it was the worst of times.

使用道具

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

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

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

GMT+8, 2024-5-10 06:29