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