From c7cc5d33e07271a3140974b171c9541b89beefee Mon Sep 17 00:00:00 2001 From: Steve Vissault Date: Mon, 19 Dec 2016 15:29:40 -0500 Subject: [PATCH 1/6] Clean fct names (#16) * CamelCase functions * restore Bartomeus data file in R/ * Fixing issue with weight_sd and weight_mean functions * removin weight_mean and weigthed_sd, already present in stats - close #17 * Rebuild package and add new clean target in makefile * adding a test for residualsNicheProb.R testing only the format. --- Makefile | 6 +++- NAMESPACE | 34 +++++++++---------- R/{fit.niche.prob.R => estNichePars.R} | 6 ++-- R/{extract.bayesreg.R => extractBayesReg.R} | 5 ++- R/{fit.bayesreg.R => fitBayesReg.R} | 4 +-- ...ect.centrality.R => fitDirectCentrality.R} | 5 ++- R/{fit.niche.bin.R => fitNicheBin.R} | 5 ++- ...tworkstat.bayesreg.R => networkBayesReg.R} | 6 ++-- R/{niche.prob.R => nicheProb.R} | 15 ++++---- R/{plot.niche.prob.R => plotPred.R} | 4 +-- R/{predict.bayesreg.R => predBayesReg.R} | 5 ++- ...ct.centrality.R => predDirectCentrality.R} | 5 ++- R/{predict.niche.bin.R => predNicheBin.R} | 5 ++- R/{predict.niche.prob.R => predNicheProb.R} | 8 ++--- R/residuals.niche.prob.R | 21 ------------ R/residualsNicheProb.R | 21 ++++++++++++ R/{sim.traitmatch.R => simTraitMatch.R} | 7 ++-- R/useful.functions.R | 30 ---------------- man/{fit.niche.prob.Rd => estNichPars.Rd} | 13 ++++--- ...extract.bayesreg.Rd => extractBayesReg.Rd} | 8 ++--- man/{fit.bayesreg.Rd => fitBayesReg.Rd} | 8 ++--- ...t.centrality.Rd => fitDirectCentrality.Rd} | 8 ++--- man/{fit.niche.bin.Rd => fitNicheBin.Rd} | 9 +++-- ...network.bayesreg.Rd => networkBayesReg.Rd} | 8 ++--- man/{niche.prob.Rd => nicheProb.Rd} | 10 +++--- man/{plot.niche.model.Rd => plotPred.Rd} | 9 +++-- man/{predict.bayesreg.Rd => predBayesReg.Rd} | 8 ++--- ....centrality.Rd => predDirectCentrality.Rd} | 8 ++--- man/{predict.niche.bin.Rd => predNicheBin.Rd} | 8 ++--- ...predict.niche.prob.Rd => predNicheProb.Rd} | 10 +++--- man/residuals.niche.prob.Rd | 25 -------------- man/residualsNicheProb.Rd | 25 ++++++++++++++ man/{sim.traitmatch.Rd => simTraitMatch.Rd} | 9 +++-- man/useful_functions.Rd | 26 -------------- tests/testthat/test-models.R | 14 ++++++-- tests/testthat/test-useful.functions.R | 12 ------- 36 files changed, 169 insertions(+), 241 deletions(-) rename R/{fit.niche.prob.R => estNichePars.R} (95%) rename R/{extract.bayesreg.R => extractBayesReg.R} (91%) rename R/{fit.bayesreg.R => fitBayesReg.R} (98%) rename R/{fit.direct.centrality.R => fitDirectCentrality.R} (86%) rename R/{fit.niche.bin.R => fitNicheBin.R} (89%) rename R/{networkstat.bayesreg.R => networkBayesReg.R} (94%) rename R/{niche.prob.R => nicheProb.R} (89%) rename R/{plot.niche.prob.R => plotPred.R} (93%) rename R/{predict.bayesreg.R => predBayesReg.R} (96%) rename R/{predict.direct.centrality.R => predDirectCentrality.R} (83%) rename R/{predict.niche.bin.R => predNicheBin.R} (91%) rename R/{predict.niche.prob.R => predNicheProb.R} (86%) delete mode 100644 R/residuals.niche.prob.R create mode 100644 R/residualsNicheProb.R rename R/{sim.traitmatch.R => simTraitMatch.R} (93%) delete mode 100644 R/useful.functions.R rename man/{fit.niche.prob.Rd => estNichPars.Rd} (84%) rename man/{extract.bayesreg.Rd => extractBayesReg.Rd} (75%) rename man/{fit.bayesreg.Rd => fitBayesReg.Rd} (91%) rename man/{fit.direct.centrality.Rd => fitDirectCentrality.Rd} (74%) rename man/{fit.niche.bin.Rd => fitNicheBin.Rd} (77%) rename man/{network.bayesreg.Rd => networkBayesReg.Rd} (83%) rename man/{niche.prob.Rd => nicheProb.Rd} (89%) rename man/{plot.niche.model.Rd => plotPred.Rd} (85%) rename man/{predict.bayesreg.Rd => predBayesReg.Rd} (89%) rename man/{predict.direct.centrality.Rd => predDirectCentrality.Rd} (72%) rename man/{predict.niche.bin.Rd => predNicheBin.Rd} (80%) rename man/{predict.niche.prob.Rd => predNicheProb.Rd} (77%) delete mode 100644 man/residuals.niche.prob.Rd create mode 100644 man/residualsNicheProb.Rd rename man/{sim.traitmatch.Rd => simTraitMatch.Rd} (83%) delete mode 100644 man/useful_functions.Rd delete mode 100644 tests/testthat/test-useful.functions.R diff --git a/Makefile b/Makefile index 760d92c..e7af43e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ rfun := $(wildcard R/*.R) +rman := $(wildcard man/) rtes := $(wildcard tests/testthat/*.R) rdm = README.Rmd md = README.md @@ -11,5 +12,8 @@ all: $(md) $(chk) $(md): $(rdm) Rscript --no-site-file --no-init-file $(rscr) 0 -$(chk): $(rfun) $(rtes) +$(chk): $(rfun) $(rtes) $(rman) Rscript --no-site-file --no-init-file $(rscr) 1 + +clean: + rm -rf man/* NAMESPACES diff --git a/NAMESPACE b/NAMESPACE index f60034f..18267dd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,26 +1,24 @@ # Generated by roxygen2: do not edit by hand -S3method(predict,bayesreg) -S3method(predict,direct.centrality) -S3method(predict,niche.bin) -S3method(predict,niche.prob) -S3method(residuals,niche.prob) export(binomialToJags) -export(extract.bayesreg) -export(fit.bayesreg) -export(fit.direct.centrality) -export(fit.niche.bin) -export(fit_it) +export(estNichPars) +export(extractBayesReg) +export(fitBayesReg) +export(fitDirectCentrality) +export(fitNicheBin) export(iEat_bin) -export(integrated.model) +export(integratedModel) export(interceptToJags) export(multinomialToJags) -export(network.bayesreg) -export(neutral.model) -export(niche.model) -export(plot_pred) +export(networkBayesReg) +export(neutralModel) +export(nicheModel) +export(plotPred) export(poissonToJags) -export(sim.traitmatch) -export(weighted_mean) -export(weighted_sd) +export(predBayesReg) +export(predDirectCentrality) +export(predNicheBin) +export(predNicheProb) +export(residualsNicheProb) +export(simTraitMatch) importFrom(magrittr,"%>%") diff --git a/R/fit.niche.prob.R b/R/estNichePars.R similarity index 95% rename from R/fit.niche.prob.R rename to R/estNichePars.R index 13107b0..b81c4a4 100755 --- a/R/fit.niche.prob.R +++ b/R/estNichePars.R @@ -1,4 +1,4 @@ -#' @name fit.niche.prob +#' @name estNichPars #' #' @title Fit a model using Genaralized Simulated Annealing (SA) functions. #' @@ -28,7 +28,7 @@ #' Dominique Gravel and Ignasi Bartomeus #' #' @export -fit_it <- function(model, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1, pars = c(a0 = 0, +estNichPars <- function(model, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1, pars = c(a0 = 0, a1 = 0, b0 = 0, b1 = 0), par_lo = c(a0 = -5000, a1 = -5000, b0 = -5000, b1 = -5000), par_hi = c(a0 = 5000, a1 = 5000, b0 = 5000, b1 = 5000), max.time = 1800) { # Initial values pars = c(a0 = 0, a1 = 0, b0 = 0, b1 = 0) #default lm_M = @@ -40,5 +40,3 @@ fit_it <- function(model, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1, pars = c(a Tlevel2 = Tlevel2, mean_Tlevel1 = mean_Tlevel1, sd_Tlevel1 = sd_Tlevel1) estim.pars$par } - - diff --git a/R/extract.bayesreg.R b/R/extractBayesReg.R similarity index 91% rename from R/extract.bayesreg.R rename to R/extractBayesReg.R index a114afe..1170405 100644 --- a/R/extract.bayesreg.R +++ b/R/extractBayesReg.R @@ -1,4 +1,4 @@ -#' @name extract.bayesreg +#' @name extractBayesReg #' @title Extract posterior distributions from Bayesian Regression Model #' #' @description A helper function for getting the chains from a JAGS model object outputted from fit.bayesreg @@ -9,10 +9,9 @@ #' @references #' Bartomeus et al. 2016. Functional Ecology. #' -#' @rdname extract.bayesreg #' @export -extract.bayesreg <- function(x) { +extractBayesReg <- function(x) { parsO <- reshape2::melt(x$BUGSoutput$sims.array) colnames(parsO) <- c("Draw", "Chain", "parameter", "estimate") diff --git a/R/fit.bayesreg.R b/R/fitBayesReg.R similarity index 98% rename from R/fit.bayesreg.R rename to R/fitBayesReg.R index a2339fb..3091d11 100644 --- a/R/fit.bayesreg.R +++ b/R/fitBayesReg.R @@ -1,4 +1,4 @@ -#' @name fit.bayesreg +#' @name fitBayesReg #' @aliases bayesian regression #' @author Ben Weinstein #' @title Hierarchical Bayesian Regression for estimating trait-matching in species interaction data @@ -29,7 +29,7 @@ #' #' @export -fit.bayesreg <- function(dat, algorithm = "Binomial", draws = 10000) { +fitBayesReg <- function(dat, algorithm = "Binomial", draws = 10000) { stopifnot(algorithm %in% c("Binomial", "Intercept", "Poisson")) diff --git a/R/fit.direct.centrality.R b/R/fitDirectCentrality.R similarity index 86% rename from R/fit.direct.centrality.R rename to R/fitDirectCentrality.R index 14a2ff7..1e37319 100644 --- a/R/fit.direct.centrality.R +++ b/R/fitDirectCentrality.R @@ -1,4 +1,4 @@ -#' @name fit.direct.centrality +#' @name fitDirectCentrality #' #' @title Direct matching centrality #' @@ -13,9 +13,8 @@ #' #' @references #' -#' @rdname fit.direct.centrality #' @export -fit.direct.centrality <- function(data, algorithm, ...) { +fitDirectCentrality <- function(data, algorithm, ...) { if (algorithm == "logistic") model <- stats::glm(I ~ . * ., data, family = "binomial") else if (algorithm == "poisson") diff --git a/R/fit.niche.bin.R b/R/fitNicheBin.R similarity index 89% rename from R/fit.niche.bin.R rename to R/fitNicheBin.R index b3b72ec..8ddad50 100644 --- a/R/fit.niche.bin.R +++ b/R/fitNicheBin.R @@ -1,4 +1,4 @@ -#' @name fit.niche.prob +#' @name fitNicheBin #' #' @title This function use a pair of traits. #' @@ -14,9 +14,8 @@ #' #' @references #' -#' @rdname fit.niche.bin #' @export -fit.niche.bin <- function(data, thresh) { +fitNicheBin <- function(data, thresh) { # input data should be checked Fit model model_o <- stats::lm(Tj ~ Ti, data) model_lo <- quantreg::rq(Tj ~ Ti, tau = thresh, data) diff --git a/R/networkstat.bayesreg.R b/R/networkBayesReg.R similarity index 94% rename from R/networkstat.bayesreg.R rename to R/networkBayesReg.R index 232c128..b464763 100644 --- a/R/networkstat.bayesreg.R +++ b/R/networkBayesReg.R @@ -1,12 +1,12 @@ #' Generate network statistics from a hierarchical bayesian model of species interactions -#' @name network.bayesreg +#' @name networkBayesReg #' @param x A predicted model object from predict.bayesreg #' @param indices a vector of network statistics corresponding to network statistics (see details) #' @details Network statistics are calculated using the fucntion networklevel from the package bipartite, see ?networklevel for a list of available options. #' #' @return A data frame with the desired metrics for each of the draws of the network. #' @export -network.bayesreg <- function(x, indices) { +networkBayesReg <- function(x, indices) { # helper function for web prediction makeN <- function(a, indices) { @@ -27,5 +27,3 @@ network.bayesreg <- function(x, indices) { return(nstats) } - - diff --git a/R/niche.prob.R b/R/nicheProb.R similarity index 89% rename from R/niche.prob.R rename to R/nicheProb.R index d3f2d9c..c15190c 100755 --- a/R/niche.prob.R +++ b/R/nicheProb.R @@ -1,7 +1,7 @@ -#' @name niche.prob -#' @aliases integrated.model -#' @aliases niche.model -#' @aliases neutral.model +#' @name nicheProb +#' @aliases integratedModel +#' @aliases nicheModel +#' @aliases neutralModel #' #' @title Bayesian models for characterizing trait-based species interactions. #' @@ -25,9 +25,8 @@ #'Williams, R.J., Anandanadesan, A. and Purves, D. (2010) The probabilistic niche model reveals the niche structure and role of body size in a complex food web. PloS one, 5, e12092. #'Williams, R.J. and Martinez, N.D. (2000) Simple rules yield complex food webs. Nature, 404, 180–183. #' -#' @rdname niche.prob #' @export -integrated.model <- function(pars, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) { +integratedModel <- function(pars, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) { a0 <- pars[1L] a1 <- pars[2L] b0 <- pars[3L] @@ -47,7 +46,7 @@ integrated.model <- function(pars, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) { return(-sum(log(pML))) } #' @export -neutral.model <- function(pars = NULL, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) { +neutralModel <- function(pars = NULL, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) { if (!is.null(pars)) warning("The neutral_model function does not use the content of the argument pars") # Compute the conditional @@ -62,7 +61,7 @@ neutral.model <- function(pars = NULL, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel return(-sum(log(pML))) } #' @export -niche.model <- function(pars, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) { +nicheModel <- function(pars, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) { a0 <- pars[1L] a1 <- pars[2L] b0 <- pars[3L] diff --git a/R/plot.niche.prob.R b/R/plotPred.R similarity index 93% rename from R/plot.niche.prob.R rename to R/plotPred.R index 538ffce..6f250f4 100644 --- a/R/plot.niche.prob.R +++ b/R/plotPred.R @@ -1,4 +1,4 @@ -#' @name plot.niche.model +#' @name plotPred #' #' @title Plot the predicted model output with data points on top. #' @@ -23,7 +23,7 @@ #' Dominique Gravel and Ignasi Bartomeus #' #' @export -plot_pred <- function(pars, Tlevel1, Tlevel2, xlab = "Trait level 2", ylab = "Trait level 1", +plotPred <- function(pars, Tlevel1, Tlevel2, xlab = "Trait level 2", ylab = "Trait level 1", legend = TRUE, pch = 19, ...) { incrementX <- (max(Tlevel2) - min(Tlevel2))/100 incrementY <- (max(Tlevel1) - min(Tlevel1))/100 diff --git a/R/predict.bayesreg.R b/R/predBayesReg.R similarity index 96% rename from R/predict.bayesreg.R rename to R/predBayesReg.R index 148e708..f045068 100644 --- a/R/predict.bayesreg.R +++ b/R/predBayesReg.R @@ -1,4 +1,4 @@ -#' @name predict.bayesreg +#' @name predBayesReg #' @aliases prediction bayesian regression #' #' @title Predict species interaction probabilities based on a fitted hierarchical bayesian regression @@ -22,11 +22,10 @@ #' @references #' Weinstein et al. 2016. Oikos #' -#' @rdname predict.bayesreg #' @importFrom magrittr %>% #' @export -predict.bayesreg <- function(x, newdata = NULL) { +predBayesReg <- function(x, newdata = NULL) { parsm1 <- extract.bayesreg(x) diff --git a/R/predict.direct.centrality.R b/R/predDirectCentrality.R similarity index 83% rename from R/predict.direct.centrality.R rename to R/predDirectCentrality.R index 3c591a5..6b48559 100644 --- a/R/predict.direct.centrality.R +++ b/R/predDirectCentrality.R @@ -1,4 +1,4 @@ -#' @name predict.direct.centrality +#' @name predDirectCentrality #' #' @title Predict direct matching centrality #' @@ -13,9 +13,8 @@ #' #' @references #' -#' @rdname predict.direct.centrality #' @export -predict.direct.centrality <- function(newdata, model, replicates) { +predDirectCentrality <- function(newdata, model, replicates) { p <- predict(model, newdata, type = "response") diff --git a/R/predict.niche.bin.R b/R/predNicheBin.R similarity index 91% rename from R/predict.niche.bin.R rename to R/predNicheBin.R index 0104737..acdcf4e 100644 --- a/R/predict.niche.bin.R +++ b/R/predNicheBin.R @@ -1,4 +1,4 @@ -#' @name predict.niche.bin +#' @name predNicheBin #' #' @title This function use a pair of traits. #' @@ -16,9 +16,8 @@ #' #' @references #' -#' @rdname predict.niche.bin #' @export -predict.niche.bin <- function(models, newdata) { +predNicheBin <- function(models, newdata) { # Check if the newdata has the right format with(newdata, { diff --git a/R/predict.niche.prob.R b/R/predNicheProb.R similarity index 86% rename from R/predict.niche.prob.R rename to R/predNicheProb.R index 215739e..cabe6b4 100644 --- a/R/predict.niche.prob.R +++ b/R/predNicheProb.R @@ -1,4 +1,4 @@ -#' @name predict.niche.prob +#' @name predNicheProb #' #' @title Predict new data points using traitmatch function generated with fit.niche.prob #' @@ -13,14 +13,14 @@ #' The next elements are as many predicted interaction as replicates. #' #' @note -#' See more here: https://github.com/ibartomeus/trait_match +#' See more here: \url{https://github.com/ibartomeus/trait_match} #' #' @author #' Dominique Gravel and Ignasi Bartomeus #' #' #' @export -predict.niche.prob <- function(pars, Tlevel1, Tlevel2, replicates = 100) { +predNicheProb <- function(pars, Tlevel1, Tlevel2, replicates = 100) { out <- list() # Optimum and range o <- pars[1L] + pars[2L] * Tlevel2 @@ -35,5 +35,5 @@ predict.niche.prob <- function(pars, Tlevel1, Tlevel2, replicates = 100) { for (i in 1:replicates + 1) { out[[i]] <- rbinom(length(Tlevel1), size = 1, prob = pLM) } - out + return(out) } diff --git a/R/residuals.niche.prob.R b/R/residuals.niche.prob.R deleted file mode 100644 index 09ef57d..0000000 --- a/R/residuals.niche.prob.R +++ /dev/null @@ -1,21 +0,0 @@ -#' @name residuals.niche.prob -#' -#' @title get the residuals from a fitted niche.prob -#' -#' @description get the residuals from a fitted niche.prob -#' -#' @param pars Parameters of the model obtained with fit.niche.prob function (alpha0, alpha 1, beta 0 and beta 1) -#' @param Tlevel1 Original vector of trait values of the first interaction partner. -#' @param Tlevel2 Original vector of trait values of the second interaction partner. -#' -#' @return a vector with the residual values for each interaction. -#' -#' -#' @author -#' Ignasi Bartomeus and Dominique Gravel -#' -#' @export -residuals.niche.prob <- function(pars, Tlevel1, Tlevel2) { - pred <- predict.niche.prob(pars, Tlevel1, Tlevel2, replicates = 1)[[1L]] - return(1 - pred) -} diff --git a/R/residualsNicheProb.R b/R/residualsNicheProb.R new file mode 100644 index 0000000..9878562 --- /dev/null +++ b/R/residualsNicheProb.R @@ -0,0 +1,21 @@ +#' @name residualsNicheProb +#' +#' @title get the residuals from a fitted nicheProb +#' +#' @description get the residuals from a fitted nicheProb +#' +#' @param pars Parameters of the model obtained with fitNicheProb function (alpha0, alpha 1, beta 0 and beta 1) +#' @param Tlevel1 Original vector of trait values of the first interaction partner. +#' @param Tlevel2 Original vector of trait values of the second interaction partner. +#' +#' @return a vector with the residual values for each interaction. +#' +#' +#' @author +#' Ignasi Bartomeus and Dominique Gravel +#' +#' @export +residualsNicheProb <- function(pars, Tlevel1, Tlevel2) { + pred <- predNicheProb(pars, Tlevel1, Tlevel2, replicates = 1)[[1L]] + return(1 - pred) +} diff --git a/R/sim.traitmatch.R b/R/simTraitMatch.R similarity index 93% rename from R/sim.traitmatch.R rename to R/simTraitMatch.R index 8514e7c..f41aa05 100644 --- a/R/sim.traitmatch.R +++ b/R/simTraitMatch.R @@ -1,4 +1,4 @@ -#' @name sim.traitmatch.R +#' @name simTraitMatch #' @aliases trait-matching #' #' @title Simulating trait-matching among species @@ -19,11 +19,10 @@ #' Bartomeus et al. 2016. Functional Ecology. #' #' -#' @rdname sim.traitmatch #' @export -sim.traitmatch <- function(size_x, size_y, traits_x, traits_y, beta_sigma = 0.1, - alpha_sigma = 0, replicates = 1) { +simTraitMatch <- function(size_x, size_y, traits_x, traits_y, beta_sigma = 0.1, alpha_sigma = 0, + replicates = 1) { # Subtract both and take absolute value, convert cm traitmatch <- abs(sapply(traits_y, function(x) x - traits_x)) diff --git a/R/useful.functions.R b/R/useful.functions.R deleted file mode 100644 index bedd531..0000000 --- a/R/useful.functions.R +++ /dev/null @@ -1,30 +0,0 @@ -#' @name useful_functions -#' @aliases weighted_mean -#' @aliases weighted_sd -#' -#' @title weighted mean and sd -#' -#' @description just weighted mean and sd. -#' -#' @param x vector to compute the mean over. -#' @param w a vector of same length with the weigths of each element. -#' -#' @return a value with the weighted mean or sd. -#' -#' @examples -#' weighted_mean(c(2,3,4), c(1,1,2)) -#' weighted_sd(c(2,3,4), c(2,1,2)) -#' -#' @rdname useful_functions -#' @export -weighted_mean <- function(x, w) { - sum(x * w)/sum(w) -} -#' @export -weighted_sd <- function(x, w) { - sum_w <- sum(w) - sum_w2 <- sum(w^2) - mean_w <- sum(x * w)/sum(w) - ((sum_w/(sum_w^2 - sum_w2)) * sum(w * (x - mean_w)^2))^0.5 -} - diff --git a/man/fit.niche.prob.Rd b/man/estNichPars.Rd similarity index 84% rename from man/fit.niche.prob.Rd rename to man/estNichPars.Rd index 217646f..eeb02df 100644 --- a/man/fit.niche.prob.Rd +++ b/man/estNichPars.Rd @@ -1,13 +1,12 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fit.niche.prob.R -\name{fit.niche.prob} -\alias{fit.niche.prob} -\alias{fit_it} +% Please edit documentation in R/estNichePars.R +\name{estNichPars} +\alias{estNichPars} \title{Fit a model using Genaralized Simulated Annealing (SA) functions.} \usage{ -fit_it(model, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1, pars = c(a0 = 0, a1 - = 0, b0 = 0, b1 = 0), par_lo = c(a0 = -5000, a1 = -5000, b0 = -5000, b1 = - -5000), par_hi = c(a0 = 5000, a1 = 5000, b0 = 5000, b1 = 5000), +estNichPars(model, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1, pars = c(a0 = + 0, a1 = 0, b0 = 0, b1 = 0), par_lo = c(a0 = -5000, a1 = -5000, b0 = -5000, + b1 = -5000), par_hi = c(a0 = 5000, a1 = 5000, b0 = 5000, b1 = 5000), max.time = 1800) } \arguments{ diff --git a/man/extract.bayesreg.Rd b/man/extractBayesReg.Rd similarity index 75% rename from man/extract.bayesreg.Rd rename to man/extractBayesReg.Rd index 8cd1e24..0bc652c 100644 --- a/man/extract.bayesreg.Rd +++ b/man/extractBayesReg.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/extract.bayesreg.R -\name{extract.bayesreg} -\alias{extract.bayesreg} +% Please edit documentation in R/extractBayesReg.R +\name{extractBayesReg} +\alias{extractBayesReg} \title{Extract posterior distributions from Bayesian Regression Model} \usage{ -extract.bayesreg(x) +extractBayesReg(x) } \arguments{ \item{x}{A JAGS model file from fit.bayesreg()} diff --git a/man/fit.bayesreg.Rd b/man/fitBayesReg.Rd similarity index 91% rename from man/fit.bayesreg.Rd rename to man/fitBayesReg.Rd index e5c533a..a365c58 100644 --- a/man/fit.bayesreg.Rd +++ b/man/fitBayesReg.Rd @@ -1,12 +1,12 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fit.bayesreg.R -\name{fit.bayesreg} +% Please edit documentation in R/fitBayesReg.R +\name{fitBayesReg} \alias{bayesian} -\alias{fit.bayesreg} +\alias{fitBayesReg} \alias{regression} \title{Hierarchical Bayesian Regression for estimating trait-matching in species interaction data} \usage{ -fit.bayesreg(dat, algorithm = "Binomial", draws = 10000) +fitBayesReg(dat, algorithm = "Binomial", draws = 10000) } \arguments{ \item{dat}{A data frame with columns named 'I','J','Interactions','TraitI','TraitJ'. diff --git a/man/fit.direct.centrality.Rd b/man/fitDirectCentrality.Rd similarity index 74% rename from man/fit.direct.centrality.Rd rename to man/fitDirectCentrality.Rd index c86331d..5015d3c 100644 --- a/man/fit.direct.centrality.Rd +++ b/man/fitDirectCentrality.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fit.direct.centrality.R -\name{fit.direct.centrality} -\alias{fit.direct.centrality} +% Please edit documentation in R/fitDirectCentrality.R +\name{fitDirectCentrality} +\alias{fitDirectCentrality} \title{Direct matching centrality} \usage{ -fit.direct.centrality(data, algorithm, ...) +fitDirectCentrality(data, algorithm, ...) } \arguments{ \item{data}{a dataframe with a first column named I (the interaction) and extra columns with covariates (can be named at will)} diff --git a/man/fit.niche.bin.Rd b/man/fitNicheBin.Rd similarity index 77% rename from man/fit.niche.bin.Rd rename to man/fitNicheBin.Rd index b2406bd..3fda058 100644 --- a/man/fit.niche.bin.Rd +++ b/man/fitNicheBin.Rd @@ -1,11 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fit.niche.bin.R -\name{fit.niche.prob} -\alias{fit.niche.bin} -\alias{fit.niche.prob} +% Please edit documentation in R/fitNicheBin.R +\name{fitNicheBin} +\alias{fitNicheBin} \title{This function use a pair of traits.} \usage{ -fit.niche.bin(data, thresh) +fitNicheBin(data, thresh) } \arguments{ \item{data}{a dataset with two columns named Tj and Ti} diff --git a/man/network.bayesreg.Rd b/man/networkBayesReg.Rd similarity index 83% rename from man/network.bayesreg.Rd rename to man/networkBayesReg.Rd index e73da42..599dd1a 100644 --- a/man/network.bayesreg.Rd +++ b/man/networkBayesReg.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/networkstat.bayesreg.R -\name{network.bayesreg} -\alias{network.bayesreg} +% Please edit documentation in R/networkBayesReg.R +\name{networkBayesReg} +\alias{networkBayesReg} \title{Generate network statistics from a hierarchical bayesian model of species interactions} \usage{ -network.bayesreg(x, indices) +networkBayesReg(x, indices) } \arguments{ \item{x}{A predicted model object from predict.bayesreg} diff --git a/man/niche.prob.Rd b/man/nicheProb.Rd similarity index 89% rename from man/niche.prob.Rd rename to man/nicheProb.Rd index c27b2e6..d43327f 100644 --- a/man/niche.prob.Rd +++ b/man/nicheProb.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/niche.prob.R -\name{niche.prob} -\alias{integrated.model} -\alias{niche.prob} +% Please edit documentation in R/nicheProb.R +\name{nicheProb} +\alias{integratedModel} +\alias{nicheProb} \title{Bayesian models for characterizing trait-based species interactions.} \usage{ -integrated.model(pars, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) +integratedModel(pars, Tlevel1, Tlevel2, mean_Tlevel1, sd_Tlevel1) } \arguments{ \item{pars}{parameters obtained from fit.niche.prob function or a vector of the form c(a0 = 0, a1 = 0, b0 = 0, b1 = 0) with known parameters.} diff --git a/man/plot.niche.model.Rd b/man/plotPred.Rd similarity index 85% rename from man/plot.niche.model.Rd rename to man/plotPred.Rd index 55864b6..79ab4f5 100644 --- a/man/plot.niche.model.Rd +++ b/man/plotPred.Rd @@ -1,11 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.niche.prob.R -\name{plot.niche.model} -\alias{plot.niche.model} -\alias{plot_pred} +% Please edit documentation in R/plotPred.R +\name{plotPred} +\alias{plotPred} \title{Plot the predicted model output with data points on top.} \usage{ -plot_pred(pars, Tlevel1, Tlevel2, xlab = "Trait level 2", +plotPred(pars, Tlevel1, Tlevel2, xlab = "Trait level 2", ylab = "Trait level 1", legend = TRUE, pch = 19, ...) } \arguments{ diff --git a/man/predict.bayesreg.Rd b/man/predBayesReg.Rd similarity index 89% rename from man/predict.bayesreg.Rd rename to man/predBayesReg.Rd index 890d18b..63d5d2e 100644 --- a/man/predict.bayesreg.Rd +++ b/man/predBayesReg.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/predict.bayesreg.R -\name{predict.bayesreg} +% Please edit documentation in R/predBayesReg.R +\name{predBayesReg} \alias{bayesian} -\alias{predict.bayesreg} +\alias{predBayesReg} \alias{prediction} \alias{regression} \title{Predict species interaction probabilities based on a fitted hierarchical bayesian regression} \usage{ -\method{predict}{bayesreg}(x, newdata = NULL) +predBayesReg(x, newdata = NULL) } \arguments{ \item{x}{A JAGS model file return from fit.bayesreg} diff --git a/man/predict.direct.centrality.Rd b/man/predDirectCentrality.Rd similarity index 72% rename from man/predict.direct.centrality.Rd rename to man/predDirectCentrality.Rd index 1f06400..50febe7 100644 --- a/man/predict.direct.centrality.Rd +++ b/man/predDirectCentrality.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/predict.direct.centrality.R -\name{predict.direct.centrality} -\alias{predict.direct.centrality} +% Please edit documentation in R/predDirectCentrality.R +\name{predDirectCentrality} +\alias{predDirectCentrality} \title{Predict direct matching centrality} \usage{ -\method{predict}{direct.centrality}(newdata, model, replicates) +predDirectCentrality(newdata, model, replicates) } \arguments{ \item{newdata}{a new dataframe with a first column named I (the interaction) and extra columns with covariates (same name as used to fit)} diff --git a/man/predict.niche.bin.Rd b/man/predNicheBin.Rd similarity index 80% rename from man/predict.niche.bin.Rd rename to man/predNicheBin.Rd index 5d50ab1..9089ef2 100644 --- a/man/predict.niche.bin.Rd +++ b/man/predNicheBin.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/predict.niche.bin.R -\name{predict.niche.bin} -\alias{predict.niche.bin} +% Please edit documentation in R/predNicheBin.R +\name{predNicheBin} +\alias{predNicheBin} \title{This function use a pair of traits.} \usage{ -\method{predict}{niche.bin}(models, newdata) +predNicheBin(models, newdata) } \arguments{ \item{models}{The output of fit.niche.bin} diff --git a/man/predict.niche.prob.Rd b/man/predNicheProb.Rd similarity index 77% rename from man/predict.niche.prob.Rd rename to man/predNicheProb.Rd index 083da78..661206e 100644 --- a/man/predict.niche.prob.Rd +++ b/man/predNicheProb.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/predict.niche.prob.R -\name{predict.niche.prob} -\alias{predict.niche.prob} +% Please edit documentation in R/predNicheProb.R +\name{predNicheProb} +\alias{predNicheProb} \title{Predict new data points using traitmatch function generated with fit.niche.prob} \usage{ -\method{predict}{niche.prob}(pars, Tlevel1, Tlevel2, replicates = 100) +predNicheProb(pars, Tlevel1, Tlevel2, replicates = 100) } \arguments{ \item{pars}{Parameters of the model obtained with fit.niche.prob function (alpha0, alpha 1, beta 0 and beta 1)} @@ -23,7 +23,7 @@ The next elements are as many predicted interaction as replicates. It generates predicted interactions based on new data. } \note{ -See more here: https://github.com/ibartomeus/trait_match +See more here: \url{https://github.com/ibartomeus/trait_match} } \author{ Dominique Gravel and Ignasi Bartomeus diff --git a/man/residuals.niche.prob.Rd b/man/residuals.niche.prob.Rd deleted file mode 100644 index 88af256..0000000 --- a/man/residuals.niche.prob.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/residuals.niche.prob.R -\name{residuals.niche.prob} -\alias{residuals.niche.prob} -\title{get the residuals from a fitted niche.prob} -\usage{ -\method{residuals}{niche.prob}(pars, Tlevel1, Tlevel2) -} -\arguments{ -\item{pars}{Parameters of the model obtained with fit.niche.prob function (alpha0, alpha 1, beta 0 and beta 1)} - -\item{Tlevel1}{Original vector of trait values of the first interaction partner.} - -\item{Tlevel2}{Original vector of trait values of the second interaction partner.} -} -\value{ -a vector with the residual values for each interaction. -} -\description{ -get the residuals from a fitted niche.prob -} -\author{ -Ignasi Bartomeus and Dominique Gravel -} - diff --git a/man/residualsNicheProb.Rd b/man/residualsNicheProb.Rd new file mode 100644 index 0000000..9e35c78 --- /dev/null +++ b/man/residualsNicheProb.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/residualsNicheProb.R +\name{residualsNicheProb} +\alias{residualsNicheProb} +\title{get the residuals from a fitted nicheProb} +\usage{ +residualsNicheProb(pars, Tlevel1, Tlevel2) +} +\arguments{ +\item{pars}{Parameters of the model obtained with fitNicheProb function (alpha0, alpha 1, beta 0 and beta 1)} + +\item{Tlevel1}{Original vector of trait values of the first interaction partner.} + +\item{Tlevel2}{Original vector of trait values of the second interaction partner.} +} +\value{ +a vector with the residual values for each interaction. +} +\description{ +get the residuals from a fitted nicheProb +} +\author{ +Ignasi Bartomeus and Dominique Gravel +} + diff --git a/man/sim.traitmatch.Rd b/man/simTraitMatch.Rd similarity index 83% rename from man/sim.traitmatch.Rd rename to man/simTraitMatch.Rd index 4c7055d..c2e8a26 100644 --- a/man/sim.traitmatch.Rd +++ b/man/simTraitMatch.Rd @@ -1,12 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/sim.traitmatch.R -\name{sim.traitmatch.R} -\alias{sim.traitmatch} -\alias{sim.traitmatch.R} +% Please edit documentation in R/simTraitMatch.R +\name{simTraitMatch} +\alias{simTraitMatch} \alias{trait-matching} \title{Simulating trait-matching among species} \usage{ -sim.traitmatch(size_x, size_y, traits_x, traits_y, beta_sigma = 0.1, +simTraitMatch(size_x, size_y, traits_x, traits_y, beta_sigma = 0.1, alpha_sigma = 0, replicates = 1) } \arguments{ diff --git a/man/useful_functions.Rd b/man/useful_functions.Rd deleted file mode 100644 index 69cc179..0000000 --- a/man/useful_functions.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/useful.functions.R -\name{useful_functions} -\alias{useful_functions} -\alias{weighted_mean} -\title{weighted mean and sd} -\usage{ -weighted_mean(x, w) -} -\arguments{ -\item{x}{vector to compute the mean over.} - -\item{w}{a vector of same length with the weigths of each element.} -} -\value{ -a value with the weighted mean or sd. -} -\description{ -just weighted mean and sd. -} -\examples{ -weighted_mean(c(2,3,4), c(1,1,2)) -weighted_sd(c(2,3,4), c(2,1,2)) - -} - diff --git a/tests/testthat/test-models.R b/tests/testthat/test-models.R index 1d8184b..9746c0c 100644 --- a/tests/testthat/test-models.R +++ b/tests/testthat/test-models.R @@ -1,7 +1,8 @@ context("Models") +## 2B improved test_that("integrated model works", { - out <- integrated.model(pars = c(1,1,1,1), + out <- integratedModel(pars = c(1,1,1,1), Tlevel1 = rnorm(10), Tlevel2 = rnorm(10), mean_Tlevel1 = 0, @@ -20,11 +21,20 @@ test_that("integrated model works", { # expect_equal(TRUE, TRUE)#is.numeric(out)) # }) +## 2B improved test_that("neutral model works", { - out <- neutral.model(pars = NULL, + out <- neutralModel(pars = NULL, Tlevel1 = rnorm(10), Tlevel2 = rnorm(10), mean_Tlevel1 = 0, sd_Tlevel1 = 1) expect_equal(TRUE, is.numeric(out)) }) + + +test_that("residuals computation for the niche model works", { + out <- residualsNicheProb(pars = c(1,1,1,1), + Tlevel1 = rnorm(10), + Tlevel2 = rnorm(10)) + expect_equal(TRUE, is.numeric(out)) +}) diff --git a/tests/testthat/test-useful.functions.R b/tests/testthat/test-useful.functions.R deleted file mode 100644 index f033fe9..0000000 --- a/tests/testthat/test-useful.functions.R +++ /dev/null @@ -1,12 +0,0 @@ -context("Useful functions") - -test_that("weigthed mean works", { - out <- weighted_mean(c(2,3,4), c(1,1,2)) - expect_equal(out, 3.25) -}) - -test_that("weigthed sd works", { - out <- weighted_sd(c(2,3,4), c(2,1,2)) - expect_equal(out, 1.118034) -}) - From c9226e815ba10a6d9d01c9ad4482560d3e4a6b1b Mon Sep 17 00:00:00 2001 From: Guillaume Blanchet Date: Thu, 9 Feb 2017 11:30:45 -0500 Subject: [PATCH 2/6] Added two other methods to implement in the package (C-scores and V-ratio) in the README file --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cd1f840..197d997 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Incoming content - binomial - poisson - RF -- Indirect matching centrality (latent \~ traits) (DG) +- Indirect matching centrality (latent ~ traits) (DG) - Niche binary (DG) - Niche probabilistic (DG) - iEat recommend (DB) @@ -28,6 +28,9 @@ Incoming content - 4th corner (GB) - Ben's magic (BW) - Ives' phylo (GB) +- Permutation methods (GB) + - C-scores + - V-ratio **Deadline:** Package ready by Christmas @@ -89,7 +92,7 @@ Contribute to this package - `git fetch` / `git pull` before you do anything else - new branches must be made from `master` -- if not, you are responsible for rebasing - good commit messages are 72 chars on the first line and explain what has been done in the imperative tone. A good rule of thumb is that if you say "If merged, this commit will" before the commit message, it should be a sentence. A good commit message is: `add informations about development practices`. A bad commit message is `CONTRIBUTING changes` -- if the branching complexity of your function is \> 3 (number of nested for / if / while), rewrite +- if the branching complexity of your function is > 3 (number of nested for / if / while), rewrite ### Styleguide @@ -100,9 +103,9 @@ Contribute to this package - all `roxygen2` flags (e.g. @param etc.) are to be set up. - R extension file has to be written in capital letter (e.g `fitBayesReg.R`) -Have a look at [](http://adv-r.had.co.nz/Style.html) +Have a look at -For further details on namespaces: [](http://r-pkgs.had.co.nz/namespace.html) +For further details on namespaces: License ------- From 7d3342f04eb015cd70b64088dd4d64dd5775a181 Mon Sep 17 00:00:00 2001 From: Steve Vissault Date: Fri, 17 Feb 2017 12:06:21 -0500 Subject: [PATCH 3/6] closed issue #23 - update badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 197d997..5564e90 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Status **Early development** **Version**: 0.0.1 -[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alienR.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alienR) [![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alienR/build/1.0.7) [![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alienR/branch/master/graphs/badge.svg)](https://codecov.io/gh/KevCaz/recruitR) +[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alienR.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alienR) [![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alienR/build/1.0.7) [![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alienR/branch/master/graph/badge.svg)](https://codecov.io/gh/TheoreticalEcosystemEcology/alienR) ALIEN: The aim of the package is to predict All Links In Ecological Networks ---------------------------------------------------------------------------- From 8b1af8a535f5cad3a957a78d96093bbe508d4ca7 Mon Sep 17 00:00:00 2001 From: Steve Vissault Date: Fri, 17 Feb 2017 12:11:50 -0500 Subject: [PATCH 4/6] change package name --- DESCRIPTION | 4 ++-- Readme.Rmd | 8 ++++---- tests/Testthat.R | 2 +- vignettes/BayesTutorial.Rmd | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 330e7e2..0ab8c4d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,4 +1,4 @@ -Package: alienR +Package: alien Type: Package Title: Comparative analysis of interaction inference methods Version: 0.0.1 @@ -31,7 +31,7 @@ Imports: SystemRequirements: none, one or more of JAGS (>= 4.0.0; (http://mcmc-jags.sourceforge.net)) NeedsCompilation: no License: MIT -BugReports: https://github.com/TheoreticalEcosystemEcology/alienR/issues +BugReports: https://github.com/TheoreticalEcosystemEcology/alien/issues Encoding: UTF-8 LazyData: true RoxygenNote: 5.0.1 diff --git a/Readme.Rmd b/Readme.Rmd index 6d61302..8d5815e 100644 --- a/Readme.Rmd +++ b/Readme.Rmd @@ -13,9 +13,9 @@ knitr::opts_chunk$set(echo = TRUE) **Early development** **Version**: 0.0.1 -[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alienR.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alienR) -[![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alienR/build/1.0.7) -[![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alienR/branch/master/graphs/badge.svg)](https://codecov.io/gh/KevCaz/recruitR) +[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alien.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alien) +[![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alien/build/1.0.7) +[![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alien/branch/master/graphs/badge.svg)](https://codecov.io/gh/KevCaz/recruitR) ## ALIEN: The aim of the package is to predict All Links In Ecological Networks @@ -85,7 +85,7 @@ devtools::test() All of the previous steps can be done with: ```bash -cd path/to/alienR +cd path/to/alien make ``` diff --git a/tests/Testthat.R b/tests/Testthat.R index 074e0c0..04b7d80 100644 --- a/tests/Testthat.R +++ b/tests/Testthat.R @@ -1,2 +1,2 @@ library(testthat) -test_check("alienR") +test_check("alien") diff --git a/vignettes/BayesTutorial.Rmd b/vignettes/BayesTutorial.Rmd index 455c17f..b98331f 100644 --- a/vignettes/BayesTutorial.Rmd +++ b/vignettes/BayesTutorial.Rmd @@ -6,16 +6,16 @@ output: html_document --- #Aim -A short tutorial explaining the different options for fitting hierarchical bayesian models for species interactions using the package alienR +A short tutorial explaining the different options for fitting hierarchical bayesian models for species interactions using the package alien ```{r} -library(alienR) +library(alien) library(ggplot2) library(knitr) opts_chunk$set(warning=F,message=F) #source scripts because I can't seem to understand how roxygen generates functions to the package! To delete once we understand how paths are handled in package creation -s<-sapply(list.files("C:/Users/Ben/Documents/alienR/R",pattern=".R",full.names = T),source) +s<-sapply(list.files("C:/Users/Ben/Documents/alien/R",pattern=".R",full.names = T),source) ``` # Simulate data @@ -68,7 +68,7 @@ ggplot(sumframe,aes(x=as.factor(I),y=J,fill=lower)) + geom_tile() + scale_fill_c If we want the distributions, instead of a summary we can plot the posterior predictions directly. For the sake of plotting, lets look at just one node. ```{r} -justB<-predframe %>% filter(I=="b") +justB<-predframe %>% filter(I=="b") ggplot(data=justB,aes(x=J,y=value)) + geom_boxplot(fill="black") + labs(y="Probability of interaction") + ggtitle("For Species B in the higher level") + theme_bw() ``` @@ -107,7 +107,7 @@ ggplot(sumframe,aes(x=as.factor(I),y=J,fill=lower)) + geom_tile() + scale_fill_c Create the same boxplot as in the intercept model ```{r} -justB<-predframe2 %>% filter(I=="b") +justB<-predframe2 %>% filter(I=="b") ggplot(data=justB,aes(x=J,y=value)) + geom_boxplot(fill="black") + labs(y="Probability of interaction") + ggtitle("For Species B in the higher level") + theme_bw() ``` @@ -135,4 +135,4 @@ allstats<-rbind_all(list(intercept_stats,binomial_stats)) ggplot(allstats,aes(x=nstat)) + geom_density(alpha=0.6,aes(fill=Model)) + facet_wrap(~Metric,scales='free',nrow=1) + theme_bw() + labs(x="value") ``` -Same data, different model, different network statistics! Models matter. \ No newline at end of file +Same data, different model, different network statistics! Models matter. From 89cb34fba73e36458493e2f2108f04c574c9ecfe Mon Sep 17 00:00:00 2001 From: Steve Vissault Date: Fri, 17 Feb 2017 12:19:49 -0500 Subject: [PATCH 5/6] remove Readme.Rmd; set badges --- README.md | 4 +-- Readme.Rmd | 101 ----------------------------------------------------- 2 files changed, 2 insertions(+), 103 deletions(-) delete mode 100644 Readme.Rmd diff --git a/README.md b/README.md index 5564e90..9bcb429 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Status **Early development** **Version**: 0.0.1 -[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alienR.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alienR) [![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alienR/build/1.0.7) [![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alienR/branch/master/graph/badge.svg)](https://codecov.io/gh/TheoreticalEcosystemEcology/alienR) +[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alienR.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alienR) [![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alienR/build/1.0.7) [![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alien/branch/master/graphs/badge.svg)](https://codecov.io/gh/KevCaz/recruitR) ALIEN: The aim of the package is to predict All Links In Ecological Networks ---------------------------------------------------------------------------- @@ -78,7 +78,7 @@ devtools::test() All of the previous steps can be done with: ``` bash -cd path/to/alienR +cd path/to/alien make ``` diff --git a/Readme.Rmd b/Readme.Rmd deleted file mode 100644 index 8d5815e..0000000 --- a/Readme.Rmd +++ /dev/null @@ -1,101 +0,0 @@ ---- -output: - md_document: - variant: markdown_github ---- - -```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -``` - -## Status - -**Early development** -**Version**: 0.0.1 - -[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alien.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alien) -[![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alien/build/1.0.7) -[![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alien/branch/master/graphs/badge.svg)](https://codecov.io/gh/KevCaz/recruitR) - - -## ALIEN: The aim of the package is to predict All Links In Ecological Networks - -## Incoming content - -### Methods - -- Direct matching centrality (DG) - - binomial - - poisson - - RF -- Indirect matching centrality (latent ~ traits) (DG) -- Niche binary (DG) -- Niche probabilistic (DG) -- iEat recommend (DB) -- iEat gap-filling (DB) -- JSDM (GB) -- Harris (KC) -- Markov logic (A.T.?) -- 4th corner (GB) -- Ben's magic (BW) -- Ives' phylo (GB) - -**Deadline:** Package ready by Christmas - -## Generate package metadata - -All enhancements to the README has to be written in the Readme.Rmd file. - -To build the metadata files (i.e. README, NAMESPACE, DESCRIPTION): - -```{r, eval=FALSE, results='asis'} -ipak <- function(pkg){ - new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])] - if (length(new.pkg)) - install.packages(new.pkg, dependencies = TRUE) - sapply(pkg, require, character.only = TRUE) -} - -## Install packages -pkgs = c('devtools','roxygen2','testthat','formatR','rmarkdown') -ipak(pkgs) - -## Make sure you're working directory is set up at path/to/alien/folder -getwd() - -## Create README file -rmarkdown::render("README.Rmd", "all", quiet=TRUE) - -## Format the R code (e.g. indentation, assignment, etc.) -formatR::tidy_dir("./R",arrow = getOption("formatR.arrow",TRUE)) -formatR::tidy_dir("./tests/test_that", arrow = getOption("formatR.arrow",TRUE)) - -## Load your current version of the package -devtools::load_all(".") - -## Create man pages -devtools::document(".") - -## Testing the code with testthat package -devtools::test() -``` - -### Only for the developers on Mac OSX and linux - -All of the previous steps can be done with: - -```bash -cd path/to/alien -make -``` - -## Contribute to this package - - -```{r child = 'CONTRIBUTING.md'} -``` - -## License - -```{r child = 'LICENSE'} -``` From d4e1bf7df8f2f231eae8ce45636b412dc25073d3 Mon Sep 17 00:00:00 2001 From: Steve Vissault Date: Fri, 17 Feb 2017 12:21:35 -0500 Subject: [PATCH 6/6] set badges 2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bcb429..e75b96f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Status **Early development** **Version**: 0.0.1 -[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alienR.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alienR) [![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alienR/build/1.0.7) [![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alien/branch/master/graphs/badge.svg)](https://codecov.io/gh/KevCaz/recruitR) +[![Travis](https://travis-ci.org/TheoreticalEcosystemEcology/alienR.svg?branch=master)](https://travis-ci.org/TheoreticalEcosystemEcology/alienR) [![Build status](https://ci.appveyor.com/api/projects/status/sk3sbvusvcyy0at0?svg=true)](https://ci.appveyor.com/project/TheoreticalEcosystemEcology/alienR/build/1.0.7) [![codecov](https://codecov.io/gh/TheoreticalEcosystemEcology/alien/branch/master/graph/badge.svg)](https://codecov.io/gh/TheoreticalEcosystemEcology/alien) ALIEN: The aim of the package is to predict All Links In Ecological Networks ----------------------------------------------------------------------------