Separation-Resistant and Bias-Reduced Logistic Regression: STATISTICA Macro

Logistic regression is one of the most popular techniques used to describe the relationship between a binary dependent variable and a set of independent variables. However, the application of logistic regression to small data sets is often hindered by the complete or quasicomplete separation. Under the separation scenario, results obtained via maximum likelihood should not be trusted, since at least one parameter estimate diverges to infinity. Firth's approach to logistic regression is a theoretically sound procedure, which is guaranteed to arrive at finite estimates even in a separation case. Firth's procedure was also proved to significantly reduce the small sample bias of maximum likelihood estimates. The main goal of the paper is to introduce the STATISTICA macro, which performs Firth-type logistic regression.


Introduction 1.Logistic regression model
Logistic regression is a commonly used tool to describe the relationship between a binary outcome variable and a set of explanatory variables.It is routinely employed in many fields, e.g., medicine, social sciences, economics.The popularity of logistic regression stems mainly from its mathematical convenience and the relative ease of interpretation in terms of odds ratios (Hosmer and Lemeshow 2000;Long 1997;Greene 2003).
Assume that the dependent variable y i ∈ {0, 1} is a Bernoulli distributed variable with success probability F (x i θ), where F (•) is the logistic distribution function, x i is a p-dimensional vector of explanatory variables and θ ∈ R p is a p-dimensional parameter vector (i = 1, . . ., n).The most frequently used estimation method of θ is the maximum likelihood estimation (MLE).The MLE principle states that the estimate of θ is the value which maximizes the likelihood function (Hosmer and Lemeshow 2000).The likelihood function and its logarithm in case of logistic regression are given by the following equations: In order to find the value of θ that maximizes L(θ), partial derivatives of a log-likelihood function with respect to θ are calculated: The solution to score equations U (θ) = 0 gives the ML estimate of θ, i.e., θ.
In most cases, there is no analytical solution to score equations.Consequently, numerical methods are used to find θ.With starting value θ (1) , the maximum likelihood estimate θ is obtained iteratively: where the superscript (r) refers to the r-th iteration and I θ denotes the Fisher information matrix evaluated at θ (Greene 2003): The desirable properties of ML estimates such as: consistency, efficiency and normality, are based on the assumption that the sample size (n) approaches infinity.However in many real life situations the large sample assumption is not satisfied, and as a result, ML estimates should not be trusted.
The bias of ML estimates in small samples can be substantial.Moreover, in small samples, there is a non-negligible probability of encountering the separation.From the geometrical point of view the separation occurs when there exists a hyperplane which separates successes and failures (complete separation), where the hyperplane itself may contain both successes and failures (quasicomplete separation).In that case, at least one parameter estimate diverges to infinity (Albert and Anderson 1984;Heinze and Schemper 2002).In practice, the separation phenomenon can be detected by tracking the magnitude of standard errors.The most common strategy to deal with separation is to remove any offending variable(s) from the model.However, this approach is seriously flawed since the omission of any important variable(s) is inappropriate.
1.2.Penalized maximum likelihood Firth (1992aFirth ( ,b, 1993) ) derived the procedure that guarantees finite estimates of logistic regression parameters in case of separation; it was also proven to significantly reduce the small sample bias of maximum likelihood estimates, i.e., the first-order term is removed from the asymptotic bias of maximum likelihood estimates.The procedure originally developed by Firth (1993) was further researched and popularized by the work of Heinze and Schemper (2002), Heinze andPloner (2004), andHeinze (2006).
The basis of Firth's approach is the idea that the bias in θ can be reduced by modifying the score equations.The modified equation has the following form: where The modification to score equations can alternatively be introduced by penalizing the original likelihood function: It is interesting that Firth's approach to logistic regression is identical to Bayesian logistic regression with noninformative Jeffreys prior.
Penalized maximum likelihood estimates (PMLE) can be found with the use of the numerical routine described above with U θ (r) term replaced by U * θ (r) .

