Skip to content

Commit

Permalink
Possible fix for CRAN check errors on non windows systems
Browse files Browse the repository at this point in the history
  • Loading branch information
BartJanvanRossum committed Sep 16, 2024
1 parent 2505ff2 commit 0d035e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions R/f_dc_CA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test_dcca.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 0d035e5

Please sign in to comment.