妹子是个入门菜鸟,这个程序已经想了一天了,大神帮帮忙吧。求蔑视求秒杀。妹子的脑子应经转不动了。
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;