---
title: "prcomp.HDF5Matrix"
subtitle: "prcomp.HDF5Matrix"
---
<span class="category-badge decompositions">DECOMPOSITIONS</span>
## Usage
```r
prcomp.HDF5Matrix(...)
```
## Arguments
::: {.param-table}
| Parameter | Description |
|-----------|-------------|
| `x` | An \code{HDF5Matrix} object. |
| `retx` | Logical. If \code{TRUE} (default) return the individual coordinates (\code{x} slot). If \code{FALSE} the \code{x} slot is \code{NULL} in the returned object. |
| `center` | Logical. Subtract column means before PCA (default \code{TRUE}). |
| `scale.` | Logical. Divide by column SDs before PCA (default \code{FALSE}). |
| `tol` | Ignored (present for interface compatibility with \code{prcomp()}). |
| `rank.` | Ignored. Present for compatibility with \code{stats::prcomp}. |
| `ncomponents` | Integer. Number of PCs to compute (0 = all, default). |
| `k` | Number of local SVDs per incremental level (default 2). |
| `q` | Number of incremental levels (default 1). |
| `method` | Computation method: \code{"auto"} (default), \code{"blocks"}, or \code{"full"}. |
| `rankthreshold` | Numeric in \code{[0, 0.1]}. Rank approximation threshold. |
| `svdgroup` | HDF5 group for intermediate SVD storage (default \code{"SVD/"}). |
| `overwrite` | Logical. Recompute even if PCA results exist (default \code{FALSE}). |
| `threads` | Integer. OpenMP threads (\code{-1} = auto-detect). |
:::
## Value
::: {.return-value}
An object of class \code{c("HDF5PCA", "list")} with elements:
\describe{
\item{\code{sdev}}{Numeric vector. Standard deviations of the PCs.}
\item{\code{rotation}}{HDF5Matrix. Variable loadings (rotation matrix).}
\item{\code{x}}{HDF5Matrix or \code{NULL}. Individual coordinates.}
\item{\code{center}}{Logical. Whether columns were centered.}
\item{\code{scale}}{Logical. Whether columns were scaled.}
\item{\code{cumvar}}{Numeric vector. Cumulative variance explained (percent).}
\item{\code{lambda}}{Numeric vector. Eigenvalues.}
\item{\code{var.cos2}}{HDF5Matrix. Squared cosines for variables.}
\item{\code{ind.cos2}}{HDF5Matrix. Squared cosines for individuals.}
\item{\code{ind.contrib}}{HDF5Matrix. Contributions of individuals to PCs.}
\item{\code{file}}{Character. Path to the HDF5 file with all results.}
}
:::
## Examples
```{r}
#| eval: false
#| warning: false
\donttest{
tmp <- tempfile(fileext = ".h5")
X <- hdf5_create_matrix(tmp, "data/M", data = matrix(rnorm(1000), 100, 10))
pca <- prcomp(X, center = TRUE, scale. = FALSE)
cat("Variance explained (PC1-3):", pca$cumvar[1:3], "\n")
dim(pca$rotation) # 10 x nPC
dim(pca$x) # 100 x nPC
hdf5_close_all()
unlink(tmp)
}
```