Programming the statistical procedures from SAS

NLMIXED Error

Reply
New Contributor
Posts: 3

NLMIXED Error

 

I'm new to SAS (using UE), just learning it for a specific analysis of NHANES dietary data. I copied code from the NHANES website for the BRR203 macro and downloaded MIXTRAN and DISTRIB from the NCI website. When I run the code, I get the following error:

 

ERROR: QUANEW Optimization cannot be completed.

NOTE: Optimization routine cannot improve the function value.

 

I believe everything is sorted correctly, so I'm not sure where my error is. Any suggestions would be great! Let me know if more information is needed. The dataset I'm using is attached. Here is the code (MIXTRAN code is pasted below as well):

 

%macro BRR203 (data, response, foodtype, subject, repeat, covars_prob, covars_amt,
outlib, pred, param, modeltype, lambda, seq, weekend, vargroup, numvargroups,
subgroup, vcontrol, nloptions, titles, printlevel,
cutpts, ncutpts, nsim_mc, byvar, final);

%MIXTRAN (data=&data, response=&response, foodtype=&foodtype, subject=&subject, repeat=&repeat,
outlib=&outlib, modeltype=&modeltype, lambda=&lambda, replicate_var=weightint, weekend=&weekend, subgroup=&subgroup,
nloptions=&nloptions, titles=&titles, printlevel=&printlevel)

%DISTRIB (seed=0, nsim_mc=&nsim_mc, modeltype=&modeltype, pred=&pred, param=&param, outlib=&outlib, cutpoints=&cutpts,
ncutpnt=&ncutpts, byvar=&byvar, subgroup=&subgroup, subject=&subject, titles=&titles, food=&foodtype) ;

data dist;
set &outlib..descript_&foodtype._weightint;
mergeby=1;
keep &subgroup mergeby numsubjects
mean_mc_t tpercentile1-tpercentile99
cutprob1-cutprob&&ncutpts. mergeby;
run;

%do run=1 %to 16;

%put ~~~~~~~~~~~~~~~~~~~ Run &run ~~~~~~~~~~~~~~~~~~~~;

%MIXTRAN (data=&data, response=&response, foodtype=&foodtype, subject=&subject, repeat=&repeat, outlib=&outlib,
modeltype=&modeltype, lambda=&lambda, replicate_var=RepWt_&run, weekend=&weekend,
nloptions=&nloptions, titles=&titles, printlevel=&printlevel);


%DISTRIB (seed=0, nsim_mc=&nsim_mc, modeltype=&modeltype, pred=&pred, param=&param, outlib=&outlib,
cutpoints=&cutpts, ncutpnt=&ncutpts, byvar=&byvar, subgroup=&subgroup, subject=&subject,
titles=&titles, food=&foodtype);

data=distbrr;
set &outlib..descript_&foodtype._RepWt_&run;
rename numsubjects=bnumsubjects
mean_mc_t=bmean_mc_t tpercentile1-tpercentile99=btpercentile1-btpercentile99

cutprob1-cutprob&&ncutpts. =bcutprob1-bcutprob&&ncutpts.;

run=&run;

mergeby=1;

data distbrr;
set distbrr;
keep &subgroup bnumsubjects bmean_mc_t
btpercentile1-btpercentile99
bcutprob1-bcutprob&&ncutpts.mergeby;
run;

proc append base=brr_runs data=distbrr;
run;

proc datasets nolist; delete distbrr;
run;
%end;

proc sort data=dist; by &subgroup
mergeby;

proc sort data=brr_runs; by &subgroup
mergeby;

data distall;
merge dist brr_runs; by &subgroup
mergeby;

array bvar (*) bmean_mc_t btpercentile1-btpercentile99 bcutprob1-bcutprob&&ncutpts.;

array varo (*) mean_mc_t tpercentile1-tpercentile99 cutprobs1-cutprob&&ncutpts.;

array dsqr (*) dbmean_mc_t dbtpercentile1-dbtpercentile99 dbcutprob1-dbcutprob&&ncutpts.;

