MyNixOS website logo
Description

Fast Generation of High-Dimensional Random Vectors.

Simulate multivariate data with arbitrary marginal distributions. 'bigsimr' is a package for simulating high-dimensional multivariate data with a target correlation and arbitrary marginal distributions via Gaussian copula. It utilizes the Julia package 'Bigsimr.jl' for its core routines.

bigsimr

bigsimr is an R package for simulating high-dimensional multivariate data with a target correlation and arbitrary marginal distributions via Gaussian copula. It utilizes Bigsimr.jl for its core routines. For full documentation and examples, please see the Bigsimr.jl docs.

Features

  • Pearson matching - employs a matching algorithm (Xiao and Zhou 2019) to account for the non-linear transformation in the Normal-to-Anything (NORTA) step
  • Spearman and Kendall matching - Use explicit transformations (Lebrun and Dutfoy 2009)
  • Nearest Correlation Matrix - Calculate the nearest positive [semi]definite correlation matrix (Qi and Sun 2006)
  • Fast Approximate Correlation Matrix - Calculate an approximation to the nearest positive definite correlation matrix
  • Random Correlation Matrix - Generate random positive [semi]definite correlation matrices
  • Fast Multivariate Normal Generation - Utilize multithreading to generate multivariate normal samples in parallel

Installation

You can install the release version of the package from GitHub:

remotes::install_github("SchisslerGroup/r-bigsimr")

To get a bug fix or to use a new feature, you can install the development version from GitHub:

remotes::install_github("SchisslerGroup/r-bigsimr", ref="develop")

Note that the first invocation of bigsimr::bigsimr_setup() will install both Julia and the required packages if they are missing. If you wish to have it use an existing Julia binary, make sure that julia is found in the path. For more information see the julia_setup() function from JuliaCall.

Usage

library(bigsimr)
bs <- bigsimr_setup()
dist <- distributions_setup()

set.seed(2024-02-20)

Examples

Pearson matching

(target_corr <- bs$cor_randPD(3))
#>            [,1]       [,2]       [,3]
#> [1,]  1.0000000 -0.1770422  0.2197788
#> [2,] -0.1770422  1.0000000 -0.8153085
#> [3,]  0.2197788 -0.8153085  1.0000000

margins <- c(
  dist$Binomial(20, 0.2), 
  dist$Beta(2, 3), 
  dist$LogNormal(3, 1)
)

(adjusted_corr <- bs$pearson_match(target_corr, margins))
#>            [,1]       [,2]       [,3]
#> [1,]  1.0000000 -0.1820291  0.2874494
#> [2,] -0.1820291  1.0000000 -0.9941172
#> [3,]  0.2874494 -0.9941172  1.0000000

x <- bs$rvec(100000, adjusted_corr, margins)

bs$cor(x, bs$Pearson)
#>            [,1]       [,2]       [,3]
#> [1,]  1.0000000 -0.1712600  0.2117211
#> [2,] -0.1712600  1.0000000 -0.6679074
#> [3,]  0.2117211 -0.6679074  1.0000000

Spearman/Kendall matching

(spearman_corr <- bs$cor_randPD(3))
#>           [,1]      [,2]      [,3]
#> [1,] 1.0000000 0.4768102 0.8865416
#> [2,] 0.4768102 1.0000000 0.5318276
#> [3,] 0.8865416 0.5318276 1.0000000

(adjusted_corr <- bs$cor_convert(spearman_corr, bs$Spearman, bs$Pearson))
#>           [,1]      [,2]      [,3]
#> [1,] 1.0000000 0.4941437 0.8954010
#> [2,] 0.4941437 1.0000000 0.5497588
#> [3,] 0.8954010 0.5497588 1.0000000

x <- bs$rvec(100000, adjusted_corr, margins)

bs$cor(x, bs$Spearman)
#>           [,1]      [,2]      [,3]
#> [1,] 1.0000000 0.4663302 0.8746458
#> [2,] 0.4663302 1.0000000 0.5276638
#> [3,] 0.8746458 0.5276638 1.0000000

Nearest correlation matrix

s <- bs$cor_randPSD(200)
r <- bs$cor_convert(s, bs$Spearman, bs$Pearson)
bs$is_correlation(r)
#> [1] FALSE
p <- bs$cor_nearPD(r)
bs$is_correlation(p)
#> [1] TRUE

Fast approximate nearest correlation matrix

s <- bs$cor_randPSD(2000)
r <- bs$cor_convert(s, bs$Spearman, bs$Pearson)
bs$is_correlation(r)
#> [1] FALSE
p <- bs$cor_fastPD(r)
bs$is_correlation(p)
#> [1] TRUE

Issues

This package is just a wrapper for the Julia package. Please file any bug reports or feature requests over at the Bigsimr.jl package repo.

Metadata

Version

0.12.0

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows