Dear Diogo,

the following function should give you the p-values (physo.obs.p) you are looking for:

# obs : observed phylosor-values (distance matrix)
# rand : list of distance matrices from the "phylosor.rnd"-function

ses.physo <- function(obs, rand){
  rand <- t(as.data.frame(lapply(rand, as.vector)))
  physo.obs <- as.numeric(obs)
  physo.mean <- apply(rand, MARGIN = 2, FUN = mean, na.rm = TRUE)
  physo.sd <- apply(rand, MARGIN = 2, FUN = sd, na.rm = TRUE)
  physo.ses <- (physo.obs - physo.mean)/physo.sd
physo.obs.rank <- apply(X = rbind(physo.obs, rand), MARGIN = 2, FUN = rank)[1, ]
  physo.obs.rank <- ifelse(is.na(physo.mean), NA, physo.obs.rank)
data.frame(physo.obs, physo.mean, physo.sd, physo.obs.rank, physo.ses, physo.obs.p = physo.obs.rank/(dim(rand)[1] + 1))
}

# code heavily borrowed from Steven Kembel's "ses.mpd"-function

Good luck,
Oliver

--
Oliver Purschke, PhD
Department of Biology
Biodiversity Unit
Sölvegatan 37, SE-223 62 Lund, Sweden

+46 (0)73 891 1048 (mobile, SE)
+46 (0)46 222 8976 (office, SE)
+49 (0)1522 916 2980 (mobile, DE)
skype: oliverpurschke

oliver.pursc...@nateko.lu.se

www.lu.se/o.o.i.s/27001
http://www.mendeley.com/profiles/oliver-purschke/

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to