do i=i to dim(bvar);
dsqr[i]=(bvar[i]-varo[i])**2;
end;
run;

proc means data=distall sum; by &subgroup mergeby;
var dbmean_mc_t dbtpercentile1-dbtpercentile99 dbcutprob1-dbcutprob&&ncutpts.;
output out=sums sum= sum_dbmean_mc_t
sum_dbtpercentile1-sum_dbtpercentile99
sum_dbcutprob1-sum_dbcutprob&&ncutpts.;
run;

data brr;
set sums;
array sumt (*) sum_dbmeans_mc_t
sum_dbtpercentile1-sum_dbtpercentile99
sum_dbcutprob1-sum_dbcutprob&&ncutpts.;
array se (*) se_mean_mc_t
se_tpercentile1-se_tpercentile99
se_cutprob1-se_cutprob&&ncutpts.;
do j=1 to dim(sumt);
se[j]=-1*sqrt((sumt[j])/(16*.49));
end;
mergeby=1;
keep se_mean_mc_t se_tpercentile1-se_tpercentile99 se_cutprob1-se_cutprob&&ncutpts. &subgroup mergeby;
run;

data toprint1;
set dist;
line=1;
keep &subgroup numsubjects mean_mc_t tpercentile1-tpercentile99 cutprob1-cutprob&&ncutpts. line;

data toprint2;
set brr;
line=2;
keep &subgroup mean_mc_t tpercentile1-tpercentile99
cutprob1-cutprob&&ncutpts. line;
run;

data &final;
set toprint1 toprint2;
run;

proc sort data=&final;
by &subgroup line;
run;

proc print data=&final split=' ' noobs;
var &subgroup line tpercentile5 tpercentile10 tpercentile25
tpercentile50 tpercentile75 tpercentile90 tpercentile95;
format line line. mean_mc_t
tpercentile1-tpercentile99 negparen10.1
cutprob1-cutprob&&ncutpts. negparen6.2;
title 'Usual Intake of LRB Calorise';
title2 'NHANES 2013-14';
run;

%mend BRR203;


%BRR203 (data=repwts, response=LRBCALS, foodtype=LRBCalories, subject=SEQN,
repeat=Day, seq=, covars_amt=, weekend=weekend, outlib=work, pred=work._pred_LRBCalories,
param=work._param_LRBCalories, modeltype=corr, lambda=.4, nloptions=qmax=61, titles=1, printlevel=2, cutpts=500 1000 1500,
ncutpts=3, nsim_mc=100, final=nh.m20task1);
run;

 

 

Here is the segment of the MIXTRAN code where the error is coming from:

