diff --git a/99_HIDDEN_functions.R b/99_HIDDEN_functions.R index 774927d4f07aa31d9a0c9989ad7a38580d881d15..45e59b9064e30d066e3847b004502770a21396f2 100644 --- a/99_HIDDEN_functions.R +++ b/99_HIDDEN_functions.R @@ -124,7 +124,7 @@ get.corXE <- function(comm, traits, envir, trait.sel="all", env.sel="all", stat= #perm.df = df traitCombination X permutations with the chosen statistic of correlation on permuteda data get.SES <- function(obs.df, perm.df, stat="RV") { - nperm <- dim(perm.df)[2] + #nperm <- dim(perm.df)[2] SES.out <- as.data.frame.table(perm.df) %>% rename(Trait.comb=Var1, perm=Var2, coef=Freq ) %>% group_by(Trait.comb) %>% @@ -134,12 +134,15 @@ get.SES <- function(obs.df, perm.df, stat="RV") { mutate(Trait.comb=paste0("t", Trait.comb)) %>% rename(obs=Coef), by=c("Trait.comb")) %>% - summarize(q15 = quantile(coef, probs = 0.15865), + summarize(q025 = quantile(coef, probs = 0.025), + q15 = quantile(coef, probs = 0.15865), q50 = quantile(coef, .5), - q84 = quantile(coef, 0.84135), + q84 = quantile(coef, 0.84135), + q975 = quantile(coef, 0.975), mean.perm=mean(coef), - sd.perm=sd(coef), - greater.than.obs=sum( (abs(coef)>=abs(obs))/n())) %>% + sd.perm = sd(coef), + greater.than.obs = sum( coef >= obs )/n(), + smaller.than.obs = sum( coef <= obs )/n()) %>% left_join(obs.df %>% filter(Test==stat) %>% dplyr::select(-pvalue, -Test) %>% @@ -149,10 +152,11 @@ get.SES <- function(obs.df, perm.df, stat="RV") { mutate(SES.np= ifelse(obs>=q50, (obs-q50)/(q84-q50), (obs-q50)/(q50-q15))) %>% mutate(SES=(obs-mean.perm)/sd.perm) %>% arrange(desc(SES.np)) %>% - mutate(conf.m=obs-1.65*(sd.perm/sqrt(nperm))) %>% - mutate(conf.p=obs+1.65*(sd.perm/sqrt(nperm))) + mutate(conf.m=mean.perm - 1.96*(sd.perm)) %>% #/sqrt(nperm))) %>% + mutate(conf.p=mean.perm + 1.96*(sd.perm)) #/sqrt(nperm))) return(SES.out) } +