Skip to content

Instantly share code, notes, and snippets.

@pepijn-devries
Created November 25, 2016 15:00
Show Gist options
  • Save pepijn-devries/5350ada2fc3a0e3930ea4c721b82566a to your computer and use it in GitHub Desktop.
Save pepijn-devries/5350ada2fc3a0e3930ea4c721b82566a to your computer and use it in GitHub Desktop.
require(pscl)
# the vuong test returns NULL. Lines below will modify the function to return the output table:
# Turn the vuong-function into text:
vuong2 <- deparse(vuong)
# remove the current return statement:
vuong2 <- vuong2[!grepl("return", vuong2)]
# instead of printing the output, return it!:
vuong2 <- gsub("print(out)", "return(out)", vuong2, fixed = T)
# now change the text back into an actual function that can be called:
vuong2 <- eval(parse(text = vuong2))
# Now fit some example models to test the modified function:
data("bioChemists", package = "pscl")
fm_zip <- zeroinfl(art ~ . | 1, data = bioChemists)
fm_zinb <- zeroinfl(art ~ . | 1, data = bioChemists, dist = "negbin")
# Test the modified function. Look it returns the test results... Nice...
result <- vuong2(fm_zip, fm_zinb)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment