Dears,
I am trying to apply the minimization algorithm mentioned in the attached pdf with SAS 9.2.
I am using the following code with the data attached (values already centered).
proc iml;
use in_data;
read all into in_data;
in_data=in_data;
start F(x) global(in_data);
x = {0, 0, 0};
f = sum(exp(in_data*x));
return(f);
finish F;
start G(x) global(in_data);
x = {0, 0, 0};
g = (exp(in_data*x)`)*in_data;
return(g);
finish G;
x = {0, 0, 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x, optn) grd="G";
print xres;
quit;
xres gives me the following result: 0.0301847 -0.008427 0.0540752
When I use R, I get the following results: 0.4941690 -0.2042731 1.5939447. I would like to know how could I fix the code so that the results are more similar to those provided by R.
Any help would be highly appreciated.
I think the following will fix the problem. Always use a row vector for x0 and don't try to modify x within the functions F and G.
proc iml;
use test;
read all into in_data;
start F(x) global(in_data);
f = sum(exp(in_data*x`));
return(f);
finish F;
start G(x) global(in_data);
g = (exp(in_data*x`)`)*in_data;
return(g);
finish G;
x0 = {0 0 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x0, optn) grd="G";
print xres;
quit;
I think the following will fix the problem. Always use a row vector for x0 and don't try to modify x within the functions F and G.
proc iml;
use test;
read all into in_data;
start F(x) global(in_data);
f = sum(exp(in_data*x`));
return(f);
finish F;
start G(x) global(in_data);
g = (exp(in_data*x`)`)*in_data;
return(g);
finish G;
x0 = {0 0 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x0, optn) grd="G";
print xres;
quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.