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 |

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