Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 8, 2023
1 parent 6e0f011 commit 1ba3abc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions R/princomp.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@


setMethod("princomp", signature(x="SpatRaster"),
function(x, cor=FALSE, fix_sign=TRUE, use="pairwise.complete.obs") {
function(x, cor=FALSE, fix_sign=TRUE, use="pairwise.complete.obs", maxcell=Inf) {

if (!hasValues(x)) {
error("princomp", "x has no values")
}
if (nlyr(x) < 2) {
error("princomp", "The number of layers of x must be > 1")
}
xcov <- layerCor(x, fun="cov", use=use, asSample=FALSE)
xcov <- layerCor(x, fun="cov", use=use, asSample=FALSE, maxcell=maxcell)
if (any(is.na(xcov[["covariance"]]))) {
error("princomp", "the covariance matrix has missing values")
}
Expand Down
2 changes: 1 addition & 1 deletion man/layerCor.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Compute correlation, (weighted) covariance, or similar summary statistics that c

\item{use}{character. To decide how to handle missing values. This must be (an abbreviation of) one of "everything", "complete.obs", "pairwise.complete.obs", "masked.complete". With "pairwise.complete.obs", the value for a pair of layers is computed for all cells that are not \code{NA} in that pair. Therefore, it may be that the (number of) cells used varies between pairs. The benefit of this approach is that all available data is used. Use "complete.obs", if you want to only use the values from cells that are not \code{NA} in any of the layers. By using "masked.complete" you indicate that all layers have NA values in the same cells}

\item{maxcell}{positive integer. The number of cells to be regularly sampled. Only used when \code{fun} is a function}
\item{maxcell}{positive integer. The maximum number of cells to be used. If this is smaller than ncell(x), a regular sample of \code{x} is used}

\item{...}{additional arguments for \code{fun} (if it is a proper function)}
}
Expand Down
3 changes: 2 additions & 1 deletion man/princomp.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ Alternatively, you can use \code{stats::\link[stats]{princomp}} or \code{stats::
}

\usage{
\S4method{princomp}{SpatRaster}(x, cor=FALSE, fix_sign=TRUE, use="pairwise.complete.obs")
\S4method{princomp}{SpatRaster}(x, cor=FALSE, fix_sign=TRUE, use="pairwise.complete.obs", maxcell=Inf)
}

\arguments{
\item{x}{SpatRaster}
\item{cor}{logical. If \code{FALSE}, the covariance matrix is used. Otherwise the correlation matrix is used}
\item{fix_sign}{logical. If \code{TRUE}, the signs of the loadings and scores are chosen so that the first element of each loading is non-negative}
\item{use}{character. To decide how to handle missing values. This must be (an abbreviation of) one of the strings "everything", "complete.obs", "pairwise.complete.obs", or "masked.complete". With "pairwise.complete.obs", the covariance between a pair of layers is computed for all cells that are not \code{NA} in that pair. Therefore, it may be that the (number of) cells used varies between pairs. The benefit of this approach is that all available data is used. Use "complete.obs", if you want to only use the values from cells that are not \code{NA} in any of the layers. By using "masked.complete" you indicate that all layers have NA values in the same cells}
\item{maxcell}{positive integer. The maximum number of cells to be used. If this is smaller than ncell(x), a regular sample of \code{x} is used}
}

\value{
Expand Down
1 change: 1 addition & 0 deletions man/terra-package.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
\name{terra-package}

\alias{terra-package}

\alias{terra}
Expand Down

0 comments on commit 1ba3abc

Please sign in to comment.