/*------------------------------------------------------------------* | MACRO NAME : nesttest | SHORT DESC : Likelihood ratio test for logistic or proportional | hazards models *------------------------------------------------------------------* | CREATED BY : Lennon, Ryan (06/26/2006 15:33) *------------------------------------------------------------------* | PURPOSE | | This program will produce a likelihood ratio test for the comparison | of two nested models. The models may be logistic regression or Cox | proportional hazards models. *------------------------------------------------------------------* | MODIFIED BY : Lennon, Ryan (03/24/2009 8:46) | | 1. Changed input data set parameter from DS to DATA | 2. Allow user to name the output data set | 3. Macro only uses 2 footnotes, instead of 3 *------------------------------------------------------------------* | OPERATING SYSTEM COMPATIBILITY | | UNIX SAS v8 : YES | UNIX SAS v9 : YES | MVS SAS v8 : | MVS SAS v9 : | PC SAS v8 : | PC SAS v9 : *------------------------------------------------------------------* | MACRO CALL | | %nesttest( | DATA= , | event= , | time= , | e_val= , | x1= , | x2= , | fam= , | OUT=_test_, | noprint=1, | DS= | ); *------------------------------------------------------------------* | REQUIRED PARAMETERS | | Name : DATA | Default : | Type : Dataset Name | Purpose : Input data set name | | Name : event | Default : | Type : Variable Name (Single) | Purpose : The event indicator variable, must be numeric | | Name : time | Default : | Type : Variable Name (Single) | Purpose : The time to event variable (Only required if FAM=COX), must be numeric | | Name : e_val | Default : | Type : Number (Single) | Purpose : The value of EVENT which indicates an event has occurred. Due to | this, only binary logistic modelling is possible. | | Name : x1 | Default : | Type : Variable Name (List) | Purpose : Explanatory variables to be found in both models. Must be numeric. | | Name : x2 | Default : | Type : Variable Name (List) | Purpose : Explanatory variable found in only the large model. Must be numeric. | So | Model 1: Y = X1 | Model 2: Y = X1 X2 | The macro tests the significance of the partial effect (given X1) | of the X2 variables. | | Name : fam | Default : | Type : Text | Purpose : BIN = Do logistic regression (binary) | COX = Do Cox PH regression | *------------------------------------------------------------------* | OPTIONAL PARAMETERS | | Name : OUT | Default : _test_ | Type : Dataset Name | Purpose : Name of output data set containing results | | Name : noprint | Default : 1 | Type : Number (Single) | Purpose : 1=Do not print output from LOGISTIC/PHREG (default) | 0=Print LOGISTIC/PHREG output | | Name : DS | Default : | Type : Dataset Name | Purpose : The input data set. This parameter retained only for functionality | with previous programs. If both DATA and DS are specified, the DS | parameter is ignored. | *------------------------------------------------------------------* | RETURNED INFORMATION | | The returned output is a PROC PRINT with the Model1 and Model 2 | parameter estimates and p-values given for all explanatory variables. | The last line has the -2 log likelihood values for both models, their | difference, the degrees of freedom, and resulting p-value. | *------------------------------------------------------------------* | ADDITIONAL NOTES | | 1. Data sets created: _tmp_ _est1 _est2 __est1 __est2 _temp_ _F &OUT. | 2. Data sets deleted: _tmp_ _est1 _est2 __est1 __est2 _temp_ _F. | | *------------------------------------------------------------------* | EXAMPLES | | | data a; | do i=1 to 1000; | var1=normal(0); | var2=normal(0); | var3=normal(0); | P_e = (1/(1 + 1/(exp(-1 + var1 + 2*var2)))); | Y1 = ranbin(0,1,p_e); | T = -log(ranuni(0))/exp(var2 + 2*var3); | C = -log(ranuni(0)); | time=min(t,c); | event=(t<=c); | output; | end; | run; | | title1 'Nested Cox PH models'; | %nesttest(data=a, event=event, time=time, e_val=1, | x1=var1 var3, x2=var2, fam=cox, noprint=0); | | title1 'Nested Logistic Regression Models'; | %nesttest(data=a, event=Y1, e_val=1, | x1=var1 var3, x2=var2, out=ntout, fam=bin, noprint=1); | | | *------------------------------------------------------------------* | REFERENCES | | Casella, G and RL Berger, Statistical Inference, Wadsworth Inc., | Belmont 1990. | *------------------------------------------------------------------* | Copyright 2009 Mayo Clinic College of Medicine. | | This program is free software; you can redistribute it and/or | modify it under the terms of the GNU General Public License as | published by the Free Software Foundation; either version 2 of | the License, or (at your option) any later version. | | This program is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | General Public License for more details. *------------------------------------------------------------------*/ %MACRO NESTTEST(data=, event=, time=, x1=, x2=, e_val=, fam=, noprint=1, out=_test_, ds=); %LOCAL ERRORFLG I XV1 J XV2 XV NN NE RM NOBS F FPLUS1 IP2; %LET ERRORFLG=0; %IF (&DATA= ) & (&DS= ) %THEN %DO; %PUT "ERROR - No input data set identified in DATA parameter. Macro will stop executing."; %LET ERRORFLG=1; %END; %ELSE %IF (&DATA^= ) & (&DS^= ) & (%UPCASE(&DATA)^=%UPCASE(&DS)) %THEN %PUT WARNING: Different input data sets were identified by the DATA and DS input parameters. Data set &DATA (DATA) will be used.; %IF (&DATA= ) %THEN %LET DATA=&DS; %IF %upcase(&FAM)=COX and &TIME= %THEN %DO; %PUT ERROR - Variable