Skip to contents

Computes bootstrap confidence intervals for the loading matrices in mixture PCA or mixture FA models. Uses Procrustes alignment to ensure bootstrap samples are comparable across resamples.

Usage

bootstrap_loading_ci(
  list_of_data,
  K,
  r,
  B = 200,
  alpha = 0.05,
  mc_cores = 1,
  model_type = c("MPCA", "MFA"),
  max_iter = 50,
  n_init = 1,
  use_kmeans_init = TRUE,
  seed = NULL,
  verbose = TRUE
)

Arguments

list_of_data

A list of N matrices, each of dimension (T_i x M), containing the observed EMG data.

K

Integer. Number of clusters.

r

Integer. Number of synergies (factors/principal components).

B

Integer. Number of bootstrap iterations. Default: 200.

alpha

Numeric. Significance level for confidence intervals. Default: 0.05 (95% CI).

mc_cores

Integer. Number of cores for parallel computation. Default: 1 (sequential).

model_type

Character. Either "MPCA" or "MFA". Default: "MPCA".

max_iter

Integer. Maximum EM iterations per fit. Default: 50.

n_init

Integer. Number of random initializations. Default: 1.

use_kmeans_init

Logical. Whether to use k-means initialization. Default: TRUE.

seed

Integer. Random seed for reproducibility. Default: NULL.

verbose

Logical. Print progress messages. Default: TRUE.

Value

A list with the following elements:

loadings_median

List of K matrices (M x r), median loadings for each cluster

loadings_lower

List of K matrices (M x r), lower CI bound for each cluster

loadings_upper

List of K matrices (M x r), upper CI bound for each cluster

loadings_se

List of K matrices (M x r), standard errors for each cluster

bootstrap_samples

Array of dimension (B x K x M x r) containing all aligned bootstrap samples (optional, if return_samples=TRUE)

reference_fit

The reference model fit used for alignment

n_successful

Number of successful bootstrap iterations

alpha

The significance level used

Details

The bootstrap procedure: 1. Fit the model to the full dataset to obtain reference loadings 2. For each bootstrap iteration b = 1, ..., B: a. Resample subjects with replacement b. Fit the model to the bootstrap sample c. Align bootstrap loadings to reference using Procrustes rotation 3. Compute percentile confidence intervals from aligned samples

Procrustes alignment is essential because factor loadings are only identifiable up to rotation and sign. Without alignment, bootstrap samples would not be comparable, leading to inflated variance estimates.

Procrustes Alignment

For each cluster k, the bootstrap loading matrix W_k(b) is aligned to the reference W_k using orthogonal Procrustes: W_aligned(b) = W_k(b) R* where R* minimizes ||W_k - W_k(b) R||_F subject to R'R = I.

The optimal R is found via SVD: if W_k' W_k(b) = UDV', then R* = VU'.

Examples

if (FALSE) { # \dontrun{
# Simulate some data
sim <- simulate_dynamic_synergy_data(N = 50, K = 2, r = 3, M = 8, T_each = 100)

# Compute bootstrap CIs
boot_ci <- bootstrap_loading_ci(
  list_of_data = sim$X_list,
  K = 2,
  r = 3,
  B = 100,
  alpha = 0.05,
  mc_cores = 4
)

# View median loadings for cluster 1
print(boot_ci$loadings_median[[1]])

# View 95% CI width for first synergy, first muscle, cluster 1
width <- boot_ci$loadings_upper[[1]][1,1] - boot_ci$loadings_lower[[1]][1,1]
print(width)
} # }