From 0d035e586d527f75b4ddc36b851585fff4db37a3 Mon Sep 17 00:00:00 2001 From: Bart-Jan van Rossum Date: Mon, 16 Sep 2024 15:06:38 +0200 Subject: [PATCH] Possible fix for CRAN check errors on non windows systems --- R/f_dc_CA.R | 16 +++++++++++----- inst/tinytest/test_dcca.R | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/f_dc_CA.R b/R/f_dc_CA.R index bc02ce4..2ecf06c 100644 --- a/R/f_dc_CA.R +++ b/R/f_dc_CA.R @@ -74,18 +74,24 @@ calculate_b_se_tval <- function(X_or_qr_decomp_of_X, out1 <- fitted_values } else { if (any(is.na(beta_hat))) { - warning("collinearity detected in ", name, "-model.\n") + warning("collinearity detected in ", name, "-model.\n", call. = FALSE) } # Compute residual sum of squares (RSS) RSS <- colSums(residuals ^ 2) # Estimate variance of the errors n <- length(w) p <- QR$rank - sigma_hat_sq <- RSS / (n - p - 1 ) + sigma_hat_sq <- RSS / (n - p - 1) # Calculate variance-covariance matrix of the estimated regression coefficients - XtXinv <- chol2inv(QR$qr) - diagXtX_inv <- diag(chol2inv(QR$qr)) - names(diagXtX_inv) <- colnames(QR$qr) + diagXtX_inv <- diag(chol2inv(QR$qr, size = p)) + naBetaHat <- apply(X = beta_hat, MARGIN = 1, FUN = function(x) all(is.na(x))) + if (sum(naBetaHat) > 0) { + diagXtX_inv <- c(diagXtX_inv, rep(NA, times = sum(naBetaHat))) + names(diagXtX_inv) <- c(colnames(QR$qr)[!naBetaHat], + rownames(beta_hat)[naBetaHat]) + } else { + names(diagXtX_inv) <- colnames(QR$qr) + } diagXtX_inv <- diagXtX_inv[rownames(beta_hat)] se <- matrix(nrow = nrow(beta_hat), ncol = length(sigma_hat_sq)) for (i in seq_along(sigma_hat_sq)) { diff --git a/inst/tinytest/test_dcca.R b/inst/tinytest/test_dcca.R index f08dca4..956f68c 100644 --- a/inst/tinytest/test_dcca.R +++ b/inst/tinytest/test_dcca.R @@ -46,7 +46,7 @@ expect_message(mod_dcca3 <- dc_CA(formulaEnv = ~ A1 + Moist + Mag + Use + Manure verbose = FALSE), "Some constraints or conditions were aliased because they were redundant") -expect_warning(scores(mod_dcca3),"collinearity detected in SNC-model") +expect_warning(scores(mod_dcca3), "collinearity detected in SNC-model") expect_inherits(mod_dcca, "dcca") expect_equal_to_reference(mod_dcca, "mod_dcca")