From 07f1857f9d7807b43daecaa17a6b0d640524c675 Mon Sep 17 00:00:00 2001 From: Jari Oksanen Date: Tue, 16 Aug 2016 21:45:06 +0300 Subject: [PATCH] goodness.cca failed for rank=1 component reported as issue #189 in github --- R/goodness.cca.R | 8 ++++++-- R/inertcomp.R | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/goodness.cca.R b/R/goodness.cca.R index cf968471c..c21eb2fc3 100644 --- a/R/goodness.cca.R +++ b/R/goodness.cca.R @@ -33,8 +33,12 @@ else pCCA <- diag(crossprod(pCCA))/nr } - CA <- t(apply(diag(w) %*% CA^2 %*% diag(eig), 1, - cumsum)) + CA <- t(apply( + diag(w, length(w)) %*% CA^2 %*% diag(eig, length(eig)), + 1, cumsum)) + ## rank=1 solutions comes out transposed: back transpose + if (length(eig) == 1) + CA <- t(CA) totals <- inertcomp(object, display = display) comps <- colnames(totals) if (statistic == "explained") { diff --git a/R/inertcomp.R b/R/inertcomp.R index e6591d3ae..c3acc1d99 100644 --- a/R/inertcomp.R +++ b/R/inertcomp.R @@ -40,9 +40,11 @@ pCCA <- diag(crossprod(pCCA))/nr } if (!is.null(CCA)) - CCA <- rowSums(diag(w) %*% CCA^2 %*% diag(object$CCA$eig)) + CCA <- rowSums(diag(w, length(w)) %*% CCA^2 %*% + diag(object$CCA$eig, length(object$CCA$eig))) if (!is.null(CA)) - CA <- rowSums(diag(w) %*% CA^2 %*% diag(object$CA$eig)) + CA <- rowSums(diag(w, length(w)) %*% CA^2 %*% + diag(object$CA$eig, length(object$CA$eig))) out <- cbind(pCCA, CCA, CA) if (statistic == "distance" && !proportional) { w <- weights(object, display = display)