Programming the statistical procedures from SAS

Nested random effect in NLMIXED

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Nested random effect in NLMIXED

Folks,

I want to fit a model in which the random effects are 'experiment' and 'block(experiment)'  in NLMIXED. Since NLMIXED does not accept two random statements, it is possible to do it in one. However, the challenge is the nesting. In the Littell 2006 book they describe it briefly, but I am not sure how to apply here.

Could anyone please help me with that? There are some parts of the code below that are completely wrong and I am not sure how to fix it;

Thanks a lot!

Marcio

%let nexp = 7214  ;

%let nblock = 39;

data growth;

do exp = 1 to &nexp;

err1 = 3*rannor(339205); *No idea what is this;

do block = 1 to &nblock;

err2 = 2*rannor(0);

ADG12M = 970 + err1 + err2 ;  *No idea what is this;

output;

end;

end;

end;

run;

proc nlmixed data=growth start ;                                                                                    

  title2 'Linear broken line';                                                                                                   

  bounds .145<R<.245;

  array aeffect { 1 };

    array beffect {&nblock };

  parms L= 970  U=-1000 R=.20 .21 s2e=100 1071 2000 ;                                                                                       

  z1=(x<R)*(R-x);       

  mean = L + U *(z1) + expffect{1} + blockeffect{B};

  model ADG12M ~ normal(mean, s2e);                                                                                              

    random eeff beff ~ Normal([0,0], [expvar, 0, blockvar]) subject=exp   out=blups;                               

  predict L + U*(z1) out=ppp;

run;


Accepted Solutions
Solution
‎11-10-2014 07:48 AM
Contributor
Posts: 45

Re: Nested random effect in NLMIXED

Steve, thanks a lot for the help! I was not able to update my sas right now. But I got it using the code below,

Thanks,

Marcio

proc nlmixed data=dataname start hess corr cov itdetails df=18;

array eeffect { 1 }; 

    array beffect { 6 }; 

  parms b0=190 b1=[.define all parms..]

    mean = b0 + b1*x + b2*x*x + eeffect{1} + beffect{block};

  model y ~ normal(mean, s2e);                                                                                              

    random eeffect1 beffect1 beffect2 beffect3 beffect4 beffect5 beffect6  ~

    Normal([0,0,0,0,0,0,0],

    [expvar,

    0, b_evar,

    0,0, b_evar,

    0,0,0, b_evar,

    0,0,0,0, b_evar,

    0,0,0,0,0, b_evar,

    0,0,0,0,0,0, b_evar]) subject=exp out=blups; *;                                                            

  predict b0 + b1*x + b2*x*x out=ppp;

run;

View solution in original post


All Replies
Respected Advisor
Posts: 2,655

Re: Nested random effect in NLMIXED

Hey Marcio,

I'll attack the data generation part first.  The first "no idea" generates a random normal, using a seed of 339205.  It could be anything for the seed, and it is older code.  Newer syntax would use rand('NORMAL') to generate a mean=0, sd=1 value.  It's multiplied by 3 to give the residual error variance component as 9 times the block variance component.  The second (ADGM12=) adds a fixed value (970) for the mean to the two values to give the dependent variable.

In the NLMIXED code, it looks like there are some undefined variables in the parms statement.  Something should be set equal to 1071 and something else to 2000 as starting values. In addition eeff and beff should be linked into expleffect and blockeffect somehow, and expvar and blockvar also defined (these latter two might be the missing parts in the parms statement).

Hope this helps you get started.

Steve Denham

Respected Advisor
Posts: 2,655

Re: Nested random effect in NLMIXED

Marcio,

What version of SAS/STAT are you using?  If you have SAS/STAT13.2 access, all of this can be handled directly now.  If you have 13.2, take a look at Example 70.7 Overdispersion Hierarchical Nonlinear Mixed Model.

Hope you have it (or can get upgrade).

Steve Denham

Solution
‎11-10-2014 07:48 AM
Contributor
Posts: 45

Re: Nested random effect in NLMIXED

Steve, thanks a lot for the help! I was not able to update my sas right now. But I got it using the code below,

Thanks,

Marcio

proc nlmixed data=dataname start hess corr cov itdetails df=18;

array eeffect { 1 }; 

    array beffect { 6 }; 

  parms b0=190 b1=[.define all parms..]

    mean = b0 + b1*x + b2*x*x + eeffect{1} + beffect{block};

  model y ~ normal(mean, s2e);                                                                                              

    random eeffect1 beffect1 beffect2 beffect3 beffect4 beffect5 beffect6  ~

    Normal([0,0,0,0,0,0,0],

    [expvar,

    0, b_evar,

    0,0, b_evar,

    0,0,0, b_evar,

    0,0,0,0, b_evar,

    0,0,0,0,0, b_evar,

    0,0,0,0,0,0, b_evar]) subject=exp out=blups; *;                                                            

  predict b0 + b1*x + b2*x*x out=ppp;

run;

Respected Advisor
Posts: 2,655

Re: Nested random effect in NLMIXED

Cool!  Now I have code to steal, er, borrow.

Steve Denham

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 477 views
  • 3 likes
  • 2 in conversation