Package {fanc}


Type: Package
Title: Penalized Likelihood Factor Analysis via Nonconvex Penalty
Version: 2.4.0
Date: 2026-07-26
Depends: Matrix
Imports: grDevices, graphics, stats, utils
Description: Computes the penalized maximum likelihood estimates of factor loadings and unique variances for various tuning parameters. The pathwise coordinate descent along with EM algorithm is used. This package also includes a graphical tool which outputs path diagrams, heatmaps, goodness-of-fit indices and model selection criteria for each regularization parameter (Yamamoto, M., Hirose, K. and Nagata, H., 2017 <doi:10.1007/s41237-016-0007-3>). The user can change the regularization parameter interactively with a built-in self-contained HTML viewer (no additional packages required), which is helpful to find a suitable value of regularization parameter. As a penalty, we can choose either the minimax concave penalty (Hirose, K. and Yamamoto, M., 2015 <doi:10.1007/s11222-014-9458-0>; Hirose, K. and Yamamoto, M., 2014 <doi:10.1016/j.csda.2014.05.011>) or the product-based elastic net penalty (Hirose, K. and Terada, Y., 2023 <doi:10.1007/s11336-022-09868-4>).
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
URL: https://doi.org/10.1007/s11222-014-9458-0, https://doi.org/10.1016/j.csda.2014.05.011, https://doi.org/10.1007/s41237-016-0007-3, https://doi.org/10.1007/s11336-022-09868-4, https://keihirose.com
NeedsCompilation: yes
Packaged: 2026-07-26 06:40:46 UTC; hirosekei
Author: Kei Hirose ORCID iD [aut, cre], Michio Yamamoto [aut], Haruhisa Nagata [aut]
Maintainer: Kei Hirose <mail@keihirose.com>
Repository: CRAN
Date/Publication: 2026-07-26 07:10:02 UTC

Penalized Likelihood Factor Analysis via Nonconvex Penalties

Description

Computes solution paths of penalized maximum likelihood estimates for factor analysis or probabilistic principal component analysis. The available penalties are MC+, the product-based elastic net (prenet), and the elastic net.

Usage

fanc(x, factors, n.obs, rho, gamma, cor.factor=FALSE, normalize=TRUE,
     normalize.penalty=FALSE, covmat, type="MC", model="FA", control=list())

## S3 method for class 'fanc'
print(x, digits=max(3, getOption("digits") - 3),
                     num.result=20, ...)

Arguments

x

A numeric data matrix.

factors

The number of factors.

n.obs

The number of observations. This is required to calculate model-selection criteria and goodness-of-fit indices when only covmat is supplied. If it is omitted, model fitting is performed but these indices are unavailable.

rho

Values of rho. This may be a scalar or a matrix with one column for each gamma value.

gamma

Values of gamma.

cor.factor

Logical; if TRUE, factor correlations are estimated. The default is FALSE.

normalize

Logical; if TRUE, each variable is normalized. The default is TRUE.

normalize.penalty

Logical; if TRUE, variable-specific penalty weights are calculated. The default is FALSE.

covmat

A covariance matrix, used when the data matrix x is unavailable.

type

Penalty type: "MC", "prenet", or "enet". The default is "MC".

model

Model type: "FA" for factor analysis or "PPCA" for probabilistic principal component analysis. The default is "FA".

control

A list of control parameters. See ‘Details’.

digits

Number of digits used by the print method.

num.result

Retained for compatibility with earlier versions; it currently does not change the printed output.

...

Reserved for compatibility; currently unused.

Details

The control argument can contain the following components:

length.rho

Number of rho candidates.

length.gamma

Number of gamma candidates.

max.rho

Maximum rho. For prenet and enet, a scalar is repeated for every gamma. Alternatively, supply one value per gamma. Other lengths are invalid.

max.gamma

Maximum finite gamma.

min.gamma

Minimum gamma.

eta

Non-negative tuning parameter used to prevent improper solutions.

ncand.initial

Number of candidate initial loading matrices. The default is 10.

ncand.initial.prenet

Number of candidate initial values for the prenet penalty. The default is 100.

maxit.em

Maximum number of EM iterations.

maxit.cd

Maximum number of coordinate-descent iterations.

