Skip to content

Commit

Permalink
Revert "use natural way of calculationg RsquareAdj for cca: conflicts…
Browse files Browse the repository at this point in the history
… varpart"

This reverts commit 6ac3365.

see github issue #295
  • Loading branch information
Jari Oksanen committed Jan 27, 2019
1 parent 943408c commit 6201d51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
30 changes: 20 additions & 10 deletions R/RsquareAdj.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,30 @@
list(r.squared = R2, adj.r.squared = radj)
}

## 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.
## cca result: RsquareAdj is calculated similarly as in
## varpart(). This is similar "semipartial" model as for rda() and
## found as a difference of R2-adj values of combined model with
## constraints + conditions and only conditions.
`RsquareAdj.cca` <-
function (x, permutations = 1000, ...)
{
r2 <- x$CCA$tot.chi / x$tot.chi
## 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))
if (is.null(x$pCCA)) {
p <- permutest(x, permutations, ...)
radj <- 1 - ((1 - r2) / (1 - mean(p$num / x$tot.chi)))
} else {
p <- getPermuteMatrix(permutations, nobs(x))
Y <- ordiYbar(x, "initial")
r2tot <- (x$pCCA$tot.chi + x$CCA$tot.chi) / x$tot.chi
r2null <- mean(sapply(seq_len(nrow(p)), function(i)
sum(qr.fitted(x$CCA$QR, Y[p[i,],])^2)))
r2tot <- 1 - ((1-r2tot)/(1-r2null/x$tot.chi))
r2p <- x$pCCA$tot.chi / x$tot.chi
r2null <- mean(sapply(seq_len(nrow(p)), function(i)
sum(qr.fitted(x$pCCA$QR, Y[p[i,],])^2)))
r2p <- 1 - ((1-r2p)/(1-r2null/x$tot.chi))
radj <- r2tot - r2p
}
list(r.squared = r2, adj.r.squared = radj)
}

Expand Down
9 changes: 5 additions & 4 deletions man/RsquareAdj.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ Adjusted R-square
R-squared for a cca. The permutations can be calculated in parallel by
specifying the number of cores which is passed to \code{\link{permutest}}}

\item{\dots}{ Other arguments (ignored) except in the \code{cca}
method, where these are passed to \code{\link{permutest.cca}}.
}
\item{\dots}{ Other arguments (ignored) except in the case of cca in
which these arguments are passed to \code{\link{permutest}}.}
}

\details{ The default method finds the adjusted \eqn{R^2}{R-squared}
Expand All @@ -50,7 +49,9 @@ Adjusted R-square
\code{\link{glm}}.

The adjusted, \eqn{R^2}{R-squared} of \code{cca} is computed using a
permutation approach developed by Peres-Neto et al. (2006).
permutation approach developed by Peres-Neto et al. (2006). By
default 1000 permutations are used. Adjusted \eqn{R^2}{R-squared} is
not calculated for partial CCA.

}

Expand Down

0 comments on commit 6201d51

Please sign in to comment.