flexIC: Minimal, Runnable Demo

1 Simulate marginals

n <- 200; k <- 5
Sigma <- matrix(0.6, k, k); diag(Sigma) <- 1
X0  <- mvtnorm::rmvnorm(n, sigma = Sigma)
R_star <- cor(X0, method = "spearman")

2 IC vs flexIC

out_ic   <- flexIC(X0, R_star, eps = "none")
out_flex <- flexIC(X0, R_star, eps = 0.02, max_iter = 50)
X_ic     <- out_ic
X_flex   <- out_flex

3 Maximum rank-error

err_ic   <- max(abs(cor(X_ic  , method = "spearman") - R_star))
err_flex <- max(abs(cor(X_flex, method = "spearman") - R_star))

data.frame(
  method         = c("IC (eps = 'none')", "flexIC (eps = 0.02)"),
  max_rank_error = c(err_ic, err_flex)
)
#>                method max_rank_error
#> 1   IC (eps = 'none')     0.09301133
#> 2 flexIC (eps = 0.02)     0.04386710

4 Speed benchmark

microbenchmark(
  IC     = flexIC(X0, R_star, eps = "none"),
  flexIC = flexIC(X0, R_star, eps = 0.02, max_iter = 50),
  times  = 100L
)
#> Unit: microseconds
#>    expr      min         lq       mean    median         uq       max neval
#>      IC  830.098   861.2715   916.0452   874.867   885.1815  4724.473   100
#>  flexIC 4759.618 17970.0535 18860.8528 18132.221 19830.4040 23247.973   100

5 Optional: Visual check

if (requireNamespace("ggplot2", quietly = TRUE)) {
  flexIC::plot_marginals_grid(X0, X_flex, bins = 30)
}
#> Showing first 4 of 5 variables.

6 Session info

sessionInfo()
#> 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] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] microbenchmark_1.5.0 mvtnorm_1.4-2        flexIC_0.1.4        
#> [4] rmarkdown_2.32      
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.7.3        cli_3.6.6          knitr_1.52         rlang_1.3.0       
#>  [5] xfun_0.61          S7_0.2.2           jsonlite_2.0.0     labeling_0.4.3    
#>  [9] glue_1.8.1         buildtools_1.0.0   htmltools_0.5.9    maketools_1.3.2   
#> [13] sys_3.4.3          sass_0.4.10        scales_1.4.0       grid_4.6.1        
#> [17] evaluate_1.0.5     jquerylib_0.1.4    MASS_7.3-66        fastmap_1.2.0     
#> [21] yaml_2.3.12        lifecycle_1.0.5    compiler_4.6.1     RColorBrewer_1.1-3
#> [25] farver_2.1.2       digest_0.6.39      R6_2.6.1           bslib_0.12.0      
#> [29] withr_3.0.3        tools_4.6.1        gtable_0.3.6       ggplot2_4.0.3     
#> [33] cachem_1.1.0