| Title: | Factor-Augmented Clustering Tree |
|---|---|
| Description: | Implements the Factor-Augmented Clustering Tree (FACT) for clustering time series using covariates and group factor models. The tree compares child-node factor spaces through projector eigenvalues and uses PCA residual energy to determine node-specific stopping tolerances. Working ranks are selected by PC2 (default), BIC1 or BIC3, and comparison ranks are selected automatically at each node or supplied as a fixed value. The package also recovers global and local factors and their loadings, provides factor-space distance measures and a data generator. Candidate splits can be evaluated in parallel. |
| Authors: | Jiaqi Hu [cre, aut], Ting Li [ctb] (Assisted with methodology), Zidan Luo [ctb] (Assisted with methodology), Xueqin Wang [ctb] (Assisted with methodology) |
| Maintainer: | Jiaqi Hu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-11-23 16:54:50 UTC |
| Source: | https://github.com/cran/factree |
Recursively clusters time series using covariate splits. The comparison rank
is selected separately at every node from the extrema of averaged-projector
eigenvalues, or supplied as a fixed positive integer in control$r_c.
In automatic mode, an empty qualifying rank set stops the node.
FACT(X, Y, control = list(), rank_method = c("PC2", "BIC1", "BIC3"))FACT(X, Y, control = list(), rank_method = c("PC2", "BIC1", "BIC3"))
X |
Finite numeric covariate matrix with dimension |
Y |
Finite numeric time series matrix with dimension |
control |
A list with the following optional entries:
|
rank_method |
Working-rank criterion: |
Each node uses one working rank for both candidate children, selected by PC2
by default. Splits compare their factor spaces through projector eigenvalues.
The stopping tolerance uses the PCA residual energy at the selected rank.
Automatic mode selects the smallest qualifying comparison rank and stops
when none qualifies. A positive control$r_c uses a fixed rank instead.
An object of class "FACT" containing frame (node and
split information), diagnostics (candidate spectra and scores),
membership (terminal node labels), control, terms,
factor estimates G, F, and loading estimates Gamma,
Lambda. Local estimates are lists named by terminal node ID.
Absent factors and loadings are zero-column matrices.
Bai, J. and Ng, S. (2002). Determining the number of factors in approximate factor models. Econometrica, 70(1), 191–221. doi:10.1111/1468-0262.00273.
recover_factors, print.FACT, plot.FACT
dat <- gendata(seed = 1, T = 60, N = rep(50, 4), p = 3) fit <- FACT(dat$X, dat$Y, control = list(sep = 2)) table(dat$group, fit$membership) dim(fit$G) lapply(fit$F, dim) plot(fit)dat <- gendata(seed = 1, T = 60, N = rep(50, 4), p = 3) fit <- FACT(dat$X, dat$Y, control = list(sep = 2)) table(dat$group, fit$membership) dim(fit$G) lapply(fit$F, dim) plot(fit)
Generates the four-group simulation design, with unequal group sizes, correlated local factors, heavy-tailed or heteroscedastic errors, and additional irrelevant covariates.
gendata( seed = 1, T = 100, N = c(100, 100, 100, 100), r0 = 2, r = rep(2, length(N)), M = length(N), sigma = 1, p = 10, mu = 3, type_F = "Independent", type_X = "Uniform", type_noise = "Gaussian", local_corr = if (type_F == "Correlated") 0.4 else 0 )gendata( seed = 1, T = 100, N = c(100, 100, 100, 100), r0 = 2, r = rep(2, length(N)), M = length(N), sigma = 1, p = 10, mu = 3, type_F = "Independent", type_X = "Uniform", type_noise = "Gaussian", local_corr = if (type_F == "Correlated") 0.4 else 0 )
seed |
Random seed; use |
T |
Number of time periods, at least two. |
N |
Positive integer vector of four group sizes. |
r0 |
Nonnegative number of global factors. |
r |
Nonnegative integer vector of four local factor counts. |
M |
Number of groups, inferred from |
sigma |
Positive noise standard deviation; under heteroscedasticity,
|
p |
Number of covariates, at least three; only the first three define groups. |
mu |
Separation parameter for |
type_F |
|
type_X |
|
type_noise |
|
local_corr |
Common off-diagonal correlation of stacked local-factor
innovations, in |
Factors follow AR(0.5) processes with normal loadings. Errors may be Gaussian, standardized t3, or heteroscedastic Gaussian. The covariate design uses four groups; heteroscedastic errors require even group sizes.
A list with data X, Y, group labels group,
factors G, F, loadings Gamma, Lambda, errors
E, factor counts r0, r, and noise_variance.
Local-factor columns are ordered by group. Unused loading columns are zero.
G0 is an alias of G.
dat <- gendata(seed = 12345, T = 100, N = c(100, 100, 200, 400), sigma = 2) correlated <- gendata(seed = 12345, local_corr = 0.4) heavy_tail <- gendata(seed = 12345, type_noise = "t3") high_p <- gendata(seed = 12345, p = 100) heterogeneous <- gendata(seed = 12345, type_noise = "heteroscedastic")dat <- gendata(seed = 12345, T = 100, N = c(100, 100, 200, 400), sigma = 2) correlated <- gendata(seed = 12345, local_corr = 0.4) heavy_tail <- gendata(seed = 12345, type_noise = "t3") high_p <- gendata(seed = 12345, p = 100) heterogeneous <- gendata(seed = 12345, type_noise = "heteroscedastic")
Draws a vertical tree with a rounded root box, split variables at internal nodes, thresholds on branches, and narrow terminal-node boxes. Only terminal nodes display sample counts. No caption is added, and outer margins are small.
## S3 method for class 'FACT' plot(x, ..., cex = 0.8, compact = FALSE, labels = NULL)## S3 method for class 'FACT' plot(x, ..., cex = 0.8, compact = FALSE, labels = NULL)
x |
An object of class |
... |
Additional arguments (not used). |
cex |
Text-size multiplier; the default |
compact |
Use shorter terminal-node labels. |
labels |
Optional named character vector mapping covariate names to short display labels. Unmapped names are shown as supplied in the tree. |
Invisibly returns the displayed ggplot object.
Provides a concise textual representation of the FACT tree structure.
## S3 method for class 'FACT' print(x, ...)## S3 method for class 'FACT' print(x, ...)
x |
An object of class 'FACT', typically the result of a call to 'FACT()'. |
... |
Additional arguments (not used). |
Invisibly returns the original 'FACT' object.
Factor-Space Distance
projector_distance(Ghat, G)projector_distance(Ghat, G)
Ghat |
Estimated factors, scaled as in |
G |
Reference factors with the same number of rows and full column rank. |
Spectral-norm distance between the two orthogonal projectors. Zero-column matrices represent absent factors.
G <- diag(4)[, 1:2] projector_distance(2 * G, G)G <- diag(4)[, 1:2] projector_distance(2 * G, G)
Recover Global and Local Factors
recover_factors(Y, membership, rank_max = 12)recover_factors(Y, membership, rank_max = 12)
Y |
Numeric time series matrix, with series in columns. |
membership |
Group label for each series. |
rank_max |
Maximum candidate factor rank; default |
Group ranks use PC2. Averaged projections recover global factors; PCA of the remaining data recovers local factors. With one group, all factors are treated as global.
A list with factor estimates G, F and loading estimates
Gamma, Lambda. F and Lambda are lists named by
group label. Loading rows follow the original series order within each
group; Gamma follows the full input order. Absent factors and their
loadings are zero-column matrices.