BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Salah
Quartz | Level 8

@Rick_SAS

 

Hi

I am working on a very simple problem that I have addressed several times before, and I always receive good estimates. For some reason, this time I am failing miserably; the maximum likelihood estimates (MLE) are so HUGE. I’m not sure where I went wrong. I need help, please.

Proc iml;
seed=0;   	theta= 1.5 ; 	beta= 1;   		 m=50;     			      
print theta beta m ;
**** MLE ***; start MLE_func(y) global (m,X); func=0; theta=y[1]; beta=y[2]; Log_X=log(1+x#beta); func=func + m*log(theta*beta) - (theta+1) * Log_X[+] ; Return(func); finish;
call randseed(seed); call randgen(U, "Uniform"); Call sort(U); X =( (1-U)##(-1/theta) - 1 )/ beta; ************* Constrain MLE ***********************; con={.001 .001, . . }; x0={1,1}; opt={2 0}; tc={10000 16000}; Call nlpqn(rc, MLE_ret, "MLE_func", x0, opt, con,tc); Theta_hat = MLE_ret[1]; Beta_hat = MLE_ret[2]; print Theta_hat Beta_hat; quit;

 

Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ
Do you need any further help? If not, you can close this thread.

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

When posting an example, please use a seed value that is nonzero so that we can reproduce your results. In the following, I use
seed=10;

 

You can't perform a MLE on a single datum. You need a sample size greater than 1.  I suspect you know this and just forgot to allocate an array for U.  This should address your immediate problem:

 

Proc iml;
seed=10;   	theta= 1.5 ; 	beta= 1;   		 m=50;     			      
print theta beta m ;

**** MLE ***;
start MLE_func(y) global (m,X);
 theta=y[1];
 beta=y[2];
 Log_X=log(1+x#beta);
 func = m*log(theta*beta) - (theta+1) * Log_X[+] ;
 Return(func);
finish;

call randseed(seed);    
N = 100;
U = j(N, 1); 
call randgen(U, "Uniform"); 
Call sort(U);
X =(  (1-U)##(-1/theta) - 1  )/ beta;

************* Constrain MLE ***********************;
x0={1,1};
con={.001 .001, . .  };
opt={2 0};
tc={10000 16000};
Call  nlpqn(rc, MLE_ret, "MLE_func", x0, opt, con,tc);

Theta_hat = MLE_ret[1];
Beta_hat  = MLE_ret[2];
print Theta_hat  Beta_hat;

 

Salah
Quartz | Level 8

Thank you so much!!!

Rick_SAS
SAS Super FREQ
Do you need any further help? If not, you can close this thread.
Salah
Quartz | Level 8

I am sorry, I thought that I closed it by just hitting the thumb up.

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 631 views
  • 1 like
  • 2 in conversation