Statistical inference
Estimation of standard errors can be based on the roots of the diagonal elements of I −1 θ , which is a first-order approximation to (Firth 1992a(Firth ,b, 1993;;Bull, Mak, and Greenwood 2002).According to the simulation study performed by the authors (results not shown), there is no clear advantage of using I * θ −1 in place of I −1 θ with respect to the number of iterations needed for convergence and the coverage of a Wald confidence interval.However, more extensive study regarding this subject would be useful.Appropriate simulation studies can be greatly facilitated by the recent work of (Chen, Ibrahim, and Kim 2008) from which the closed form of I * θ −1 can be easily obtained.
Given the estimate of the covariance matrix I −1 θ , one can compute Wald confidence intervals and p values based on the normal approximation to the distribution of the PML estimates.The (1 − α)% Wald confidence interval for θ j , (j = 1, . . ., p) is given by: where θj is the PML estimate of j-th element of θ, z 1− α 2 is the 1 − α 2 quantile of the standard normal distribution function and (I −1 θ ) j is a j-th diagonal element of I −1 θ .It should be noted, however, that in small samples the coverage probability of the Wald confidence interval may deviate from its nominal value.This behavior was observed in simulation studies performed by (Heinze 1999), it was also shown there that profile likelihood confidence intervals are superior to Wald intervals.Simulation studies performed by the authors (results not shown) led to similar conclusions.

STATISTICA macro
The STATISTICA data analysis software system (StatSoft, Inc. 2010) offers a user-friendly module for maximum likelihood estimation of logistic regression coefficients.As was mentioned above, the maximum likelihood estimation is not resistant to the separation problem and, generally speaking, is not suitable for small datasets.This was the main motivation for the implementation of a STATISTICA macro performing Firth-type logistic regression.
The presented macro was written in SVB (the Visual Basic programming environment integrated with STATISTICA) in STATISTICA 9.1.SVB is similar to Microsoft Visual Basic 6, as well as the Visual Basic language available in Microsoft Excel.SVB includes a comprehensive library of optimized matrix procedures.The employment of built-in matrix functions resulted in a more readable macro code.
The macro code was partly based on a source code of the R (R Development Core Team 2012) package logistf (Heinze and Ploner 2004;Ploner, Dunkler, Southworth, and Heinze 2010).An alternative R implementation offering similar functionality is available in the package brglm (Kosmidis 2011), based on the recent work of Kosmidis and Firth (2009).

Starting a macro
Launch STATISTICA and open a dataset of interest.
Open the macro file named SR_BR_LR.svb(separation-resistant bias-reduced logistic regression), available along with this manuscript.
Press the F5 keyboard button or left-click the Run Macro button on the Macro toolbar (see Figure 1).
The variable selection window should appear.The list of variables available for analysis is automatically loaded from the active workbook.
Select appropriate variables and press the OK button.After a short time, an output window should appear.
If one plans to use the macro frequently, then a different approach should be taken, i.e., the macro should be installed.This process creates a button which automatically starts the macro without the need to manually reopen the macro file every time STATISTICA is restarted.To install the macro file:    Open the macro file named SR_BR_LR.svb.
Right-click on any toolbar and select the Customize (see Figure 2).
Go to the Command/Macros tab, select Macros from the Categories list, and from the Commands list, drag the macro name (i.e., SR_BR_LR) from its original position to the main toolbar (see Figure 3 and 4).
Press the newly created button to start the macro.

Generated output
The output generated by the macro consists of a workbook with three spreadsheets.The first spreadsheet holds the original values of the dependent variable along with estimated probabilities of a success.The second spreadsheet holds the estimate of the covariance matrix, i.e., I −1 θ .The third spreadsheet is of the most importance as it shows the following: The number of iterations needed for convergence.
The value of log-likelihood at last iteration.
Parameter estimates.
Standard errors (SE) of parameter estimates.
Odds ratios for a unit increase in the independent variables.95% Wald confidence intervals for odds ratios.
P values for a hypothesis test that a given parameter is equal to zero.
In the current version of the macro, profile penalized likelihood confidence intervals are not implemented.They are, however, planned for future release.

Toy example
The toy dataset was constructed to demonstrate the case of the infiniteness of ML estimates in logistic regression.The data matrix X in the first column contains 1s and the only explanatory variable assumes 10 equidistant values from 1 to 10.The first 5 values of dependent variable (y) are failures (0) and the last 5 are successes (1).One can clearly see the complete separation, i.e., all cases are failures where the value of the explanatory variable is less than 6 and all cases are successes where the value of the explanatory variable is greater than or equal to 6.
X = 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 y = 0 0 0 0 0 1 1 1 1 1 To estimate the logistic regression model on this dataset, we used both the package logistf and our macro.Below we show the necessary commands to create the toy dataset, estimate the model and visualize the results.Figure 6 presents the dataset along with the fitted logistic function.Figure 5 shows a screen capture of the output of our macro.The estimation results of both the package logistf and our macro are in very close agreement.

Swiss banknotes example
For the next example we used the 'Swiss banknotes' dataset (Flury 1988).The dataset contains 7 variables, of which the first 6 variables are explanatory variables and the last variable is the outcome variable which describes whether the banknote is genuine or not.The dataset was taken from the R package ncomplete (Christmann and Rousseeuw 2001).The explanatory variables were standardized before applying estimation procedures.
The 'Swiss banknotes' dataset also exhibits complete separation.Consequently, penalized maximum likelihood estimates should be preferred.As before, estimation results of both the package logistf and our macro (see Figure 7) are in very close agreement.

Figure 1 :
Figure 1: The localization of the Run Macro button on the Macro toolbar.

Figure 2 :
Figure 2: The localization of the Customize button.

Figure 3 :
Figure 3: The localization of the Commands list.

Figure 4 :
Figure 4: The effect of the macro installation.

Figure 6 :
Figure 6: Logistic function fitted to the toy dataset.