BookmarkSubscribeRSS Feed
Medo_Aldeni
Fluorite | Level 6

Hello,

Attached is the code I'm using to find MLEs.

I'm trying to find the bias and standard deviation for given parameters.

my problem is: whenever I changed the initial values for the parameters, I get a different answer (output). 

For example, if I change the initial values ( lambda30, lambda40) from 0.1,0.1 to 0.4,0.4 , respectively, I will get different answers.

Could you figure out why?

Can you make a refinement for the code?

Sincere thanks!

8 REPLIES 8
Rick_SAS
SAS Super FREQ

If you haven't already read these articles, please look at

I don't seem to be able to reproduce what you are seeing. I set nr=1 and optn={1 2}.  I ran the program twice, once with initial conditions (1, 1, 0.1, 0.1) and again with (1, 1, 0.4, 0.4).

I got the exact same optimum both times.

 

Perhaps you could post a screenshot of what you are seeing.

 

Medo_Aldeni
Fluorite | Level 6

Thank you professor.

Please see the attachment.

Ksharp
Super User
That is because the following code change the result:

"
parest=estmat[:,]; 
gamma_mle=parest[1]; c_mle=parest[2]; lm3_mle=parest[3];	lm4_mle=parest[4];
gamma_bias=gammav-gamma_mle; c_bias=cv-c_mle; lm3_bias=lambda3v-lm3_mle; lm4_bias=lambda4v-lm4_mle;
onev=j(nrow(estmat),1,1); devv=(estmat-onev*parest)#(estmat-onev*parest);
varr=devv[+,]/(nrow(estmat)-1); stdev=sqrt(varr);
gamma_sd=stdev[1]; c_sd=stdev[2]; lm3_sd=stdev[3]; lm4_sd=stdev[4];
res1[nc,]=lambda4v||cv||gammav||lambda3v||gamma_bias||gamma_sd||lm3_bias||lm3_sd||c_bias||c_sd||lm4_bias||lm4_sd;
"






Medo_Aldeni
Fluorite | Level 6

Hello Xia Keshan,

I don't think so the reason is what you have mensioned, since I defined a nother function (lf2(x)) and I GOT THE SAME RESULTS.

I think the reason is the function itself.

 

Thanks!

Ksharp
Super User
No. Once you change optn={1 0}; -> optn={1 2};  which means you can the result of call nlptr() .
After running the code with different initial value , I got the result, in other words, there must be 
some code from you to change the final result.

gamma0=1; c0=1; lambda30=0.1; lambda40=0.1;
OUTPUT:
MLE-simulation
Optimization Results
Parameter Estimates
N	Parameter	Estimate	Gradient
Objective
Function
1	X1	1.865201	0.000001331
2	X2	2.079614	0.000016103
3	X3	1.054787	0.000024134
4	X4	0.790518	0.000010652
Value of Objective Function = -313.0280387



gamma0=1; c0=1; lambda30=0.4; lambda40=0.4;
OUTPUT:
MLE-simulation
Optimization Results
Parameter Estimates
N	Parameter	Estimate	Gradient
Objective
Function
1	X1	1.865201	0.000009320
2	X2	2.079609	-0.000002477
3	X3	1.054794	-0.000003713
4	X4	0.790524	0.000008522
Value of Objective Function = -313.0280387
 
Medo_Aldeni
Fluorite | Level 6

Do you know how to fix the code in order to get correct standard dev and bias. Your help would be appreciated.

parest=estmat[:,]; 
gamma_mle=parest[1]; c_mle=parest[2]; lm3_mle=parest[3];	lm4_mle=parest[4];
gamma_bias=gammav-gamma_mle; c_bias=cv-c_mle; lm3_bias=lambda3v-lm3_mle; lm4_bias=lambda4v-lm4_mle;
onev=j(nrow(estmat),1,1); devv=(estmat-onev*parest)#(estmat-onev*parest);
varr=devv[+,]/(nrow(estmat)-1); stdev=sqrt(varr);
gamma_sd=stdev[1]; c_sd=stdev[2]; lm3_sd=stdev[3]; lm4_sd=stdev[4];
res1[nc,]=lambda4v||cv||gammav||lambda3v||gamma_bias||gamma_sd||lm3_bias||lm3_sd||c_bias||c_sd||lm4_bias||lm4_sd;
"

 

Ksharp
Super User
No. I have no time to go through all these. You have to check it on your own.
I am sure  matrix  estmat[ ]  is right.

Rick_SAS
SAS Super FREQ

You are displaying the Monte Carlo means of the parameter estimates. Means are, of course, not robust statistics, so this could be caused by a small number of random samples for which one initial conditions (ICs) converges and the other does not (or converges to a different local maximum.)

 

Here's how to determine what is happening:

  1. Run the simulation with one set of ICs and save the parameter estimates to MLE_EST1. Then run the simulation again with the other ICs and save the estimates to MLE_EST1. 
  2. Plot the parameter estimates for the two runs against each other in a scatter plot. 
  3. For most of samples, the two estimates should fall on or near the line y=x.  For a few, you will probably see that the estimates are far from each other.
  4. If you label each marker with the simulation number, that will enable you to find out which samples are leading to different estimates.
  5. You can then investigate the MLE function for those samples.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 8 replies
  • 1673 views
  • 6 likes
  • 3 in conversation