BookmarkSubscribeRSS Feed
Forecaster
Obsidian | Level 7

hello, I'm trying to code up the likelihood below using Proc NLMIXED.

 

I have dataset that is person period, sorted by id and time. here is the structure of dataset, sorted by ID and time.

 

ID Time y (Event) last_ob x1
1 1 0 1 20
2 1 0 0 21
2 2 0 1 20
2 3 0 0 10
2 4 1 1 5
3 1 0 0 12
3 2 0 0 23
3 3 0 0 10
3 4 0 0 4
3 5 0 0 23
3 6 0 0 10
3 7 0 1 5

 

Forecaster_0-1744035604814.png

 

Below is the sas proc NLMIXED code:

 

 

proc nlmixed data=your_data qpoints=50;
   parms mu=0 sigma2=1 beta1=0;
   bounds sigma2 > 0;

   /* Linear predictor */
   linpred = eta + beta1*x1;
   theta = exp(linpred) / (1 + exp(linpred));
   log_surv = log(1 - theta);

   /* Accumulate log survival up to time t-1 using ZLAG */
   if time = 1 then acc_log_surv = 0;
   else acc_log_surv = ZLAG(acc_log_surv) + ZLAG(log_surv);

   /* Event or censoring contribution */
   if y = 1 then loglik = acc_log_surv + log(theta);
   else if last_obs = 1 then loglik = acc_log_surv + log(1 - theta);
   else loglik = .;

   model y ~ general(loglik);
   random eta ~ normal(mu, sigma2) subject=id;
run;

 

 

I have two part question,

 

what would "y" in model general(loglik) be? and also how do I code up cumulative product (or log sum) of P(T) and S(T) since retain and first.id is not available. I just used zlag based on time = 1? is this correct?

 

Any help would be greatly appreciated.

 

Thanks

 

Sri

 

 

 

 

1 REPLY 1
Season
Barite | Level 11

I am not an expert in compiling codes for maximizing custom likelihoods, but I know somebody is. There is a monograph dedicated to the theory of maximum likelihood estimation as well as how to implement it in statistical softwares including SAS named Maximum Likelihood Estimation and Inference: With Examples in R, SAS and ADMB (Statistics in Practic.... Issues on maximizing custom likelihoods via SAS procedures like PROC NLMIXED and PROC NLP are discussed frequently in that book. While waiting for an expert in the community for his/her help, you may also consult the book to see if there is anything useful. In addition, writing an e-mail to the author of the book to directly raise your question to him/her might be of help.

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

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
  • 1 reply
  • 516 views
  • 0 likes
  • 2 in conversation