maxit.bfgs

Maximum number of BFGS iterations.

maxit.initial

Maximum number of iterations used when choosing initial values.

start

Starting-value strategy, either "warm" or "cold".

Delta

Ratio of the minimum rho to the maximum rho.

min.uniquevar

Minimum unique variance.

tol.em

Convergence tolerance for the EM algorithm.

tol.cd

Convergence tolerance for coordinate descent.

tol.bfgs

Convergence tolerance for BFGS.

min.rhozero

Logical; if TRUE, the minimum rho is zero.

zita

Hyper-parameter for factor correlations.

progress

Logical; if TRUE, fitting progress is displayed.

openmp

Logical; if TRUE, OpenMP parallel computation is requested.

num.threads

Number of OpenMP threads.

gamma.ebic

Gamma used in the extended BIC.

Value

An object of class "fanc". Important components include:

loadings

Factor-loading matrices for every rho and gamma.

uniquenesses

Unique variances for every rho and gamma.

Phi

Factor-correlation matrices.

rho

Matrix of rho values.

gamma

Vector of gamma values.

df, dfnonzero

Degrees of freedom.

AIC, BIC, CAIC, EBIC

Model-selection criteria based on reparametrized degrees of freedom.

AIC_dfnonzero, BIC_dfnonzero, CAIC_dfnonzero, EBIC_dfnonzero

Model-selection criteria based on active parameters.

GFI, AGFI, CFI, RMSEA, SRMR

Goodness-of-fit indices.

AGFI_dfnonzero, CFI_dfnonzero, RMSEA_dfnonzero

Goodness-of-fit indices based on active parameters.

factors

Number of factors.

cor.factor

Whether factor correlations were estimated.

x

The original data matrix, or NULL when only covmat was supplied.

convergence

Convergence indicators for the fitting algorithms.

type, model

Penalty and model types.

When only covmat is supplied and n.obs is omitted, the model-selection criteria and goodness-of-fit indices are NULL.

Author(s)

Kei Hirose
mail@keihirose.com

References

Hirose, K. and Yamamoto, M. (2015). Sparse estimation via nonconcave penalized likelihood in a factor analysis model, Statistics and Computing, 25, 633–648.

See Also

out, select, and plot.fanc.

Examples

set.seed(0)
loadings0 <- matrix(c(rep(0.8, 5), rep(0, 5),
                      rep(0, 5), rep(0.8, 5)), 10, 2)
common.factors0 <- matrix(rnorm(50 * 2), 50, 2)
unique.factors0 <- matrix(rnorm(50 * 10, sd=sqrt(0.36)), 50, 10)
x <- common.factors0 %*% t(loadings0) + unique.factors0

fit <- fanc(x, 2)
print(fit)
out(fit, rho=0.1, gamma=Inf)
select(fit, criterion="BIC", gamma=Inf)

## Not run: 
plot(fit)
plot(fit, file="fanc-viewer.html")

## End(Not run)

Extract a Result from a "fanc" Object

Description

Extracts the fitted model at specified values of rho and gamma from a "fanc" object.

Usage

out(x, rho, gamma, scores=FALSE, df.method="active")

Arguments

x

Fitted "fanc" model object.

gamma

The value of gamma.

rho

The value of rho.

scores

Logical flag for outputting factor scores. The original data matrix must have been supplied to fanc. The default is FALSE.

df.method

Two types of degrees of freedom are supported. If "reparametrization", the degrees of freedom of the MC+ are reparametrized based on the degrees of freedom of the lasso. If "active", the degrees of freedom are the number of nonzero parameters.

Value

loadings

factor loadings

uniquenesses

unique variances

Phi

Factor-correlation matrix, when factor correlations were estimated.

scores

Factor scores, when scores=TRUE.

df

Degrees of freedom under the selected df.method.

criteria

Values of AIC, BIC, CAIC and EBIC, when available.

goodness.of.fit

Values of GFI, AGFI, CFI, RMSEA and SRMR, when available.

rho

The selected value of rho.

gamma

The selected value of gamma.

Author(s)

Kei Hirose
mail@keihirose.com

References

Hirose, K. and Yamamoto, M. (2015). Sparse estimation via nonconcave penalized likelihood in a factor analysis model,
Statistics and Computing, 25, 633–648.

See Also

fanc and plot.fanc objects.


Plot a Solution Path from a "fanc" Object

Description

This function plots the solution paths or heatmaps from a "fanc" object. By default it opens a self-contained, interactive HTML viewer in the browser or RStudio viewer pane (no additional packages required). The viewer has sliders for rho and gamma, buttons that jump to the model selected by AIC, BIC, CAIC or EBIC, and an overview mode showing every rho along the path at once. All data and code are embedded in the page, so it runs without a server and can be saved and shared as a single file via the file argument.

Usage

## S3 method for class 'fanc'
plot(x, Window.Height=500, type=NULL, df.method="active",
                    viewer=c("auto", "html", "base"), file=NULL,
                    rho.index=1, gamma.index=1, ...)

Arguments

x

Fitted "fanc" model object.

Window.Height

Maximum plot height in pixels for the HTML viewer. It does not change the internal layout of base R plots. It must be between 250 and 2000. The default is 500.

type

Two plot types are supported. If "path", the path diagram is depicted. If "heatmap", the heatmap is depicted. When NULL, a path diagram is used when there are fewer than 50 variables and fewer than seven factors; otherwise a heatmap is used. Explicitly requesting "path" with seven or more factors is allowed but produces a warning because the diagram may be difficult to read.

df.method

Two types of degrees of freedom are supported. If "reparametrization", the degrees of freedom of the MC+ are reparametrized based on the degrees of freedom of the lasso. If "active", the degrees of freedom are the number of nonzero parameters.

viewer

Viewer backend. "auto" opens the interactive HTML viewer in an interactive session (or whenever file is supplied) and otherwise falls back to a base R plot. "html" always builds the HTML viewer. "base" draws the selected indices with base graphics. Long labels in base R plots are reduced or abbreviated to fit the available space. Rendering non-ASCII labels depends on the fonts supported by the active graphics device.

file

Optional path for the generated HTML file. When NULL (default) a temporary file is used. Supplying a path writes a permanent, self-contained .html file that can be opened on any computer (no R required).

rho.index

Initial index of the rho value.

gamma.index

Initial index of the gamma value.

...

Reserved for compatibility; currently unused.

Value

For viewer="html" the path to the generated HTML file (invisibly); otherwise NULL (invisibly). Called for the side effect of drawing or opening the viewer.

Author(s)

Kei Hirose
mail@keihirose.com

References

Hirose, K. and Yamamoto, M. (2015). Sparse estimation via nonconcave penalized likelihood in a factor analysis model,
Statistics and Computing, 25, 633–648.

See Also

fanc and out objects.


Select a Model from a "fanc" Object

Description

Selects the value of rho that minimizes a model-selection criterion, optionally at a specified value of gamma.

Usage

select(x, criterion=c("BIC","AIC","CAIC","EBIC"), 
	gamma,  scores=FALSE, df.method="active")

Arguments

x

Fitted "fanc" model object.

criterion

The criterion by which to select the tuning parameter rho. One of "AIC", "BIC", "CAIC", or "EBIC". Default is "BIC".

gamma

The value of gamma.

scores

Logical flag for outputting factor scores. The original data matrix must have been supplied to fanc. The default is FALSE.

df.method

Two types of degrees of freedom are supported. If "active", the degrees of freedom are the number of nonzero parameters. If "reparametrization", the degrees of freedom of the MC+ are reparametrized based on the degrees of freedom of the lasso.

Value

loadings

factor loadings

uniquenesses

unique variances

Phi

Factor-correlation matrix, when factor correlations were estimated.

scores

Factor scores, when scores=TRUE.

df

Degrees of freedom under the selected df.method.

AIC, BIC, CAIC, EBIC

The value of the selected criterion.

goodness.of.fit

Values of GFI, AGFI, CFI, RMSEA and SRMR, when available.

rho

The selected value of rho.

gamma

The selected value of gamma.

Author(s)

Kei Hirose
mail@keihirose.com

References

Hirose, K. and Yamamoto, M. (2015). Sparse estimation via nonconcave penalized likelihood in a factor analysis model,
Statistics and Computing, 25, 633–648.

See Also

fanc and plot.fanc objects.