Skip to content

Commit

Permalink
Merge branch 'x-in-designdist'
Browse files Browse the repository at this point in the history
  • Loading branch information
jarioksa committed Jan 17, 2025
2 parents 32037c6 + 33e609a commit 26b6fbc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions R/designdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
if (terms == "binary")
x <- ifelse(x > 0, 1, 0)
if (terms == "binary" || terms == "quadratic")
x <- tcrossprod(x)
XX <- tcrossprod(x)
if (terms == "minimum")
x <- .Call(do_minterms, as.matrix(x))
d <- diag(x)
XX <- .Call(do_minterms, as.matrix(x))
d <- diag(XX)
A <- as.dist(outer(rep(1, N), d))
B <- as.dist(outer(d, rep(1, N)))
J <- as.dist(x)
J <- as.dist(XX)
## 2x2 contingency table notation
if (abcd) {
a <- J
Expand Down
11 changes: 8 additions & 3 deletions man/designdist.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ chaodist(x, method = "1 - 2*U*V/(U+V)", name)
number of columns (species) or in \code{chaodist} it can use terms
\code{U} and \code{V}. The equation can also contain any \R
functions that accepts vector arguments and returns vectors of the
same length. }
same length. It can also include functions of input \code{x} that
return a scalar or a \code{dist} vector.}
\item{terms}{How shared and total components are found. For vectors
\code{x} and \code{y} the \code{"quadratic"} terms are \code{J = sum(x*y)},
\code{A = sum(x^2)}, \code{B = sum(y^2)}, and \code{"minimum"} terms
Expand Down Expand Up @@ -162,18 +163,22 @@ chaodist(x, method = "1 - 2*U*V/(U+V)", name)
large when the number of columns is high, and particularly large with
quadratic terms. For precise calculations it is better to use
functions like \code{\link{dist}} and \code{\link{vegdist}} which are
more robust against numerical problems.
moqre robust against numerical problems.
}

\seealso{ \code{\link{vegdist}}, \code{\link{betadiver}}, \code{\link{dist}},
\code{\link{raupcrick}}.}
\examples{
data(BCI)
## Four ways of calculating the same Sørensen dissimilarity
## Five ways of calculating the same Sørensen dissimilarity
d0 <- vegdist(BCI, "bray", binary = TRUE)
d1 <- designdist(BCI, "(A+B-2*J)/(A+B)")
d2 <- designdist(BCI, "(b+c)/(2*a+b+c)", abcd = TRUE)
d3 <- designdist(BCI, "gamma/alpha - 1", alphagamma = TRUE)
d4 <- designdist(BCI, "dist(x, 'manhattan')/(A+B)")
## Zero-adjusted Bray-Curtis of Clarke et al. (J Exp Marine Biol & Ecol
## 330:55-80; 2006)
dbr0 <- designdist(BCI, "(A+B-2*J)/(A+B+2*min(x[x>0]))", terms = "minimum")
## Arrhenius dissimilarity: the value of z in the species-area model
## S = c*A^z when combining two sites of equal areas, where S is the
## number of species, A is the area, and c and z are model parameters.
Expand Down
8 changes: 6 additions & 2 deletions tests/Examples/vegan-Ex.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -2480,11 +2480,15 @@ Icmaeric Cladcerv Claddefo Cladphyl
> ### ** Examples
>
> data(BCI)
> ## Four ways of calculating the same Sørensen dissimilarity
> ## Five ways of calculating the same Sørensen dissimilarity
> d0 <- vegdist(BCI, "bray", binary = TRUE)
> d1 <- designdist(BCI, "(A+B-2*J)/(A+B)")
> d2 <- designdist(BCI, "(b+c)/(2*a+b+c)", abcd = TRUE)
> d3 <- designdist(BCI, "gamma/alpha - 1", alphagamma = TRUE)
> d4 <- designdist(BCI, "dist(x, 'manhattan')/(A+B)")
> ## Zero-adjusted Bray-Curtis of Clarke et al. (J Exp Marine Biol & Ecol
> ## 330:55-80; 2006)
> dbr0 <- designdist(BCI, "(A+B-2*J)/(A+B+2*min(x[x>0]))", terms = "minimum")
> ## Arrhenius dissimilarity: the value of z in the species-area model
> ## S = c*A^z when combining two sites of equal areas, where S is the
> ## number of species, A is the area, and c and z are model parameters.
Expand Down Expand Up @@ -9142,7 +9146,7 @@ Procrustes sum of squares:
> cleanEx()
> options(digits = 7L)
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
Time elapsed: 8.684 0.353 9.056 0 0
Time elapsed: 8.741 0.323 9.079 0 0
> grDevices::dev.off()
null device
1
Expand Down

0 comments on commit 26b6fbc

Please sign in to comment.