Created
August 18, 2017 14:14
-
-
Save jwaage/ae351b64eab8ce5e125485a01566fdce to your computer and use it in GitHub Desktop.
Adonis Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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