BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Marx
Calcite | Level 5

Dear Xia Keshan,

 

Thank you very much for your comments. 

 

And I cannot understand your last comments. 

 

proc nlin data=circle converge=1e-6;
parms x0 = 0, y0 = 0, R = 1;
bounds R >= 0;
delta = ( (x - x0)**2 + (y - y0)**2 - R**2 ) **2;
model zero = delta;
run;

Can I estimate parameter values without data for independent variables?

 

Sincerely yours,

 

J1

Ksharp
Super User
Yes. You can. the point is what is your Object value , so I can minimize it .
Did you read that blog I pointed you ?

I am also shocked by your so complicated constraint condition:

bounds x2>0,x3>0,x1<1,X1*(X2+X3)<1,X1*(1+X2+X3)<1;



Marx
Calcite | Level 5

Dear Xia Keshan,

 

I read the article that you pointed. My objective is to maximize the utility function (U). I have data for C, M, G, T, and I would like to estimate X1, X2, X3, X4 with standard errors. I read the article that you pointed, and my understading is that there are observed data for the objective function. But my case is that there is no observed data for the utility function. In this case, I would like to know how to estimate X1, X2, X3, X4 with standard errors. FYI, I attached data for dependent variables.

 

For iml, is it possible to add these restrictions? If so, then I can get parameter values using iml. But these parameter values are just temporal. Then, I can get some values for independent variable using these parameter values and data for dependent values. And then, I can use Inlin to get standard errors. I would like to know your opinion. Does it make sense?

 

Parameters: X1, X2, X3, X4

Dependent variable: U

Independent variables: C, M, G, T

Model: U = (1/X1)*(C*M^X2*(380/G)^X3)^X1*exp(-X4*T)

Restriction for parameters:

X2, X3>0;

-infinity < X1 <1;

X1*(X2+X3) < 1;

X1*(1+X2+X3) < 1

 

 

 

Ksharp
Super User
The problem is proc nlin can't handle so complicated constrain condition, 
and it is about OLS estimate, but you want Maximal U function. I think that is not right way to do it.

BTW, that attachment didn't contain any data, just a proc import !


Ksharp
Super User
So it is Utility function ?
And you want 
Max :  sum ( (1/X1)*(C*M^X2*(380/G)^X3)^X1*exp(-X4*T) )
?

Can you share your data ,you didn't post any data, that is just sas code .

Due to your so complicated constrain condition, which force me to use GA .






data have;
 call streaminit(1234);
 do i=1 to 100;
  C=rand('uniform');
  M=rand('uniform');
  G=rand('uniform');
  T=rand('uniform');
  output;
 end;
 drop i;
run;


proc iml;
use have;
read all var {C M G T};
close; 

