This vignette demonstrates how to reproduce the simulation study used in our manuscript to compare
Performance is evaluated on 10 independent replicates with metrics that reflect goodness of fit (Bayesian Information Criterion, BIC), clustering accuracy (Adjusted Rand Index, ARI) and reconstruction quality (Variance Accounted For, VAF).
For reference, VAF is defined as
\[ \mathrm{VAF} = 1 - \frac{\sum_{i}(y_i - \hat{y}_i)^2}{\sum_{i} y_i^2}, \]
where \(y_i\) is the observed signal and \(\hat{y}_i\) its low-rank reconstruction.
Each replicate draws \(N=50\) synthetic subjects whose EMG signals are generated from \(K=4\) true clusters sharing common factor loadings of rank \(r=4\) across \(M=7\) muscles. The simulation:
use_kmeans_init = TRUE),n_init = 5 times to reduce
local-optimum bias, andNoise level (noise_scale) and between-cluster separation
(cluster_sep) can be tuned; we keep both at 1.0 for an
intermediate difficulty setting.
The following code demonstrates how to run the simulation using the package’s simulation functions. Note that the actual function names may vary; please refer to the package documentation for the current API.
seeds_vec <- 101:110
# Example simulation workflow using package functions
res_list <- lapply(seeds_vec, function(s) {
# Generate synthetic data
sim_data <- generate_synergy_data(
N = 50, K = 4, r = 4, M = 7, T_each = 100,
cluster_sep_spatial = 1.0, seed = s
)
# Fit models and collect results
# (Implementation details depend on your analysis workflow)
# This is a placeholder showing the expected structure
data.frame(
Method = c("SingleFA", "SinglePCA", "MixtureFA", "MixturePCA"),
BIC = NA_real_,
ARI = NA_real_,
VAF = NA_real_,
Seed = s
)
})
df_all <- bind_rows(res_list)
dplyr::glimpse(df_all)We annotate two helper columns to simplify downstream plotting:
library(ggplot2)
ggplot(df_all, aes(x = Type, y = VAF, fill = Method)) +
geom_boxplot(alpha = 0.6, outlier.shape = NA) +
theme_bw() +
facet_wrap(~SubMethod) +
labs(x = NULL, y = "VAF", title = "VAF by model family") +
theme(legend.position = "none")
ggplot(df_all, aes(x = Type, y = BIC, fill = Method)) +
geom_boxplot(alpha = 0.6, outlier.shape = NA) +
theme_bw() +
facet_wrap(~SubMethod) +
labs(x = NULL, y = "BIC", title = "BIC by model family") +
theme(legend.position = "none")Interpretation. Mixture models yield lower (better) BIC and markedly higher ARI (not shown) whenever distinct latent clusters exist. VAF differences between FA and PCA reflect method-specific assumptions (orthogonality vs. diagonal uniqueness). In practice, the trade-off between VAF and model complexity (BIC) suggests MixtureFA strikes the best balance for heterogeneous cohorts.
#> R version 4.6.1 (2026-06-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] parallel stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] purrr_1.2.2 dplyr_1.2.1 tidyr_1.3.2 ggplot2_4.0.3
#> [5] synergyMixR_1.0.0 rmarkdown_2.32
#>
#> loaded via a namespace (and not attached):
#> [1] gtable_0.3.6 jsonlite_2.0.0 compiler_4.6.1 tidyselect_1.2.1
#> [5] Rcpp_1.1.2 stringr_1.6.0 jquerylib_0.1.4 scales_1.4.0
#> [9] yaml_2.3.12 fastmap_1.2.0 plyr_1.8.9 R6_2.6.1
#> [13] labeling_0.4.3 generics_0.1.4 knitr_1.52 tibble_3.3.1
#> [17] maketools_1.3.2 bslib_0.12.0 pillar_1.11.1 RColorBrewer_1.1-3
#> [21] rlang_1.3.0 stringi_1.8.9 cachem_1.1.0 xfun_0.61
#> [25] sass_0.4.10 sys_3.4.3 S7_0.2.2 otel_0.2.0
#> [29] cli_3.6.6 withr_3.0.3 magrittr_2.0.5 digest_0.6.39
#> [33] grid_4.6.1 mvtnorm_1.4-2 mclust_6.1.3 lifecycle_1.0.5
#> [37] vctrs_0.7.3 evaluate_1.0.5 glue_1.8.1 farver_2.1.2
#> [41] buildtools_1.0.0 reshape2_1.4.5 tools_4.6.1 pkgconfig_2.0.3
#> [45] htmltools_0.5.9