Skip to content

Commit

Permalink
for #1361
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 6, 2023
1 parent d2d9c1a commit f4ee4df
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/princomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f4ee4df

Please sign in to comment.