From f4ee4dfde07cdb201cb0b0d172da7131981102d0 Mon Sep 17 00:00:00 2001 From: rhijmans Date: Wed, 6 Dec 2023 10:00:07 -0800 Subject: [PATCH] for #1361 --- R/princomp.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/princomp.R b/R/princomp.R index ad8deca52..83bfbab13 100644 --- a/R/princomp.R +++ b/R/princomp.R @@ -3,14 +3,14 @@ setMethod("princomp", signature(x="SpatRaster"), function(x, cor=FALSE, fix_sign=TRUE) { stopifnot(nlyr(x) > 1) - xcov <- layerCor(x, fun="cov", na.rm=TRUE) + xcov <- layerCor(x, fun="cov", na.rm=TRUE, asSample=FALSE) model <- princomp(covmat=xcov$covariance, cor=cor, fix_sign=fix_sign) model$center <- diag(xcov$mean) n <- diag(xcov$n) if (cor) { - ## Scale as population sd, like in in princomp + ## scale as population sd S <- diag(xcov$covariance) - model$scale <- sqrt(S * (n-1) / n) + model$scale <- sqrt(S) } model$n.obs <- as.dist(xcov$n) model