I found something of a solution I think. It is a bit messy and I'm not sure if this is actually helping me, but it would be nice if someone might have a look over it and give some comments on whether the code does what I think it does. So first of all I changed my data format to a wide format, meaning that there is just one row per subject now. In this row the dependent variable for different time points is given as different variables and the associated times are in separate variables. I also included a variable that contains the number of observations for a patient, which is useful for a loop later on. Example data for 20 patients is given below: * example data; data data; infile datalines delimiter=','; input subjectID n yvar1-yvar19 time1-time19; datalines; 2956,8,32,30,32,31,28,30,27,27,.,.,.,.,.,.,.,.,.,.,.,14,42,77,105,140,189,259,315,.,.,.,.,.,.,.,.,.,.,. 3551,7,31,34,32,31,30,24,17,.,.,.,.,.,.,.,.,.,.,.,.,11,39,74,102,130,186,313,.,.,.,.,.,.,.,.,.,.,.,. 3870,8,36,37,37,32,33,32,33,31,.,.,.,.,.,.,.,.,.,.,.,6,34,69,97,126,189,252,315,.,.,.,.,.,.,.,.,.,.,. 4752,6,31,27,27,26,21,23,.,.,.,.,.,.,.,.,.,.,.,.,.,7,64,134,197,253,323,.,.,.,.,.,.,.,.,.,.,.,.,. 5155,9,28,28,27,29,27,27,28,26,24,.,.,.,.,.,.,.,.,.,.,0.001,13,49,71,104,139,204,258,328,.,.,.,.,.,.,.,.,.,. 7399,8,35,33,31,30,27,28,27,26,.,.,.,.,.,.,.,.,.,.,.,0.001,28,56,84,111,182,245,301,.,.,.,.,.,.,.,.,.,.,. 8480,9,32,32,34,31,31,30,28,28,25,.,.,.,.,.,.,.,.,.,.,0.001,27,62,84,119,181,244,307,364,.,.,.,.,.,.,.,.,.,. 9683,6,31,30,29,29,28,28,.,.,.,.,.,.,.,.,.,.,.,.,.,0.001,18,41,69,97,133,.,.,.,.,.,.,.,.,.,.,.,.,. 10995,7,29,30,29,29,27,27,26,.,.,.,.,.,.,.,.,.,.,.,.,0.001,28,63,93,126,154,182,.,.,.,.,.,.,.,.,.,.,.,. 11041,8,24,19,20,19,19,19,19,16,.,.,.,.,.,.,.,.,.,.,.,40,94,108,137,164,221,290,350,.,.,.,.,.,.,.,.,.,.,. 13105,9,29,29,28,28,31,33,26,20,14,.,.,.,.,.,.,.,.,.,.,0.001,7,35,63,92,120,190,244,314,.,.,.,.,.,.,.,.,.,. 13613,5,32,28,23,25,24,.,.,.,.,.,.,.,.,.,.,.,.,.,.,28,56,84,112,143,.,.,.,.,.,.,.,.,.,.,.,.,.,. 15472,8,22,25,26,24,24,23,20,22,.,.,.,.,.,.,.,.,.,.,.,14,42,70,98,126,183,252,308,.,.,.,.,.,.,.,.,.,.,. 16375,8,21,22,14,18,13,13,8,6,.,.,.,.,.,.,.,.,.,.,.,0.001,7,48,74,95,132,200,326,.,.,.,.,.,.,.,.,.,.,. 18157,8,28,22,21,20,20,23,14,10,.,.,.,.,.,.,.,.,.,.,.,0.001,29,59,92,127,183,253,316,.,.,.,.,.,.,.,.,.,.,. 18747,8,33,34,32,30,28,27,26,24,.,.,.,.,.,.,.,.,.,.,.,0.001,24,52,80,108,136,199,273,.,.,.,.,.,.,.,.,.,.,. 19256,7,34,31,32,34,30,32,33,.,.,.,.,.,.,.,.,.,.,.,.,0.001,35,63,98,126,154,182,.,.,.,.,.,.,.,.,.,.,.,. 19764,6,35,34,33,33,33,31,.,.,.,.,.,.,.,.,.,.,.,.,.,7,70,133,189,252,316,.,.,.,.,.,.,.,.,.,.,.,.,. 19871,6,24,18,16,15,15,14,.,.,.,.,.,.,.,.,.,.,.,.,.,10,70,135,198,247,329,.,.,.,.,.,.,.,.,.,.,.,.,. 20121,4,30,24,29,29,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,5,40,63,106,.,.,.,.,.,.,.,.,.,.,.,.,.,.,. ; *The model now looks like this: proc nlmixed data=data gconv=0 maxit=100 maxfunc=2000; array yvars{19} yvar1-yvar19; array times{19} time1-time19; array means{38} mean1-mean38; parms td_pop1=536.32 td_pop2=29795 a_pop=33.2965 b_pop=0.5079 prob=0.3710 s2epsilon=20.9501; bounds s2epsilon prob > 0; bounds prob < 1; pi=constant('pi'); td1=td_pop1; td2=td_pop2; B=b_pop; A=a_pop; lh1=1; lh2=1; do i=1 to n; means=A*exp(-(times/td1)**B); means[i+19]=A*exp(-(times/td2)**B); lh1=lh1*(1/((2*pi*s2epsilon)**0.5)) * exp(-0.5*(((yvars - means)**2) / s2epsilon)); lh2=lh2*(1/((2*pi*s2epsilon)**0.5)) * exp(-0.5*(((yvars - means[i+19])**2) / s2epsilon)); end; lh=prob*lh1 + (1 - prob)*lh2; ll=log(lh); dum=1; model dum ~ general(ll); run; So what I think (and certainly hope) this code does is: 1) It does every calculation per data set row (so subject in this case). This is what I suspect that nlmixed does in general although I couldn't really find any information on how nlmixed works internally. 2) This means it calculates an expectation per subject, time point and mixture component combination inside the loop. 3a) This mean is put into the normal density together with the corresponding dependent variable measurement to give a subject-time-mixture component specific likelihood contribution. 3b) These likelihood contributions are multiplied per mixture component which gives a subject-mixture component specific likelihood contribution. 4) After the loop is finished, the two subject-mixture component specific likelihood contributions are added under the mixture probability to give a subject specific likelihood contribution. 5) The log of this likelihood contribution is modeled using a dummy variable, since the whole likelihood has been specified already using all the dependent variable outcomes, so it is not dependent on that anymore. 6) nlmixed multiplies all the subject specific likelihood contributions in the background to give the total likelihood for one iteration. I'm really hoping people have some insides or opinions about this, since I'm really uncertain if the code is correct. Especially the dummy part I'm not sure about, since I just took this from something I found on the internet; this paper uses it in the code:http://www.education.umd.edu/EDMS/fac/Harring/MIsc/WUSS-Paper.pdf. Also, I'm having troubles figuring out how to get predictions from this model and how to include random subject effects. So thoughts on that are also more than welcome. Magnus
... View more