% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/prepare_matrix.R
\name{.prepare_matrix}
\alias{.prepare_matrix}
\title{Demean and Scale a Matrix for Factor Analysis}
\usage{
.prepare_matrix(
  X,
  demean = c("both", "individual", "time", "none"),
  standardize = TRUE
)
}
\arguments{
\item{X}{Numeric matrix of dimensions T x N (time periods x units).}

\item{demean}{Character string specifying the demeaning method. One of:
\describe{
\item{"both"}{Remove both individual (column) and time (row) means.
This is the recommended default for macro panels.}
\item{"individual"}{Remove individual (column) means only.}
\item{"time"}{Remove time (row) means only.}
\item{"none"}{No demeaning applied.}
}}

\item{standardize}{Logical. If \code{TRUE} (default), scale each column
to unit variance after demeaning.}
}
\value{
A demeaned and optionally scaled numeric matrix of the same
dimensions as \code{X}.
}
\description{
Removes individual means, time means, or both from a numeric matrix,
and optionally scales to unit variance. This is the standard preprocessing
step required before eigendecomposition in factor number estimation.
}
\details{
When \code{demean = "both"}, the function iterates individual and time
demeaning to convergence. This follows the within-transformation used in
panel data models.
}
\references{
Bai, J. and Ng, S. (2002). Determining the Number of Factors in
Approximate Factor Models. \emph{Econometrica}, 70(1), 191-221.
}
\seealso{
\code{\link{select_factors}}
}
