% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/S3_correlation.R
\name{cor.HDF5Matrix}
\alias{cor.HDF5Matrix}
\title{Correlation matrix for HDF5Matrix objects}
\usage{
\method{cor}{HDF5Matrix}(
  x,
  y = NULL,
  use = "everything",
  method = "pearson",
  trans_x = FALSE,
  trans_y = FALSE,
  compute_pvalues = TRUE,
  block_size = NULL,
  threads = NULL,
  result_path = NULL,
  compression = NULL,
  ...
)
}
\arguments{
\item{x}{An \code{HDF5Matrix} object.}

\item{y}{An \code{HDF5Matrix} for cross-correlation, or
\code{NULL} (default) to compute \code{cor(x, x)}.}

\item{use}{Character string.  Only \code{"everything"} (default)
and \code{"complete.obs"} are currently supported.}

\item{method}{\code{"pearson"} (default) or \code{"spearman"}.}

\item{trans_x}{Logical.  If \code{TRUE}, correlate rows of \code{x}
instead of columns (useful for sample-sample
correlations in omics data). Default \code{FALSE}.}

\item{trans_y}{Logical.  Same for \code{y}. Default \code{FALSE}.}

\item{compute_pvalues}{Logical. Also compute and store p-values on disk.
Default \code{TRUE}.}

\item{block_size}{Integer or NULL. Block size for HDF5 reads (NULL = auto).}

\item{threads}{Integer or NULL. Number of OpenMP threads (NULL = auto).}

\item{result_path}{Output location:
\code{NULL} (default) writes to \code{"CORR/<dataset>/correlation"} in the
same file as \code{x}. A character string specifies a custom output group
in the same file.  A named list \code{list(file=, group=)} writes to a
different file.}

\item{compression}{Integer (0-9) or NULL. gzip compression level for the
result datasets.  NULL uses the global option set by
\code{\link{hdf5matrix_options}} (default 6).  Use \code{0} to disable
compression (faster for benchmarks).}

\item{...}{Ignored (for S3 compatibility).}
}
\value{
An \code{HDF5Matrix} pointing to the correlation matrix on disk.
Attributes attached to the result:
\describe{
\item{\code{cor.method}}{The correlation method used.}
\item{\code{cor.type}}{\code{"single"} or \code{"cross"}.}
\item{\code{cor.n.vars}}{Number of variables (columns/rows correlated).}
\item{\code{cor.n.obs}}{Number of observations used.}
\item{\code{cor.pvalues.path}}{HDF5 path to the p-values dataset
(present only when \code{compute_pvalues = TRUE}).}
}
}
\description{
Block-wise computation of Pearson or Spearman correlation, running
entirely on disk without loading the full matrix into RAM.
Supports both auto-correlation \code{cor(X)} and cross-correlation
\code{cor(X, Y)}.
}
\examples{
\donttest{
tmp <- tempfile(fileext = ".h5")
X   <- hdf5_create_matrix(tmp, "data/X",
                           data = matrix(rnorm(500), 50, 10))

# Auto-correlation: cor(X) — 10 x 10 matrix
C <- cor(X)
dim(C)
cat("method:", attr(C, "cor.method"), "\n")

# Spearman
Cs <- cor(X, method = "spearman")
dim(Cs)

# Sample-sample correlation (rows)
Sr <- cor(X, trans_x = TRUE)   # 50 x 50
dim(Sr)

X$close(); C$close(); Cs$close(); Sr$close()
unlink(tmp)
}

}
