clarkeTest

ClarkeTest makes doing tests of non-nested models easy and clear. The main testing function currently supports models of class lm, glm (binomial, poisson and negative binomial), polr, clm, multinom, mlogit.

The initial code came from the games package which worked with strategic game models as well as binomial GLMs and linear models. The impetus for making this package was to extend the classes of models that could be evaluated.

I re-wrote the function to call generic functions for the individual log-likelihoods and the number of model parameters. This makes it easy for others to extend the functionality by writing indivLogLiks and nparams methods for a new model class.

indivLogLiks.clm <- function(model){
  probs <- predict(model, type="prob")$fit
  ans <- log(probs)
  return(ans)
}
nparams.clm <- function(model){
  length(coef(model))
}
nobs.mlogit <- function(object, ...){
  length(object$fitted.values)
}

Installation

# Install release version from CRAN
install.packages("clarkeTest")
# Install development version from GitHub
remotes::install_github("davidaarmstrong/ClarkeTest")

Usage

Here is an example of how the function works:

library(clarkeTest)
data(conflictData)
lm1 <- lm(riots ~ log(rgdpna_pc) + log(pop*1000) + 
    polity2, data=conflictData)
lm2 <- lm(riots ~ rgdpna_pc + pop + 
    polity2, data=conflictData)
clarke_test(lm1, lm2)
#> 
#> Clarke test for non-nested models
#> 
#> Model 1 log-likelihood: -8446
#> Model 2 log-likelihood: -8433
#> Observations: 4381
#> Test statistic: 1830 (42%)
#> 
#> Model 2 is preferred (p < 2e-16)