Skip to content

Instantly share code, notes, and snippets.

@jwaage
Created August 18, 2017 14:14
Show Gist options
  • Save jwaage/ae351b64eab8ce5e125485a01566fdce to your computer and use it in GitHub Desktop.
Save jwaage/ae351b64eab8ce5e125485a01566fdce to your computer and use it in GitHub Desktop.
Adonis Table
adonis_table <- function(phy, d, ...){
subs <- function(dist, index) as.dist(as.matrix(dist)[index,index])
contcheck <- function(var){
suppressWarnings(
if(all(is.na(as.numeric(var))) | length(unique(var))<10){
return(var)
} else {
return(as.numeric(var))
}
)
}
tab <- phy %>%
get_variable(.) %>%
gather(variable, value, ...)
tab %>%
group_by(variable) %>%
do( adonis(subs(d,!is.na(.$value)) ~ contcheck(value), .[!is.na(.$value),]) %>%
( function(x) {data.frame( x$aov.tab[1,4:6],
n = nrow(x$model.matrix),
perms = nrow(x$f.perms)
)} )
) %>%
ungroup %>%
rename(pval = `Pr..F.`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment