--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- name: log: C:\vhm812-data\5b_exact_log.txt log type: text opened on: 8 Feb 2016, 07:37:31 . . keep if age >=30 (162 observations deleted) . keep low ptl smoke . . *create a 2by2 table with chi2 . tab low ptl, chi | History of premature Low birth | labor weight | None One | Total -----------+----------------------+---------- 0 | 19 4 | 23 1 | 2 2 | 4 -----------+----------------------+---------- Total | 21 6 | 27 Pearson chi2(1) = 2.0963 Pr = 0.148 . . *2by2 with Fisher's exact . tab low ptl, exact | History of premature Low birth | labor weight | None One | Total -----------+----------------------+---------- 0 | 19 4 | 23 1 | 2 2 | 4 -----------+----------------------+---------- Total | 21 6 | 27 Fisher's exact = 0.204 1-sided Fisher's exact = 0.204 . . *binomial coefficient-factorial . di(comb(21,2)*comb(6,2))/comb(27,4) .17948718 . . *hypergeometric distribution . di hypergeometricp(27,6,4,2) .17948718 . . *same as Fisher's exact test . exlogistic low ptl Enumerating sample-space combinations: observation 1: enumerations = 2 observation 2: enumerations = 3 observation 3: enumerations = 6 observation 4: enumerations = 9 observation 5: enumerations = 11 observation 6: enumerations = 13 observation 7: enumerations = 14 observation 8: enumerations = 14 observation 9: enumerations = 14 observation 10: enumerations = 15 observation 11: enumerations = 15 observation 12: enumerations = 15 observation 13: enumerations = 15 observation 14: enumerations = 15 observation 15: enumerations = 15 observation 16: enumerations = 15 observation 17: enumerations = 15 observation 18: enumerations = 15 observation 19: enumerations = 15 observation 20: enumerations = 15 observation 21: enumerations = 15 observation 22: enumerations = 15 observation 23: enumerations = 15 observation 24: enumerations = 14 observation 25: enumerations = 12 observation 26: enumerations = 9 observation 27: enumerations = 5 Exact logistic regression Number of obs = 27 Model score = 2.018634 Pr >= score = 0.2043 --------------------------------------------------------------------------- low | Odds Ratio Suff. 2*Pr(Suff.) [95% Conf. Interval] -------------+------------------------------------------------------------- ptl | 4.402267 2 0.4085 .2507705 79.01123 --------------------------------------------------------------------------- . . *logistic . logistic low ptl Logistic regression Number of obs = 27 LR chi2(1) = 1.81 Prob > chi2 = 0.1791 Log likelihood = -10.423421 Pseudo R2 = 0.0797 ------------------------------------------------------------------------------ low | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ptl | 4.75 5.421312 1.37 0.172 .5072157 44.48304 _cons | .1052632 .0782518 -3.03 0.002 .0245188 .4519108 ------------------------------------------------------------------------------ . . *logistic with robust SE . logistic low ptl, robust Logistic regression Number of obs = 27 Wald chi2(1) = 1.79 Prob > chi2 = 0.1803 Log pseudolikelihood = -10.423421 Pseudo R2 = 0.0797 ------------------------------------------------------------------------------ | Robust low | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ptl | 4.75 5.524584 1.34 0.180 .486056 46.41955 _cons | .1052632 .0797424 -2.97 0.003 .0238477 .4646294 ------------------------------------------------------------------------------ . . *show problem with perfect prediction . *create a 2by2 table with chi2 . tab low smoke, chi | Smoking status during Low birth | pregnancy weight | no yes | Total -----------+----------------------+---------- 0 | 17 6 | 23 1 | 0 4 | 4 -----------+----------------------+---------- Total | 17 10 | 27 Pearson chi2(1) = 7.9826 Pr = 0.005 . exlogistic low smoke Enumerating sample-space combinations: observation 1: enumerations = 2 observation 2: enumerations = 3 observation 3: enumerations = 4 observation 4: enumerations = 5 observation 5: enumerations = 9 observation 6: enumerations = 12 observation 7: enumerations = 14 observation 8: enumerations = 15 observation 9: enumerations = 15 observation 10: enumerations = 15 observation 11: enumerations = 15 observation 12: enumerations = 15 observation 13: enumerations = 15 observation 14: enumerations = 15 observation 15: enumerations = 15 observation 16: enumerations = 15 observation 17: enumerations = 15 observation 18: enumerations = 15 observation 19: enumerations = 15 observation 20: enumerations = 15 observation 21: enumerations = 15 observation 22: enumerations = 15 observation 23: enumerations = 15 observation 24: enumerations = 14 observation 25: enumerations = 12 observation 26: enumerations = 9 observation 27: enumerations = 5 note: CMLE estimate for smoke is +inf; computing MUE Exact logistic regression Number of obs = 27 Model score = 7.686957 Pr >= score = 0.0120 --------------------------------------------------------------------------- low | Odds Ratio Suff. 2*Pr(Suff.) [95% Conf. Interval] -------------+------------------------------------------------------------- smoke | 12.30305* 4 0.0239 1.361276 +Inf --------------------------------------------------------------------------- (*) median unbiased estimates (MUE) . logistic low smoke note: smoke != 1 predicts failure perfectly smoke dropped and 17 obs not used Logistic regression Number of obs = 10 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -6.7301167 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ low | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- smoke | 1 (omitted) _cons | .6666667 .4303315 -0.63 0.530 .1881311 2.362419 ------------------------------------------------------------------------------ . . ******************************************* . * Example from VER book . ******************************************* . clear . set memory 500m set memory ignored. Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically. . use nocardia.dta . xi:exlogistic casecont i.dneo*dclox , condvars(dcpct) estc coef memory(500m) nolog i.dneo _Idneo_0-1 (naturally coded; _Idneo_0 omitted) i.dneo*dclox _IdneXdclox_# (coded as above) Exact logistic regression Number of obs = 108 --------------------------------------------------------------------------- casecont | Coef. Suff. 2*Pr(Suff.) [95% Conf. Interval] -------------+------------------------------------------------------------- _Idneo_1 | 3.079451 49 0.0000 1.411797 5.425363 dclox | .4277257 8 1.0000 -1.968834 3.113536 _IdneXdclo~1 | -2.424265 5 0.1021 -5.469863 .3647573 _cons | -3.580348 54 0.0000 -6.232561 -1.662305 --------------------------------------------------------------------------- . xi:exlogistic casecont i.dneo dclox , condvars(dcpct) estc coef memory(500m) nolog i.dneo _Idneo_0-1 (naturally coded; _Idneo_0 omitted) Exact logistic regression Number of obs = 108 --------------------------------------------------------------------------- casecont | Coef. Suff. 2*Pr(Suff.) [95% Conf. Interval] -------------+------------------------------------------------------------- _Idneo_1 | 2.130762 49 0.0001 .9483869 3.503259 dclox | -1.374472 8 0.0203 -2.631807 -.1890695 _cons | -2.812699 54 0.0000 -4.662363 -1.300788 --------------------------------------------------------------------------- . logit casecont dcpct i.dneo##i.dclox , robust Iteration 0: log pseudolikelihood = -74.859896 Iteration 1: log pseudolikelihood = -52.23958 Iteration 2: log pseudolikelihood = -51.712191 Iteration 3: log pseudolikelihood = -51.70842 Iteration 4: log pseudolikelihood = -51.708419 Logistic regression Number of obs = 108 Wald chi2(4) = 23.22 Prob > chi2 = 0.0001 Log pseudolikelihood = -51.708419 Pseudo R2 = 0.3093 ------------------------------------------------------------------------------ | Robust casecont | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- dcpct | .0226175 .0081559 2.77 0.006 .0066323 .0386028 | dneo | yes | 3.184002 .8989331 3.54 0.000 1.422125 4.945878 | dclox | yes | .4457043 1.048054 0.43 0.671 -1.608443 2.499852 | dneo#dclox | yes#yes | -2.551997 1.254033 -2.04 0.042 -5.009857 -.0941365 | _cons | -3.776896 1.183989 -3.19 0.001 -6.097471 -1.45632 ------------------------------------------------------------------------------ . logit casecont dcpct i.dneo##i.dclox Iteration 0: log likelihood = -74.859896 Iteration 1: log likelihood = -52.23958 Iteration 2: log likelihood = -51.712191 Iteration 3: log likelihood = -51.70842 Iteration 4: log likelihood = -51.708419 Logistic regression Number of obs = 108 LR chi2(4) = 46.30 Prob > chi2 = 0.0000 Log likelihood = -51.708419 Pseudo R2 = 0.3093 ------------------------------------------------------------------------------ casecont | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- dcpct | .0226175 .0077233 2.93 0.003 .0074802 .0377549 | dneo | yes | 3.184002 .8372021 3.80 0.000 1.543116 4.824888 | dclox | yes | .4457043 1.026029 0.43 0.664 -1.565275 2.456683 | dneo#dclox | yes#yes | -2.551997 1.205077 -2.12 0.034 -4.913904 -.190089 | _cons | -3.776896 .9932539 -3.80 0.000 -5.723638 -1.830154 ------------------------------------------------------------------------------ . end of do-file . exit, clear