Do all univariate linear and logistic regressions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ Purpose of the macros: to perform automatically all univariate regressions for one, or more, dependent variables and a lot of independent variables. They are useful if you have a lot of predictors, and don't fell like "Copy-Paste" the syntax several times. Marta **************************************************************************** * 'Do All Univariate Regressions' MACROS, for linear and logistic regression ****************************************************************************. * Sample data for both MACROS. INPUT PROGRAM. - VECTOR V(20). - LOOP #I = 1 TO 100. - LOOP #J = 1 TO 20. - COMPUTE V(#J) = NORMAL(1). - END LOOP. - END CASE. - END LOOP. - END FILE. END INPUT PROGRAM. execute. * Let's consider that the first 3 variables are the dependent, * and the last 17 are the independent. * For both MACROS, the dependents' names should be: y1, y2, .... * and the independents': x1, x2, x3..... * So, we are going to RENAME them. RENAME VARIABLES (v1 to v3 = y1 to y3). RENAME VARIABLES (v4 to v20 = x1 to x17). * (the variables must be consecutive in the database * in order to make these two commands work). ********************************************************************. * (1) Linear regression. * MACRO definition. DEFINE lirdoall(!POSITIONAL !TOKENS(1) /!POSITIONAL !TOKENS(1)) DO IF $CASENUM=1. !DO !i=1 !to !1. !LET !yvar=!concat('y', !i). !DO !j=1 !to !2. !LET !xvar=!concat('x', !j). WRITE OUTFILE "c:\\windows\\temp\\alltests.sps" /"REGRESSION" /" /DESCRIPTIVES MEAN STDDEV" /" /STATISTICS COEFF CI R ANOVA" /" /DEPENDENT "!quote(!yvar) /" /METHOD=ENTER " !quote(!xvar) " .". * I have selected some descriptives&statistics, * modify them if needed, but be careful with the / and " . !DOEND. !DOEND. END IF. EXECUTE. INCLUDE FILE="c:\\windows\\temp\\alltests.sps". !ENDDEFINE. * MACRO call: macroname 'number of dependent' 'number of independent'. * The following call will create&run a syntax file that performs * 3x17=51 regressions. SET MPRINT=yes. LIRDOALL 3 17. SET MPRINT=no. ********************************************************************. * (2) Logistic Regression. * MACRO definition. DEFINE lordoall(!POSITIONAL !TOKENS(1) /!POSITIONAL !TOKENS(1)) DO IF $CASENUM=1. !DO !i=1 !to !1. !LET !yvar=!concat('y', !i). !DO !j=1 !to !2. !LET !xvar=!concat('x', !j). WRITE OUTFILE "c:\\windows\\temp\\alltests.sps" /"LOGISTIC REGRESSION VAR="!quote(!yvar) /" /METHOD=ENTER " !quote(!xvar) /" /PRINT=GOODFIT CI(95) .". * I have selected some statistics, * modify them if needed, but be careful with the / and " . !DOEND. !DOEND. END IF. EXECUTE. INCLUDE FILE="c:\\windows\\temp\\alltests.sps". !ENDDEFINE. * First, we need binary dependents for the example. RECODE y1 TO y3 (Lowest thru 0.501=0) (0.501 thru Highest=1) . VALUE LABELS y1 TO y3 0 'No' 1 'Yes'. EXECUTE . * MACRO call: macroname 'number of dependent' 'number of independent'. * The following call will create&run a syntax file that performs * 3x17=51 regressions. LORDOALL 3 17. |
Related pages
...