Two-Stage Model Selection for MPCA: Select K First, Then r
Source:R/best_fit.R
select_optimal_K_r_mpca_twostage.RdThis function implements a more stable two-stage approach to model selection: Stage 1: Fix r (e.g., r=2) and search for optimal K using BIC or ICL Stage 2: Fix K at the optimal value and search for optimal r using BIC
Usage
select_optimal_K_r_mpca_twostage(
list_of_data,
Kvec = 2:5,
rvec = 1:5,
r_fixed = 2,
criterion = c("ICL", "BIC"),
max_iter = 50,
icl_max_iter = NULL,
icl_temperature = 2,
nIterPCA = 5,
tol = 0.001,
method = "EM",
n_init = 1,
use_kmeans_init = TRUE,
subject_rdim_for_kmeans = 2,
mc_cores = 1,
n_threads = 1
)Arguments
- list_of_data
A list of data matrices, each (T_i x M).
- Kvec
An integer vector of candidate K values for Stage 1.
- rvec
An integer vector of candidate r values for Stage 2.
- r_fixed
Fixed r value to use in Stage 1 (default: 2).
- criterion
Model selection criterion for K selection in Stage 1. Either "BIC" (default) or "ICL". ICL adds an entropy penalty that discourages uncertain cluster assignments, making it more conservative for K selection. Stage 2 (r selection) always uses BIC.
- max_iter
Maximum EM iterations.
- icl_max_iter
Maximum EM iterations for ICL entropy calculation (default: 10). Only used when criterion="ICL". This limits iterations to maintain soft cluster assignments (non-zero entropy), making ICL effective. If NULL, defaults to 10. Uses random initialization (not K-means) internally.
- icl_temperature
Temperature parameter for ICL entropy scaling (default: 2.0). Higher values favor more clusters by scaling down the entropy penalty.
- nIterPCA
Sub-iterations within the PCA/PPCA update in C++.
- tol
Convergence tolerance.
- method
"EM" or "closed_form" (passed to mixture_pca_em_fit).
- n_init
Number of random initializations to try.
- use_kmeans_init
Logical; whether to also try a k-means-based init.
- subject_rdim_for_kmeans
Dimension for PCA-based features if use_kmeans_init=TRUE.
- mc_cores
Number of CPU cores for initialization-level parallelization (default: 1).
- n_threads
Number of OpenMP threads for EM-level parallelization (default: 1).
Value
A list with:
- stage1_summary
Data frame with K search results (r fixed). Contains BIC and optionally ICL if criterion="ICL".
- stage2_summary
Data frame with r search results (K fixed).
- best_K
Optimal K from Stage 1.
- best_r
Optimal r from Stage 2.
- best_model_info
Final model with optimal (K, r).
- best_model
The fitted model object.
- criterion
The criterion used for K selection.
Details
This approach is more stable than simultaneous (K, r) grid search because K and r have strong interactions in mixture models.
This two-stage approach is recommended in the literature for mixture models because it avoids the instability of simultaneous (K, r) optimization. The default r_fixed=2 is a reasonable starting point for most applications.
When criterion="ICL", the Integrated Complete-data Likelihood is used for K selection. ICL adds an entropy penalty to BIC that discourages models with uncertain cluster assignments. This makes ICL more conservative than BIC and can help avoid overestimating K.