Skip to content

Commit

Permalink
Merge branch 'one-species-accumulation': fixes issue #501
Browse files Browse the repository at this point in the history
  • Loading branch information
jarioksa committed Mar 11, 2022
2 parents 4d8d153 + ee2e591 commit 6a5f9b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 3 additions & 2 deletions R/plot.specaccum.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
if (!add) {
if (missing(ylim))
if (random)
ylim <- c(1, max(x$perm, na.rm = TRUE))
ylim <- c(min(1, x$perm), max(x$perm, na.rm = TRUE))
else
ylim <- c(1, max(x$richness, x$richness + ci*x$sd, na.rm = TRUE))
ylim <- c(min(1, x$richness),
max(x$richness, x$richness + ci*x$sd, na.rm = TRUE))
plot(xaxvar, x$richness, xlab=xlab, ylab=ylab, ylim=ylim,
type="n", ...)
}
Expand Down
13 changes: 4 additions & 9 deletions R/specaccum.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@
x <- x[, colSums(x) > 0, drop=FALSE]
n <- nrow(x)
p <- ncol(x)
if (p == 1) {
x <- t(x)
n <- nrow(x)
p <- ncol(x)
}
accumulator <- function(x, ind) {
rowSums(apply(x[ind, ], 2, cumsum) > 0)
rowSums(apply(x[ind, , drop=FALSE], 2, cumsum) > 0)
}
specaccum <- sdaccum <- sites <- perm <- NULL
if (n == 1 && method != "rarefaction")
message("no actual accumulation since only one site provided")
switch(method, collector = {
sites <- 1:n
sites <- seq_len(n)
xout <- weights <- cumsum(w)
specaccum <- accumulator(x, sites)
perm <- as.matrix(specaccum)
Expand All @@ -37,7 +32,7 @@
perm <- apply(permat, 1, accumulator, x = x)
if (!is.null(w))
weights <- as.matrix(apply(permat, 1, function(i) cumsum(w[i])))
sites <- 1:n
sites <- seq_len(n)
if (is.null(w)) {
specaccum <- apply(perm, 1, mean)
sdaccum <- apply(perm, 1, sd)
Expand Down Expand Up @@ -99,7 +94,7 @@
result[i, ] <- (1 - i/n)^freq
}
result <- 1 - result
sites <- 1:n
sites <- seq_len(n)
specaccum <- rowSums(result)
sdaccum <- sqrt(rowSums(result * (1 - result)))
})
Expand Down

0 comments on commit 6a5f9b3

Please sign in to comment.