/*---Fit Correlated Model---*/
1589
1590 title%eval(&titles+1) 'Correlated Model';
1591
1592 ods output ParameterEstimates=parmsf3 AdditionalEstimates=adprmsf3 FitStatistics=fitf3 ConvergenceStatus=convf3;
1593
1594 proc nlmixed data=data &nloptions;
1595 parms / data=&start_val3 ;
1596 &replicate ; /* If replicate variable supplied */
1597 &lambdabounds ;
1598
1599 %if &vargroup ne %STR() %then %do;
1600 ARRAY VARGRP[&NUMVGMINUS1] A_VARGRP2-A_VARGRP&NUMVARGROUPS;
1601 ARRAY A_DELTAVG[&numvgminus1] A_DELTAVG2-A_DELTAVG&numvargroups;
1602
1603 if &vargroup=1 then do;
1604 A_VARGRP1 = EXP(2*A_LOGSDE);
1605 A_VAR_E = A_VARGRP1;
1606 end;
1607 else do vg = 2 to &numvargroups;
1608 if &vargroup=vg then do;
1609 indx=vg-1;
1610 VARGRP[INDX] = EXP(2*(A_LOGSDE + A_DELTAVG[INDX]));
1611 A_VAR_E = VARGRP[INDX];
1612 end;
1613 end;
1614 %end;
1615 %else %do;
1616 A_VAR_E = EXP(2*A_LOGSDE);
1617 %end;
1618
1619 &vu1= EXP(2*P_LOGSDU1);
1620 &vu2= EXP(2*A_LOGSDU2);
1621 RHO=(EXP(2*Z_U) - 1) / (EXP(2*Z_U) + 1);
1622 COV_U1U2 = RHO*EXP(P_LOGSDU1+A_LOGSDU2);
1623
1624 x1b1u1=&eta1;
1625 p=exp(x1b1u1)/(1+exp(x1b1u1));
1626 llb=log((1-p)**(1-YN)) + log(p**(YN));
1627 x2b2u2=&eta2;
1628 pi=arcos(-1);
1629 E_int=x2b2u2;
1630 if &response>0 then do;
1631 %if (&lambdabounds eq %str()) %then %let amtlambda = λ /* user supplied lambda */
1632 %if &lambda ne %str(0) %then %do;
1633 boxcoxy=(&response**&amtlambda-1)/&amtlambda;
1634 %end; /* lambda ne 0 */
1635 %else %do;
1636 boxcoxy=log(&response) ;
1637 %end; /* lambda=0 */
1638 ll1=log(1/(sqrt(2*pi*A_VAR_E)));
1639 ll2=(-(boxcoxy-x2b2u2)**2)/(2*A_VAR_E)+(&amtlambda-1)*log(&response);
1640 ll_n=ll1+ll2;
1641 end; /* if &response>0... */
1642 if &response=0 then ll=llb;
1643 else if &response>0 then ll=llb+ll_n;
1644 model &response ~ general(ll);
1645 random u1 u2 ~ normal([0,0],[&vu1,COV_U1U2,&vu2]) subject=&subject out=rndm;
1646 estimate "P_VAR_U1" EXP(2*P_LOGSDU1);
1647 estimate "A_VAR_U2" EXP(2*A_LOGSDU2);
1648 %if &vargroup ne %STR() %THEN %DO;
1649 estimate "A_VARGRP1" EXP(2*A_LOGSDE);
1650 %let kvg = 2;
1651 %do kvg = 2 %to &NUMVARGROUPS;
1652 estimate "A_VARGRP&KVG" EXP(2*(A_LOGSDE + A_DELTAVG&KVG));
1653 %end;
1654 %end;
1655 %else %do;
1656 estimate "A_VAR_E" EXP(2*A_LOGSDE);
1657 %end;
1658 estimate "RHO" (EXP(2*Z_U) - 1) / (EXP(2*Z_U) + 1);
1659 estimate "COV_U1U2" RHO*EXP(P_LOGSDU1+A_LOGSDU2);
1660 x2b2=x2b2u2-u2;
1661 x1b1=x1b1u1-u1;
1662 predict p out=predp;
1663 predict e_int out=predeint;
1664 predict x2b2 out=predx2b2;
1665 predict x1b1 out=predx1b1;
1666 predict u1 out=_predu1;
1667 predict u2 out=_predu2;
1668 run;
1669 ** end of NLMIXED for correlations;
1670
1671 data _null_;
1672 set convf3;
1673 call symput('convcr',Reason);
1674 run;
1675
1676 /* check for convergence error. End processing if found */
1677 Data _null_ ;
1678 %let ccscr=%index(&convcr,convergence criterion satisfied) ;
1679 %if &ccscr=%str(0) %then %do ;
1680
1681 %put ****************************************************;
1682 %put ##! Convergence Problem from PROC NLMIXED ;
1683 %put ##! Macro MIXTRAN Stopped Due to Convergence Error in Correlated Model ;
1684 %put ##! Response Variable is &response ;
1685 %put ##! data is &data;
1686 %put ##! weight variable is &replicate_var;
1687 %put **ERROR** MSG: &convcr ;
1688 %put ****************************************************;
Attachment
Ask a Question
Discussion stats
  • 0 replies
  • 84 views
  • 0 likes
  • 1 in conversation