* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * File: logistic1.SPS . * Date: 18-Jan-2002 . * Author: Bruce Weaver, weaverb@mcmaster.ca . * Notes: Demonstration binary logistic regression . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * This syntax performs the chi-square test of association for the screwdriver experiment described in my notes on categorical data (URL given below). * http://www.angelfire.com/wv/bwhomedir/notes/categorical.doc . * It then shows how you could analyze the same data using binary logistic regression rather than CROSSTABS . * The "change in -2 log likelihood" chi-square test from the logistic regression is identical to the Likelihood Ratio Chi-square produced by CROSSTABS. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * First approach using individual data . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Generate the data file with an input program . new file. input program. loop #i = 1 to 90. compute case = $casenum. do if range(case,1,9). compute a = 1. compute b = 1. else if range(case,10,26). compute a = 2. compute b = 1. else if range(case,27,48). compute a = 3. compute b = 1. else if range(case,49,69). compute a = 1. compute b = 2. else if range(case,70,82). compute a = 2. compute b = 2. else. compute a = 3. compute b = 2. end if. end case. end loop. end file. end input program. exe. formats case a b (f5.0). val lab a 1 'No instructions' 2 'Common uses' 3 'Uncommon uses' / b 1 'Solve' 2 'Fail to solve' . crosstabs b by a /cells = count exp /stat = chisq. * Note that both Pearson's chi-square and the Likelihood Ratio chi-square are identical to the values reported in the notes. * The Linear-by-Linear Association test is sometimes * reported if both of your categorical variables are * ordinal. The following website has more info about it, * for anyone who is interested: * http://www.uvm.edu/~dhowell/StatPages/More_Stuff/OrdinalChisq/OrdinalChiSq.html . * ------------------------------------------------ . * Analyzing the same data with logistic regression. * ------------------------------------------------ . * We could have used logistic regression to analyze these data. * You can find it in the pull-down menus under: * Analyze->Regression->Binary logistic. * Enter B as the dependent variable, and A as the covariate. * A is a categorical variable, so click on the Categorical button, * and move A into the Categorical variables box. * I also clicked on options, and put a check by CI for Exp(B). * This requests display of the 95% CI for the odds ratios, which * you may not know about yet--but it's convenient to have this displayed. * Here's the syntax I generated by clicking on PASTE . LOGISTIC REGRESSION VAR=b /METHOD=ENTER a /CONTRAST (a)=Indicator /PRINT=CI(95) /CRITERIA PIN(.05) POUT(.10) ITERATE(20) CUT(.5) . * In the output, notice that before variable A is entered into the model, the -2 Log Likelihood = 124.3662. * -2 Log Likelihood (-2LL) for a logistic regression model is similar to R-squared for a linear regression model insofar as it is an index of how well the model fits; but one difference is that SMALLER values of -2 LL reflect better fit (as opposed to LARGER values of R-squared). * Also notice that AFTER variable A has been entered, -2 LL has dropped to 112.501; the change in -2LL = 124.3622 - 112.501 = 11.866, which is shown as a chi-square test with df=2; this is because change in -2LL (from one model to another) is approximately distributed as a chi-square with df = the difference in the number of parameters for the 2 models; variable A has 3 levels, so two variables are required for its coding. * Finally, notice that this "change in -2LL" chi-square is identical to the likelihood ratio chi-square statistic we obtained earlier using the CROSSTABS procedure . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Second approach using the 6 cell counts and WEIGHT cases . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . DATA LIST LIST /a (f2.0) b (f2.0) count(f5.0) . BEGIN DATA. 1 1 9 2 1 17 3 1 22 1 2 21 2 2 13 3 2 8 END DATA. val lab a 1 'No instructions' 2 'Common uses' 3 'Uncommon uses' / b 1 'Solve' 2 'Fail to solve' . weight by count. crosstabs b by a /cells = count exp /stat = chisq. * Logistic regression works with cell counts and WEIGHT CASES too. LOGISTIC REGRESSION VAR=b /METHOD=ENTER a /CONTRAST (a)=Indicator /PRINT=CI(95) /CRITERIA PIN(.05) POUT(.10) ITERATE(20) CUT(.5) . * Finished. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .