Skip to content

Commit

Permalink
Merge pull request #1388 from ailich/master
Browse files Browse the repository at this point in the history
Update prcomp and princomp docs
  • Loading branch information
rhijmans authored Jan 4, 2024
2 parents c37b78c + 3891334 commit bf83619
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions man/prcomp.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\title{SpatRaster PCA with prcomp}

\description{
Compute principal components for SpatRaster layers. For very large rasters this can only be done with a sample. This may be good enough but see \code{\link{prcomp}} if you want to use all values.
Compute principal components for SpatRaster layers. This method is may be preferred due to greater numerical accuracy, however it is slower and for very large rasters it can only be done with a sample. This may be good enough but see \code{\link{princomp}} if you want to use all values. Unlike \code{\link{princomp}}, in this method the sample variances are used with \code{n-1} as the denominator.
}

\usage{
Expand All @@ -28,7 +28,7 @@ Compute principal components for SpatRaster layers. For very large rasters this
prcomp object
}

\author{Alex Ilich and Robert Hijmans, based on a similar method by Benjamin Leutner}
\author{Robert Hijmans}


\seealso{ \code{\link{princomp}}, \code{\link[stats]{prcomp}}}
Expand Down
5 changes: 3 additions & 2 deletions man/princomp.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
\description{
Compute principal components for SpatRaster layers. The benefit of this method is that it uses all values to compute the principal components, even for very large rasters. This is because it computes the covariance matrix by processing the data in chunks, if necessary, using \code{\link{layerCor}}. The population covariance is used (not the sample, with \code{n-1} denominator, covariance).

Alternatively, you can use \code{stats::\link[stats]{princomp}} or \code{stats::\link[stats]{prcomp}} with a data.frame of the raster values, using a sample for very large rasters (see the examples below).
Alternatively, you can specify \code{maxcell} or sample raster values to a data.frame to speed up calculations for very large rasters (see the examples below).
See \code{\link{princomp}} for an alternative method that has better numerical accuracy, but is slower, and for very large rasters can only be accomplished with a sample since all values must be read into memory.
}

\usage{
Expand All @@ -30,7 +31,7 @@ princomp object
\author{Alex Ilich and Robert Hijmans, based on a similar method by Benjamin Leutner}


\seealso{ \code{\link[stats]{princomp}}}
\seealso{ \code{\link{prcomp}} \code{\link[stats]{princomp}}}

\examples{
f <- system.file("ex/logo.tif", package = "terra")
Expand Down

0 comments on commit bf83619

Please sign in to comment.