Skip to content

Commit

Permalink
Revert "disable adjusted R2 for partial ordination (pRDA, pCCA)"
Browse files Browse the repository at this point in the history
This reverts commit 32fd2e0.

see github issue #295
  • Loading branch information
Jari Oksanen committed Jan 27, 2019
1 parent 6617fca commit 943408c
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions R/RsquareAdj.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
r2
}

## rda. Function varpart() estimates adjusted R2 for partial model
## rda(Y, X1, X2) as a difference of adjusted R2 values of models
## rda(Y, cbind(X1,X2)) and rda(Y, X2), and we did the same here from
## vegan release 2.0-3 to 2.4. However, I am not quite convinced that
## this is correct, and therefore I disable adjusted R2 for partial
## models while I study the issue (Jari Oksanen, 23/2/2018). If you
## change handling of partial models, remember to update ordiR2step!
## Use this with rda() results
`RsquareAdj.rda` <-
function(x, ...)
{
Expand All @@ -30,25 +24,29 @@
if (is.null(x$pCCA)) {
radj <- RsquareAdj(R2, n, m)
} else {
radj <- NA
## Partial model: same adjusted R2 as for component [a] in two
## source varpart model
R2p <- x$pCCA$tot.chi/x$tot.chi
p <- x$pCCA$QR$rank
radj <- RsquareAdj(R2 + R2p, n, m + p) - RsquareAdj(R2p, n, p)
}
list(r.squared = R2, adj.r.squared = radj)
}

## cca: for pCCA, see comment for rda. Earlier we used the same
## equation both for pCCA and CCA which was inconsistent with rda. git
## commit 9c25e6fdb4 has a version that was consistent with rda in
## vegan 2.0-3 to 2.4-6.
## cca result: R2_adj calculation for partial models differs from
## varpart(), where it is assessed as difference of R2_adj values for
## conditions and constraints. Here we use difference of unadjusted R2
## values, and adjust that difference.
`RsquareAdj.cca` <-
function (x, permutations = 1000, ...)
{
r2 <- x$CCA$tot.chi / x$tot.chi
if (is.null(x$pCCA) || x$pCCA$rank == 0) {
p <- permutest(x, permutations, ...)
radj <- 1 - ((1 - r2) / (1 - mean(p$num) / x$tot.chi))
} else {
radj <- NA
}
## model='direct' makes a difference in pCCA: it guarantees that
## dependent data are permuted in the same way in the partial and
## constrained components so that we can take their difference for
## the correction term.
p <- permutest(x, permutations, model = "direct")
radj <- 1 - ((1 - r2) / (1 - mean(p$num) / x$tot.chi))
list(r.squared = r2, adj.r.squared = radj)
}

Expand Down

0 comments on commit 943408c

Please sign in to comment.