modeLLtest: An R Package for Unbiased Model Comparison using Cross Validation

Selection among statistical models describing the same process is a crucial methodological step in quantitative research. Because different estimators for the same process are commonly available, researchers have developed tests for selecting among models. The R package mode LLtest implements a variety of such tests using leave-one-out cross-validation (LOOCV) to adjudicate among estimation methods. LOOCV accounts for outliers in data by comparing results across samples in which one observation has been left out (Diebold & Mariano, 2002). The R package modeLLtest has three main functionalities. It implements an unbiased comparison of two linear parametric, non-nested models (Desmarais & Harden, 2014; Harden & Desmarais, 2011), a test comparing two estimations of the Cox proportional hazards model the conventional partial likelihood maximization (PLM) and the iteratively reweighted robust model (IRR) (Desmarais & Harden, 2012), and a set of more general functions for comparison of arbitrary models. In addition to making these comparison tests easily accessible in an R package, we improve the running speed of selected functions by making use of C++ to per-form LOOCV before pulling the output into R. As a result, these tests now run in a reasonable amount of time on large data sets. Researchers can use the fast LOOCV results as inputs to alternative and new model testing procedures. models fit the data using methods by and Clarke (2001,


Summary
Selection among statistical models describing the same process is a crucial methodological step in quantitative research. Because different estimators for the same process are commonly available, researchers have developed tests for selecting among models. The R package mode LLtest implements a variety of such tests using leave-one-out cross-validation (LOOCV) to adjudicate among estimation methods. LOOCV accounts for outliers in data by comparing results across samples in which one observation has been left out (Diebold & Mariano, 2002).
The R package modeLLtest has three main functionalities. It implements an unbiased comparison of two linear parametric, non-nested models (Desmarais & Harden, 2014;Harden & Desmarais, 2011), a test comparing two estimations of the Cox proportional hazards modelthe conventional partial likelihood maximization (PLM) and the iteratively reweighted robust model (IRR) (Desmarais & Harden, 2012), and a set of more general functions for comparison of arbitrary models. In addition to making these comparison tests easily accessible in an R package, we improve the running speed of selected functions by making use of C++ to perform LOOCV before pulling the output into R. As a result, these tests now run in a reasonable amount of time on large data sets. Researchers can use the fast LOOCV results as inputs to alternative and new model testing procedures.

Unbiased linear model comparison
When models are parametric and non-nested, the null hypothesis that two models fit the data equally well has often been tested using methods introduced by Vuong (1989) and Clarke (2001Clarke ( , 2003Clarke ( , 2007. These methods compare the Kullback-Leibler Divergence (KLD) of the two models from the true model that generated the data. However, more recently, Desmarais and Harden (2014) showed the estimate of the KLD used by Vuong, the individual loglikelihood contributions, is biased. They also showed the Clarke test to be inconsistent when applied to the difference in KLDs. As a solution, Desmarais and Harden (2014) derived a test based on LOOCV contributions, creating an unbiased KLD estimate. The implementation of Desmarais and Harden's test comparing two methods of estimation is a major component of modeLLtest. A primary example of the test's use within this context is in the adjudication among ordinary least squares (OLS) regression, robust regression, and the less-commonly used median regression (MR) (Hao & Naiman, 2007;Harden & Desmarais, 2011;Koenker, 2005). For researchers looking to make more informed decisions regarding model fit rather than relying on conventionally-used methods such as OLS alone, modeLLtest significantly improves the ease of choosing among estimation methods.

Cox proportional hazards model
The Cox model is a partial parametric model that does not make assumptions about the baseline hazard. The conventional partial likelihood maximization (PLM) and iteratively reweighted robust (IRR) estimation methods represent two alternatives for parameter estimation. Either could be optimal based on characteristics of the data. Plausible deviations from correct specification and operationalization, which can be caused by issues such as measurement error or omitted variables, can produce substantial bias when the Cox model is estimated by PLM. However, using the IRR estimator in the absence of these problems can result in a loss of efficiency. For this reason, Desmarais and Harden (2012) developed a novel cross-validated median fit (CVMF) test for selecting between the two estimators. The R package modeLLtest provides implementation of this test with original contributions which include options to specify methods other than Efron approximation (e.g., Breslow approximation), specify the truncation or trimming level for the robust estimator, adjust fitting weights, and run the test on only a subset of data.

General tools
In addition to providing the above tests, modeLLtest also contains tools for model comparison in a more general setting. Given any model specification and estimation method as inputs, mo deLLtest can create a vector of LOOCV log-likelihood estimates. These vectors subsequently can be fed to a function that performs the unbiased Johnson t-test (see also Desmarais & Harden, 2014;Johnson, 1978) on the two vectors of log-likelihoods in order to select between models.

Functionality and use
The R package modeLLtest is designed to be used by both researchers and students looking to compare models or create LOOCV log-likelihood estimates for a given model. The ease and speed of implementing selected tests are significantly improved through the use of C++ to obtain LOOCV log-likelihood estimates. The source code is on GitHub. The documentation can be found on GitHub Pages. Functions can be tested using data from real-world analyses from Joshi and Mason (2008) and Golder (2010).

Future work
Future work will include providing implementation for additional models to be used in the CVDM and CVLL functions.