start func(x) global(C,M,G,T); 
 if x[2]<=0 | 
    x[3]<=0 | 
    x[1]>=1 | 
    x[1]#(x[2]+x[3])>=1 | 
    x[1]#(1+x[2]+x[3])>=1 
 then obj=-999999; 
 else obj=sum(  (1/x[1])# ( (C#(M##x[2])# ((380/G)##x[3]) )##x[1] )  #exp(-x[4]#T)  );
 return (obj);
finish;

id=gasetup(1,4,123456789);
call gasetobj(id,1,"func");
call gasetsel(id,1000,1,0.95);
call gasetcro(id,0.05,4);
call gasetmut(id,0.05);

encoding={-9   0  0 -99,
            1  9  9  99};
call gainit(id,10000,encoding);
niter = 100;
do i = 1 to niter;
 call garegen(id);
 call gagetval(value, id);
end;
call gagetmem(mem, value, id, 1);

print mem[ l="best member:"],
      value[l = "Max Value:"] ;
call gaend(id);
quit;



Rick_SAS
SAS Super FREQ

@Ksharp: Instead of GA, I recommend that you look at the NLPNMS or NLPQN functions and use the NLC= option (rather than the BLC matrix) to specify a module that evaluates whether parameters are inside nonlinear constraints.

Ksharp
Super User
Ha, @Rick, I never though there is an option could handle so complicated constrain condition.
Here is what I got :



data have;
 call streaminit(1234);
 do i=1 to 100;
  C=rand('uniform');
  M=rand('uniform');
  G=rand('uniform');
  T=rand('uniform');
  output;
 end;
 drop i;
run;


proc iml;
use have;
read all var {C M G T};
close; 

start func(x) global(C,M,G,T);
 obj=sum(  (1/x[1])# ( (C#(M##x[2])# ((380/G)##x[3]) )##x[1] )  #exp(-x[4]#T)  );
 return (obj);
finish;
start C_UC2D(x);
 c = j(5,1,0);
 c[1]=1-x[1];
 c[2]=x[2];
 c[3]=x[3];
 c[4]=1-X[1]*(X[2]+X[3]);
 c[5]=1-X[1]*(1+X[2]+X[3]);
return(c);
finish;

x = j(1,4,1);
opt = j(1, 11, .);
opt[1]=1;opt[2] = 3; opt[10] = 5; 

CALL NLPNMS(rc,xres,"func",x,opt, , , , , "C_UC2D");
quit;




OUTPUT:
Optimization Results
Iterations	7	Function Calls	59
Restarts	0	Objective Function	1441457.6526
Maximum Constraint Violation	0	Merit Function	-1441457.653
Actual Over Pred Change	0.0001	 	 
ABSXCONV convergence criterion satisfied.
Optimization Results
Parameter Estimates
N	Parameter	Estimate
1	X1	0.000024143
2	X2	0.641951
3	X3	1.527559
4	X4	2.563865
Value of Objective Function = 1441457.6526


Marx
Calcite | Level 5

Dear Xia Keshan,

 

 

Thank you very much for your help.

 

I saw the result of parameter estimation, and I would like to know how to get standard errors. 

 

I attached the excel file about data here. 

 

I deeply appreciate your help.

 

 

Sincerely yours,

 

J1

Ksharp
Super User
Did you see the reply of Rick ? 
" is singular for X1=0, so it cannot have a maximum."

That utility function is not right. You can't get the maximal value .
About standard error, I think you can run the code many times and use empirical std dev to estimate it .

Ksharp
Super User
@Rick,
I am worried about parameter estimate result. 
There are so many local optimal values. Every time, I run the code with different initial value,
I got the different result.
It looks like GA has some edge to get global optimal value.



Rick_SAS
SAS Super FREQ

The function the OP wrote down is singular for X1=0, so it cannot have a maximum. As far as I can tell, the problem is ill-defined.  I do not know what the OP wants.

Ksharp
Super User
Here is an example to get standard error.
But as @Rick pointed out ,your utility function is not validate . 
You should take a look at this utility function.



data have;
infile cards truncover expandtabs;
input C	M	G	T;
cards;
2.36361198	1.69019608	2.549003262	1990
2.390935107	1.770852012	2.551449998	1991
2.431363764	1.84509804	2.551449998	1992
2.436162647	1.875061263	2.552668216	1993
2.530199698	2.064457989	2.555094449	1994
2.643452676	2.120573931	2.557507202	1995
2.722633923	2.1430148	2.559906625	1996
2.764176132	2.152288344	2.561101384	1997
2.794488047	2.146128036	2.564666064	1998
2.827369273	2.220108088	2.565847819	1999
2.870988814	2.352182518	2.568201724	2000
2.907948522	2.387389826	2.56937391	2001
2.938519725	2.469822016	2.571708832	2002
2.972665592	2.615950052	2.575187845	2003
3.024485668	2.748962861	2.57634135	2004
3.083860801	2.820857989	2.579783597	2005
3.151982395	2.900367129	2.582063363	2006
3.240049772	2.983626287	2.584331224	2007
3.343999069	3.058426024	2.586587305	2008
3.394101302	3.001733713	2.587710965	2009
3.457427693	3.145817714	2.591064607	2010
;
run;

proc iml;
use have;
read all var {C M G T};
close; 

start func(x) global(C,M,G,T);
 obj=sum(  (1/x[1])# ( (C#(M##x[2])# ((380/G)##x[3]) )##x[1] )  #exp(-x[4]#T)  );
 return (obj);
finish;
start C_UC2D(x);
 c = j(5,1,0);
 c[1]=1-x[1];
 c[2]=x[2];
 c[3]=x[3];
 c[4]=1-X[1]*(X[2]+X[3]);
 c[5]=1-X[1]*(1+X[2]+X[3]);
return(c);
finish;

call randseed(123456789);
x = j(1,4,.);

opt = j(1, 11, .);
opt[1]=1;opt[2] = 3; opt[10] = 5; 

ods select none;

do i=1 to 14;
call randgen(x,'uniform');x=x#10;
ods output  ParameterEstimates=parm_est ConvergenceStatus=converg;
CALL NLPNMS(rc,xres,"func",x,opt, , , , , "C_UC2D");
end;
quit;
ods select all;
proc sort data=parm_est;by parameter;run;
data want;
 set parm_est;
 if mod(_n_,2)=0;
run;
proc means data=want mean std nway;
class parameter ;
var estimate;
run;







OUTPUT:
Analysis Variable : Estimate
Parameter	N Obs	Mean	Std Dev
X1	14	0.2696622	0.3173314
X2	14	3.0781021	3.0322890
X3	14	3.4676889	3.6468576
X4	14	4.6412822	3.1000697
Ksharp
Super User
Use stderr instead of std , maybe:


proc means data=want mean stderr nway;
class parameter ;
var estimate;
run;


Marx
Calcite | Level 5

Dear Xia Keshan,

 

I deeply appreciate your help.

I think the utility function needs some constraints to maximize it. This utility function is a part of my model.

To solve the optimal control problem, I used GAMS (General Algebraic Modeling System).

But, unfortunately, GAMS cannot estimate parameter values.

I recently found that SAS is a useful program to estimate parameter values such as a Cobb-Douglas production function.

I would like to know if SAS can solve the optimal control problem such as a differential game or not.

 

For standard error, I saw the asymptotic standard errors in SAS.

I would like to know if standard errors are different from asymptotic standard errors or not.

To get asymptotic standard errors using SAS, do I need a specific coding?

 

I need time to figure out what you did, but can you explain more detail about your last coding.

If I want to estimate different parameter values, then I would like to know which part I have to change in your coding.

 

Thank you very much for your help again.

 

Sincerely yours,

 

J1

Ksharp
Super User
As Rick pointed out, either your utility function is not right or your constraint condition
x1<1 is not right. when x1~0 your utility function can't get the max value.

"I would like to know if SAS can solve the optimal control problem such as a differential game or not."
I am not familiar with these concepts . But I am sure SAS can solve almost any optimal problem.
Especially for SAS/OR .


"I would like to know if standard errors are different from asymptotic standard errors or not."
I think both are the same thing. Asymptotic standard errors are based on big sample(e.g. n is big enough).
If you want exact std err you need to know exact distribution , but it is every hard sometime.


"To get asymptotic standard errors using SAS, do I need a specific coding?"
Most time, SAS can give you std err ,no need for coding. But for your this special case,I think you need to write some code.


"If I want to estimate different parameter values, then I would like to know which part I have to change in your coding."
For changing Object function, you need change:
start func();
....
return (obj);
finish;

For changing constrain condition , you need change another function,
Check IML documentation to know how to write these.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 39 replies
  • 3117 views
  • 5 likes
  • 3 in conversation