Skip to content

Instantly share code, notes, and snippets.

@ajpelu
Last active May 18, 2016 14:52
Show Gist options
  • Save ajpelu/194e721077ec045a2b864088908e7aca to your computer and use it in GitHub Desktop.
Save ajpelu/194e721077ec045a2b864088908e7aca to your computer and use it in GitHub Desktop.
How to get results from multcomp glht object to print as table
# Table for export results of multiple comparison (post hoc Tukey)
# Source: Modified from https://gist.github.com/cheuerde/3acc1879dc397a1adfb0
# x is a ghlt object
table_glht <- function(x) {
pq <- summary(x)$test
mtests <- cbind(pq$coefficients, pq$sigma, pq$tstat, pq$pvalues)
error <- attr(pq$pvalues, "error")
pname <- switch(x$alternativ, less = paste("Pr(<", ifelse(x$df ==0, "z", "t"), ")", sep = ""),
greater = paste("Pr(>", ifelse(x$df == 0, "z", "t"), ")", sep = ""), two.sided = paste("Pr(>|",ifelse(x$df == 0, "z", "t"), "|)", sep = ""))
colnames(mtests) <- c("Estimate", "Std. Error", ifelse(x$df ==0, "z value", "t value"), pname)
return(mtests)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment