% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulate.R
\name{simulate_factor_model}
\alias{simulate_factor_model}
\title{Simulate Data from an Approximate Factor Model}
\usage{
simulate_factor_model(N, TT, k, sd = 1, seed = NULL)
}
\arguments{
\item{N}{Integer. Number of cross-sectional units.}

\item{TT}{Integer. Number of time periods. Named \code{TT} to avoid
conflict with the base R function \code{T} (which evaluates to
\code{TRUE}).}

\item{k}{Integer. True number of factors.}

\item{sd}{Numeric. Standard deviation of the idiosyncratic error term.
Defaults to \code{1}. Lower values produce stronger signal relative
to noise.}

\item{seed}{Integer or \code{NULL}. Random seed for reproducibility.
Defaults to \code{NULL} (no seed set).}
}
\value{
A numeric matrix of dimensions \code{TT x N} generated from:
\deqn{X = F \Lambda' + E}
where \eqn{F} is a \code{TT x k} matrix of factors drawn from
\eqn{N(0,1)}, \eqn{\Lambda} is an \code{N x k} matrix of loadings
drawn from \eqn{N(0,1)}, and \eqn{E} is a \code{TT x N} matrix of
idiosyncratic errors drawn from \eqn{N(0, sd^2)}.
}
\description{
Generates a simulated panel data matrix from a static approximate factor
model. Useful for testing and benchmarking factor number estimators.
}
\details{
The data generating process follows the standard approximate factor
model of Chamberlain and Rothschild (1983) as used in the simulation
exercises of Ahn and Horenstein (2013). Factors and loadings are
independent standard normal draws. Errors are i.i.d. normal with
mean zero and standard deviation \code{sd}.

The signal-to-noise ratio is controlled by \code{sd} — smaller values
produce a cleaner factor structure that is easier for estimators to
recover. The default \code{sd = 1} matches the baseline simulation
design of Ahn and Horenstein (2013) with \code{theta = 1}.
}
\examples{
# Simulate a factor model with 3 factors
X <- simulate_factor_model(N = 100, TT = 200, k = 3, sd = 0.5, seed = 42)
dim(X)

# Pass directly to select_factors
result <- select_factors(X)
result$k
}
\references{
Ahn, S.C. and Horenstein, A.R. (2013). Eigenvalue Ratio Test for the
Number of Factors. \emph{Econometrica}, 81(3), 1203-1227.

Chamberlain, G. and Rothschild, M. (1983). Arbitrage, Factor Structure,
and Mean-Variance Analysis on Large Asset Markets.
\emph{Econometrica}, 51(5), 1281-1304.
}
\seealso{
\code{\link{select_factors}}
}
