% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ife.R
\name{ife_select_r}
\alias{ife_select_r}
\title{Select the Number of Factors via Information Criteria}
\usage{
ife_select_r(
  formula,
  data,
  index,
  r_max = NULL,
  force = "two-way",
  verbose = TRUE,
  tol = 1e-09,
  max_iter = 10000L
)
}
\arguments{
\item{formula}{R formula passed to \code{ife()}}

\item{data}{long-format data.frame}

\item{index}{character(2): \code{c("unit_id", "time_id")}}

\item{r_max}{maximum r to consider (default: \code{min(8, floor(min(N,T)/2))})}

\item{force}{additive FE type (default \code{"two-way"})}

\item{verbose}{logical; if \code{TRUE} (default) print progress and results table
to the console. Set to \code{FALSE} for silent operation.}

\item{tol}{convergence tolerance (default \code{1e-9})}

\item{max_iter}{maximum iterations (default \code{10000L})}
}
\value{
(invisibly) a data.frame with columns \code{r}, \code{V_r}, \code{IC1}, \code{IC2},
\code{IC3}, \code{IC_bic}, \code{PC}, \code{converged}, and attribute \code{"suggested"} (named
integer vector giving the IC-minimising r for each criterion).
}
\description{
Fits the IFE model for r = 0, 1, ..., \code{r_max} and evaluates
five information criteria at each value of r. Returns IC1, IC2, and IC3
from Bai and Ng (2002) Proposition 1, applied to IFE residuals per Bai
(2009) Section 9.4, plus a BIC-style penalty (\code{IC_bic}) and a
small-sample-corrected prediction criterion (\code{PC}) from Bai (2009).
The criterion-minimising r for each IC is flagged with \code{"*"} in the
printed table, and a data-driven recommendation (favouring \code{IC_bic} when
the Bai-Ng criteria decrease monotonically) is displayed.
}
\examples{
\donttest{
  data(cigar, package = "xtife")
  sel <- ife_select_r(sales ~ price, data = cigar,
                      index = c("state", "year"), r_max = 4)
}
}
\references{
Bai, J. (2009). Panel data models with interactive fixed effects.
\emph{Econometrica}, 77(4), 1229--1279. \doi{10.3982/ECTA6135}

Bai, J. and Ng, S. (2002). Determining the number of factors in approximate
factor models. \emph{Econometrica}, 70(1), 191--221. \doi{10.1111/1468-0262.00273}
}
