Skip to content

Commit

Permalink
Merge branch 'issue-#610'
Browse files Browse the repository at this point in the history
  • Loading branch information
jarioksa committed Dec 6, 2023
2 parents 29bd5b3 + f8f5221 commit 003391b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion R/RsquareAdj.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
function (x, permutations = 1000, ...)
{
r2 <- x$CCA$tot.chi / x$tot.chi
if (is.null(x$pCCA)) {
if (df.residual(x) == 0) {
radj <- NA
} else if (is.null(x$pCCA)) {
p <- permutest(x, permutations, ...)
radj <- 1 - ((1 - r2) / (1 - mean(p$num / x$tot.chi)))
} else {
Expand Down
3 changes: 3 additions & 0 deletions R/ordConstrained.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@
}
## Residuals
resid <- ordResid(Y)
if (resid$rank < 1)
warning("overfitted model with no unconstrained component",
call. = FALSE)
## return a CCA object
out <- c(head,
call = match.call(),
Expand Down
4 changes: 2 additions & 2 deletions R/ordiR2step.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
R2.all <- list(adj.r.squared = NA)
## Check that the full model can be evaluated
if (is.na(R2.all$adj.r.squared) && R2scope)
stop("the upper scope cannot be fitted (too many terms?)")
stop("R2 cannot be adjusted in upper scope (too many terms?)")
R2.all <- R2.all$adj.r.squared
## Collect data to anotab returned as the 'anova' object
anotab <- list()
Expand All @@ -58,7 +58,7 @@
fla <- paste(". ~ .", names(R2.adds[trm]))
R2.tmp <- RsquareAdj(update(object, fla),
permutations = R2permutations, ...)$adj.r.squared
if (!length(R2.tmp))
if (!length(R2.tmp) || is.na(R2.tmp))
R2.tmp <- 0
R2.adds[trm] <- R2.tmp
}
Expand Down
21 changes: 11 additions & 10 deletions man/ordistep.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ ordiR2step(object, scope, Pin = 0.05, R2scope = TRUE,
step, and stopping when the adjusted \eqn{R^2}{R2} starts to decrease,
or the adjusted \eqn{R^2}{R2} of the \code{scope} is exceeded, or the
selected permutation \eqn{P}-value is exceeded (Blanchet et
al. 2008). The second criterion is ignored with option
\code{R2scope = FALSE}, and the third criterion can be ignored setting
\code{Pin = 1} (or higher).
The function cannot be used if adjusted \eqn{R^2}{R2}
cannot be calculated, including partial models. If the number of
predictors is higher than the number of observations, adjusted
\eqn{R^2}{R2} is also unavailable, but such models can be analysed
with \code{R2scope = FALSE}. The \eqn{R^2}{R2} of \code{\link{cca}}
is based on simulations (see \code{\link{RsquareAdj}}) and different
runs of \code{ordiR2step} can give different results.
al. 2008). The second criterion is ignored with option \code{R2scope =
FALSE}, and the third criterion can be ignored setting \code{Pin = 1}
(or higher). The function cannot be used if adjusted \eqn{R^2}{R2}
cannot be calculated. If the number of predictors is higher than the
number of observations, adjusted \eqn{R^2}{R2} is also unavailable.
Such models can be analysed with \code{R2scope = FALSE}, but the
variable selection will stop if models become overfitted and adjusted
\eqn{R^2}{R2} cannot be calculated, and the adjusted \eqn{R^2}{R2}
will be reported as zero. The \eqn{R^2}{R2} of \code{\link{cca}} is
based on simulations (see \code{\link{RsquareAdj}}) and different runs
of \code{ordiR2step} can give different results.

Functions \code{ordistep} (based on \eqn{P} values) and \code{ordiR2step}
(based on adjusted \eqn{R^2}{R2} and hence on eigenvalues) can select
Expand Down

0 comments on commit 003391b

Please sign in to comment.