Select Optimal r by Smoothness Penalty for MPCA
Source:R/r_selection_advanced.R
select_r_by_smoothness_mpca.RdSelects the optimal number of factors (r) for a given number of clusters (K) by minimizing the smoothness penalty of PC activation profiles, subject to constraints on VAF or BIC.
Usage
select_r_by_smoothness_mpca(
list_of_data,
K,
rvec = 1:6,
lambda_smooth = 0.001,
vaf_threshold = 0.9,
max_iter = 50,
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 N matrices, each (T_i x M).
- K
Number of clusters (fixed).
- rvec
Vector of candidate r values to evaluate.
- lambda_smooth
Smoothness penalty weight. Default is 1e-3.
- vaf_threshold
Minimum VAF threshold. Models with VAF below this are excluded. Default is 0.9.
- max_iter
Maximum EM iterations.
- nIterPCA
Sub-iterations for PCA update.
- tol
Convergence tolerance.
- method
"EM" or "closed_form".
- n_init
Number of random initializations.
- use_kmeans_init
Whether to use k-means initialization.
- subject_rdim_for_kmeans
Dimension for k-means features.
- mc_cores
Number of cores for parallelization.
- n_threads
Number of OpenMP threads.
Value
A list with:
- best_r
The selected r value.
- summary
A data.frame with columns r, BIC, VAF, smoothness, penalized_score.
- best_model
The fitted model for the selected r.
Details
This function fits MPCA models for each r in rvec with fixed K, computes PC scores, and evaluates the smoothness penalty. The optimal r is selected by minimizing: $$ \text{score} = \text{BIC} + \lambda_{\text{smooth}} \times \text{smoothness} $$ among models satisfying VAF >= vaf_threshold.
Examples
if (FALSE) { # \dontrun{
result <- select_r_by_smoothness_mpca(
list_of_data, K = 3, rvec = 1:5,
lambda_smooth = 1e-3, vaf_threshold = 0.9
)
print(result$summary)
best_model <- result$best_model
} # }