MyNixOS website logo
Description

Distribution-Free Tests of Non-Nested Models.

Implementation of Clarke's distribution-free test of non-nested models. Currently supported model functions are: lm(), glm() ('binomial', 'poisson', 'negative binomial' links), polr() ('MASS'), clm() ('ordinal'), and multinom() ('nnet'). For more information on the test, see Clarke (2007) <doi:10.1093/pan/mpm004>.

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.

  • The indivLogLiks function should take the model object as its only argument and return a vector of the individual log-likelihoods for each observation in the estimation sample. Here is an example for objects of class clm.
indivLogLiks.clm <- function(model){
  probs <- predict(model, type="prob")$fit
  ans <- log(probs)
  return(ans)
}
  • The nparams function should take the model object as its only argument and return a scalar that gives the number of parameters in the model. Here is an example for models of class clm.
nparams.clm <- function(model){
  length(coef(model))
}
  • Additionally, the function uses the nobs() generic to find the number of observations. If there is no nobs() method for the current model class, the user would have to write one of those, too. Here is an example of the nobs method for mlogit objects.
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)
Metadata

Version

0.2.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows