Skip to content

Commit

Permalink
qr.X could fail with too many aliased variables: fixes issue #452
Browse files Browse the repository at this point in the history
model.matrix fails if the full model matrix has more columns than
there are observations, but number of non-aliased parameters was
lower than the number observations. This typically happens with
models with high-order interactions. This was reported for marginal
models in adonis2 (issue #452) but also affects constrained
ordination methods (rda, cca, dbrda) in anova with by="margin" or
by="axis".
  • Loading branch information
jarioksa committed May 6, 2023
1 parent 1394238 commit a64ed4e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/model.matrix.cca.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
X <- Z <- NULL
w <- 1/sqrt(object$rowsum)
if (!is.null(object$pCCA))
Z <- w * qr.X(object$pCCA$QR)
Z <- w * qr.X(object$pCCA$QR, ncol = length(object$pCCA$QR$pivot))
if (!is.null(object$CCA)) {
X <- qr.X(object$CCA$QR)
X <- qr.X(object$CCA$QR, ncol = length(object$CCA$QR$pivot))
## First columns come from Z
if (!is.null(Z))
X <- X[, -seq_len(ncol(Z)), drop = FALSE]
Expand All @@ -27,9 +27,9 @@
{
X <- Z <- NULL
if (!is.null(object$pCCA))
Z <- qr.X(object$pCCA$QR)
Z <- qr.X(object$pCCA$QR, ncol = length(object$pCCA$QR$pivot))
if (!is.null(object$CCA)) {
X <- qr.X(object$CCA$QR)
X <- qr.X(object$CCA$QR, ncol = length(object$CCA$QR$pivot))
if (!is.null(Z))
X <- X[, -seq_len(ncol(Z)), drop=FALSE]
}
Expand Down

0 comments on commit a64ed4e

Please sign in to comment.