全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2518 11
2013-12-07
悬赏 1 个论坛币 未解决
妹子是个入门菜鸟,这个程序已经想了一天了,大神帮帮忙吧。求蔑视求秒杀。妹子的脑子应经转不动了。
Topic:  Nonlinear regression

Aim:        Fit a nonlinear model and provide graphs of the results.

Dataset:

data a ;
     input trial x y ;
     datalines ;
1 480 58
1 440 91
1 400 112
1 360 344
1 320 942
2 570 48
2 520 69
2 475 102
2 425 265
2 380 1456
3 480 .
3 440 .
3 400 179
3 360 424
3 320 837
4 510 86
4 465 111
4 425 219
4 380 298
4 360 708
5 570 27
5 520 75
5 475 83
5 425 252
5 380 351
proc print ;

/*
%mp11(b0=20000,b1=300,b2=-50,xstart=319,xend=500,group=0) ;
*/
run ;
quit ;

Shell macro code:

Notes:

1. The NL model is y = = (a0 /(x-a1)) + a2;

2. Use b0, b1, b2 to pass the "initial guesses" of the NL model parameters (see above)

3. To plot the results use xstart to xend (see below)

%macro mp11(data=,b0=,b1=,b2=,xstart=,xend=, group=);
  proc nlin data =&data ;
  parms a0=&b0 a1=&b1 a2=&b2;
     if &group EQ 0 then
        model y = (a0 /(x-a1)) + a2;
    else do;
        model y = (a0 /(x-a1)) + a2;
        by &group;
    output out=b parms= a0 a1 a2;
/*
  dataset to create the fitted model:
     use xstart to xend to get X2 and create Y2 from:

     Y2 = (a0 /(X2-a1)) + a2;

proc gplot ;
   overlay the plots y*x Y2*X2
*/   
%mend mp11;

下面是我目前为止尽力做的,
data a ;
     input trial x y ;
     datalines ;
1 480 58
1 440 91
1 400 112
1 360 344
1 320 942
2 570 48
2 520 69
2 475 102
2 425 265
2 380 1456
3 480 .
3 440 .
3 400 179
3 360 424
3 320 837
4 510 86
4 465 111
4 425 219
4 380 298
4 360 708
5 570 27
5 520 75
5 475 83
5 425 252
5 380 351
proc print ;
%mp11(b0=20000,b1=300,b2=-50,xstart=480,xend=320,group=trial) ;
run ;
quit;
%macro mp11(data=,b0=,b1=,b2=,xstart=,xend=, group=);
  proc nlin data =&data a;
  parms a0=&b0 a1=&b1 a2=&b2;
     %if &group EQ 0 %then %do;
        model y = (a0 /(x-a1)) + a2;
  run;
  %end;
    %else %do;
        model y = (a0 /(x-a1)) + a2;
        by &group;
  run;
  %end;
data plot;
    output out=b parms= a0 a1 a2;
%do x2=&xstart %to &xend by -40;
y2=(a0/(x2-a1))+a2;
output;
%end;
proc gplot;
plot y*x y2*x2/overlay;
%mend mp11;

二维码

扫码加我 拉你入群

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

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

全部回复
2013-12-7 20:14:04
大神们大侠们,帮帮忙吧,表再围观啦,该出手时就出手
二维码

扫码加我 拉你入群

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

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

2013-12-8 08:41:39
可是你没有说你要问什么啊,只是告诉别人帮你看看,别人看完了,然后呢?你不是要别人把你贴的这个程序从头到尾全部讲解一遍吧?

你没有说明你遇到了什么问题,也没有提出你的问题啊
二维码

扫码加我 拉你入群

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

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

2013-12-8 09:30:55
为什么要这么做
二维码

扫码加我 拉你入群

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

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

2013-12-8 11:28:17
Imasasor 发表于 2013-12-8 08:41
可是你没有说你要问什么啊,只是告诉别人帮你看看,别人看完了,然后呢?你不是要别人把你贴的这个程序从头 ...
我不大明白那个data set to create the fitted model是要干什么用,意思是把从xstart到xend代入得到那个非线性回归的方程吗? 如果是这样,我写的这一段
“        data plot;
        %do x2=&xstart %to &xend by -40;
        y2=(a0/(x2-a1))+a2;
        output;
"
但是运行出来也不出成果。是不是这段程序我本身就写得不对。
还有就是overlay the plots y*x Y2*X2
在这里因为有五组数据,是不是就是plots y1*x1 y2*x2 y3*x3 y4*x4 y5*x5/overlay?
/*
%mp11(b0=20000,b1=300,b2=-50,xstart=319,xend=500,group=0) ;
*/
这处是教授举得例子来invoke宏程序,于是我针对这道题一样画葫芦,

%mp11(b0=20000,b1=300,b2=-50,xstart=480,xend=320,group=1) ;

但是运行的时候log 那边检测说这边group=1不对,于是我尝试这group=trial,虽然出了output, 但是感觉这样整套运行下来应该不对,因为我这边宏程序里写的是一组数据一组数据分析

        %do x2=&xstart %to &xend by -40;

因为datalines里的五组数据里每组数据里的数大概都相差40左右。
问题有点多,望大神指点下。
二维码

扫码加我 拉你入群

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

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

2013-12-8 11:34:20
爱萌 发表于 2013-12-8 09:30
为什么要这么做
教授给的shell code,我都不大明白/*   */里的那些是什么意图。哎,网上查了好多,都没有什么类似的。同学做的其他project都找到原题了,感觉好难过,自己又笨又没天赋,不过还是很想学好sas,毕竟很有用。菜鸟摸爬滚打努力摸索中。
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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