Programming the statistical procedures from SAS

NLMIXED: Alternative covarinace structures?

New Contributor
Posts: 4

NLMIXED: Alternative covarinace structures?

With proc mixed one can specifiy a covariance structure for ranomd effects that has the same structure but with different values for each level of a categorical variable. For example, suppose Time is continuous, Period is a 0/1 variable that signals the transition from one period of time to another, SubjectID identifies the indiviudal subjects.  Using proc mixed we can fit a random slope and intercept model where the covarnace struture is different for perods 0 and 1 wiht the following code.

Proc Mixed data=D;

     class SubjectID Period;

     model y = Time/s;

     random intercept time/type=un subject= SubjectID group= period;


Because period changes within subjects, the covariance matrix for the random effects is block diagnonal.   Mixed is used as an example but for the model I really want to fit I will need NLMIXED.  Can anyone explain how this covariance strucutre can also be implemented with  NLMIXED?    



Regular Contributor
Posts: 169

Re: NLMIXED: Alternative covarinace structures?

In order to have different random efffect covariance values across levels of some group with the NLMIXED procedure, you need to include group-specific random effects in your linear predictor.  When constucting the covariance structure for the random effects, we assume that the group-specific random effects are independent of each other.

For the example which you show above, suppose that period has just two values (1 and 2).  Then NLMIXED code which would fit the model specified by your MIXED code would be:

proc nlmixed data=D;

  /* construct linear predictor, including random effects */

  eta = b0 + b1*time +

        (u0_1 + u1_1*time)*(period=1) +  /* period 1 random effects */

        (u0_2 + u1_2*time)*(period=2);    /* period 2 random effects */

  /* Parameterize the covariance between u0_i and u1_i as */

  /* a function of the correlation between u0_i and u1_i. */

  /* Parameterize the correlation between u0_i and u1_i   */

  /* through the inverse Fisher transformation.           */

  rho_1 = (exp(2*z1) -1) / (exp(2*z1) + 1);   /* rho(u0_1, u1_1) */

  rho_2 = (exp(2*z2) -1) / (exp(2*z2) + 1);   /* rho(u0_2, u1_2) */

  /* Specify and fit the model */

  model y ~ normal(eta, Vres);

  random u0_1 u1_1 u0_2 u1_2 ~ normal([0,0,0,0],

                                      [Vu0_1, rho_1*sqrt(Vu0_1*Vu1_1), 0, 0,

                                              Vu1_1,                   0, 0,

                                                     Vu0_2, rho_2*sqrt(Vu0_2*Vu1_2),




Note that this can quickly become a very difficult estimation problem for NLMIXED because of the need to integrate over all random effects.

Occasional Contributor
Posts: 7

Re: NLMIXED: Alternative covarinace structures?

Hi, Dale:

Shouldn't "time" be part of the random slope terms? That is, I think the linear predictor "eta" should be written as follows:

eta = b0 + b1*time + (u0_1 + u1_1*time)*(period=1) + (u0_2 + u1_2*time)*(period=2);


Regular Contributor
Posts: 169

Re: NLMIXED: Alternative covarinace structures?

Yes, indeed!  Thanks for the correction.

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation