Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ Carlson committed Feb 9, 2019
2 parents f0371dc + f24f661 commit 4126db6
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 223 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ $RECYCLE.BIN/
# Operating System Files
# =========================
.Rproj.user
README.Rmd
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ Description: An R package for estimating affiliate species richness based on pow
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
Depends: ggplot2,
EnvStats
Imports: EnvStats,
ggplot2,
stats,
Imports: stats,
graphics,
nlstools
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(binera)
export(binera.50)
export(copredict)
export(copredict.ci)
export(curve.50)
export(curve.df)
import(EnvStats)
import(ggplot2)
Expand Down
5 changes: 3 additions & 2 deletions R/binera.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
#' @param assoc.df The raw dataset of associations (pairs of names in two columns, hosts and affiliates)
#' @param iter Number of iterations required for each subsample
#' @param plots Do you want plots? Maybe you do. The world is your oyster.
#' @param subSample Fraction of host species to subsample (default=NULL, use all data)
#'
#' @export


binera <- function(assoc.df, iter, plots=FALSE) {
binera <- function(assoc.df, iter, plots=FALSE, subSample=NULL) {

n.host <- n.par <- host <- pred <- 0

c <- curve.df(assoc.df, iter)
c <- curve.df(assoc.df, iter, subSample=subSample)
model1 <- stats::nls(n.par~b*n.host^z,start = list(b = 1, z = 0.5),data=c)

if(plots==TRUE) {
Expand Down
28 changes: 0 additions & 28 deletions R/binera50.R

This file was deleted.

17 changes: 8 additions & 9 deletions R/copredict.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#'
#'
#' @importFrom stats nls
#' @importFrom stats sd
#' @importFrom stats qt
#' @importFrom stats coef
#' @importFrom graphics hist
#' @importFrom graphics par
#'

#' @title Extrapolating richness via curve-fitting
#'
#' @description
Expand All @@ -19,6 +11,13 @@
#' @param plot (boolean; default is TRUE) plot results?
#'
#' @details
#'
#' @importFrom stats nls
#' @importFrom stats sd
#' @importFrom stats qt
#' @importFrom stats coef
#' @importFrom graphics hist
#' @importFrom graphics par
#'
#' @export

Expand Down
7 changes: 5 additions & 2 deletions R/copredict50.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
#' @param iter1 Set the number of times to fit a curve
#' @param iter2 Set the number of points to subsample at each host richness within the generation of each curve
#' @param plot (boolean; default is TRUE) plot results?
#' @param subSample Fraction of host species to subsample (default=NULL, use all data)
#'
#'
#' @details
#' @export


copredict.ci <- function(assoc.df, n.indep, iter, plot=TRUE) {
copredict.ci <- function(assoc.df, n.indep, iter,
plot=TRUE, subSample=0.5) {

model <- binera.50(assoc.df, iter)
model <- binera(assoc.df, iter, subSample)
q <- stats::coef(model)
p.cis <- nlstools::confint2(model)

Expand Down
52 changes: 40 additions & 12 deletions R/curvedf.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,63 @@
#' @title Subsampling of entire network
#'
#' @description
#' This function iteratively samples the entire network and generates a data frame with sub-sample host and affilaite richness tallied together
#' This function iteratively samples the entire network and generates
#' a data frame with sub-sample host and affilaite richness tallied together
#'
#' @param assoc.df The raw dataset of associations (pairs of names in two columns, hosts and affiliates)
#' @param iter Number of iterations required for each subsample
#' @param assoc.df The raw dataset of associations (pairs of names in
#' two columns, hosts and affiliates)
#'
#' @param iter Number of iterations required for each subsample
#' @param subSample Fraction of host species to subsample for richness estimation
#' @export

<<<<<<< HEAD
curve.df <- function(assoc.df, iter, subSample=0){
=======
curve.df <- function(assoc.df, iter, subSample=NULL){

if(!is.null(subSample)){
hostlist <- unique(assoc.df[,1])
hostCut <- sample(hostlist, round(subSample*hostlist,0), replace = FALSE)
assoc.df <- assoc.df[assoc.df[,1] %in% hostCut,]
}
>>>>>>> origin/master

# placeholder: Tad add subsample at this level because you didn't
u.hosts <- unique(assoc.df[,1])
n.hosts <- length(u.hosts)

results.df <- data.frame(n.host=0,n.par=0)
results.df <- results.df[-1,]
oneSp <- function(x, i=iter){
df<- vapply(1:iter, FUN.VALUE=c(double(1), double(1)),
function(a){
sub.hosts <- sample(u.hosts, x)
sub.df <- assoc.df[assoc.df[,1] %in% sub.hosts,]
u.par <- unique(sub.df[,2])
n.par <- length(u.par)
return(c(x, n.par))
})
return(t(df))
}

results.df <- lapply(1:n.hosts,
oneSp, i=iter)
ret <- do.call(rbind, results.df)
colnames(ret) <- c('n.host', 'n.par')
return(ret)
}




for (i in 1:n.hosts) {
#for (i in 1:5) {
for (j in 1:iter) {

sub.hosts <- sample(u.hosts,i)
sub.df <- assoc.df[assoc.df[,1] %in% sub.hosts,]
u.par <- unique(sub.df[,2])
n.par <- length(u.par)

<<<<<<< HEAD
results.df[nrow(results.df)+1,] <- c(i, n.par)
}
#print(i)
}
results.df <- data.frame(results.df)
return(results.df)
}
=======
>>>>>>> origin/master
39 changes: 0 additions & 39 deletions R/curvedf50.R

This file was deleted.

35 changes: 0 additions & 35 deletions README.RMd

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Author

Colin J. Carlson ([email protected])

(Contributions by Tad Dallas!)

Installing the package
----------------------

Expand Down
16 changes: 0 additions & 16 deletions man/binera.50.Rd

This file was deleted.

4 changes: 3 additions & 1 deletion man/binera.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 3 additions & 16 deletions man/copredict.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4126db6

Please sign in to comment.