/*--------------------------------------------------------------------------------------------------- MACRO COVPARMS Written by: Edward Vonesh Date: September 20, 2009 Purpose: Creates a SAS dataset that contains parameter starting values for nonlinear mixed-effects models with random effects. This macro appends OLS-based parameter estimates from NLMIXED when one has random effects with all variance-covariance parameters set to 0 (see example below) and one creates a ParameterEstimates dataset (from ODS Output) that contains all fixed effects parameters and within-subject variance parameters. Specifically, it takes an output dataset from the PREDICT statement in NLMIXED that contains the derivatives of the random effects evaluated at the final OLS estimates from NLMIXED and obtains estimated variances and covariances of the random effects and amends these estimates to those of the fixed-effects in a final dataset defined by OUTPUT=. To successfully run this macro one MUST 1. Specify a PREDICT statement in an initial call to NLMIXED that will contain the estimate residuals from a least squares (LS) fit to the data in which random effects, although specified initially, are ignored because their variances and covariances are all set equal to 0. This PREDICT statement must include the option DER when specified. 2. Specify an ODS output statement containing the initial NLMIXEd results one obtains when essentially running a model with no random-effects despite the requirement that one actuall does specify the random effects that one wishes to incorporate into the model (see example below). This statement is of the form ODS Output ParameterEstimates='name'. Output: The program will print out the initial estimated random-effects variance-covariance matrix as well as initial estimates of the correlations of the random effects (useful for deciding whether to include or exclude one or more random effects in the final model). It will also print out the dataset containing all initial starting values of the parameters one is attempting to fit with NLMIXED. One can edit and delete parameters from the dataset to increase the speed at which NLMIXED converges based on reasonable starting values. Details: This macro computes approximate starting values for the variance-covariance matrix of the random effects for nonlinear mixed-effects models in NLMIXED. One must run NLMIXED with the desired random effects specified in the model but with all values within the RANDOM statement set to 0 so that NLMIXED is performing an OLS analysis. One must also specify the PREDICT= statement in NLMIXED such that the output dataset contains the residual values from the nonlinear function (i.e., resid=response-predicted where predicted is the predicted response from each observation and response is the response variable specified in the MODEL statement of NLMIXED). KEY: PARMS= -Defines a SAS dataset defined by ODS Output ParameterEstimates='name' that contains OLS parameter estimates from NLMIXED when all random effect variance-covariance parameters are set equal to 0 PREDOUT= -Defines a SAS dataset containing residual values from an initial call to NLMIXED that are defined by an ID statement in combination with the PREDICT 'expression' OUT='dataset name' from the initial call to NLMIXED. RESID= -Defines the name of the variable that is the residual (y-yhat) from NLMIXED. It must be defined within the initial call to NLMIXED and placed in an ID statement so that it will be included in the dataset METHOD= -Defines what method one wishes to use to estimate the random effect variance-covariance parameters to be estimated in NLMIXED RANDOM= -Defines the variables having prefix 'Der_' created by NLMIXED corresponding to the dataset specified by the DATA= statement above. These are the random effect derivatives to be used in PROC MIXED as a means to compute the variance-covariance parameters from a first-order approximation. SUBJECT= -Defines a SUBJECT variable needed in MIXED. This should be the same SUBJECT variable used in the initial call to NLMIXED TYPE= -Defines the type of random-effects variance-covariance matrix (typically UN or VC) COVNAME= -Defines a prefix name to be used for the character variable, Parameter, that exits within the dataset defined by PARMS above. This prefix is then used in the creation of values for Parameter that specify starting values for the random-effects variance-covariance parameters. OUTPUT= -Defines a SAS dataset, say 'outname' that is to contain all of the parameters to be used in a call to NLMIXED using the PARMS / data='outname' statement. This dataset will include the OLS regression parameter estimates in the dataset specified by PARMS= statement above as well as the variance-covariance parameter estimates from this macro having the prefix defined by the COVNAME= option above. -----------------------------------------------------------------------------------------------------*/ %macro covparms(parms=, predout=, resid=resid, method=ml, random=der_u1 der_u2 der_u3, subject=subject, type=un, covname=psi, output=parms); %let random=%qupcase(&random); %let type=%qupcase(&type); ods listing close; ods output covparms=covparms082152; ods output gcorr=gcorr; ods output g=g; proc mixed data=&predout method=ml covtest; class &subject; model &resid = ; random &random / subject=&subject type=&type g gcorr; run; ods listing; proc print data=g; run; proc print data=gcorr; run; proc print data=covparms082152; run; data covparms082152; set covparms082152; if scan(CovParm,1)='UN' then do; i=scan(CovParm,2); j=scan(CovParm,3); p082152a="&covname"; p082152b=p082152a||compress(left(i))||compress(left(j)); Parameter=compress(left(p082152b)); end; else if scan(CovParm, 1, '_')='Der' then do; i=scan(CovParm, 2, '_'); j=' '; p082152a="&covname"; p082152b=p082152a||compress(left(i))||compress(left(j)); Parameter=compress(left(p082152b)); end; else delete; keep Parameter Estimate; run; proc print;run; data &output; set &parms covparms082152; run; proc print data=&output; run; %mend covparms;