Learn R Programming

bigstatsr

R package {bigstatsr} provides functions for fast statistical analysis of large-scale data encoded as matrices. The package can handle matrices that are too large to fit in memory thanks to memory-mapping to binary files on disk. This is very similar to the format big.matrix provided by R package {bigmemory}, which is no longer used by this package (see the corresponding vignette). As inputs, package {bigstatsr} uses Filebacked Big Matrices (FBM).

LIST OF FEATURES

Note that most of the algorithms of this package don't handle missing values.

Installation

# For the CRAN version
install.packages("bigstatsr")
# For the latest version
remotes::install_github("privefl/bigstatsr")

Small example

library(bigstatsr)

# Create the data on disk
X <- FBM(5e3, 10e3, backingfile = "test")$save()
# If you open a new session you can do
X <- big_attach("test.rds")

# Fill it by chunks with random values
U <- matrix(0, nrow(X), 5); U[] <- rnorm(length(U))
V <- matrix(0, ncol(X), 5); V[] <- rnorm(length(V))
NCORES <- nb_cores()
# X = U V^T + E
big_apply(X, a.FUN = function(X, ind, U, V) {
  X[, ind] <- tcrossprod(U, V[ind, ]) + rnorm(nrow(X) * length(ind))
  NULL  ## you don't want to return anything here
}, a.combine = 'c', ncores = NCORES, U = U, V = V)
# Check some values
X[1:5, 1:5]

# Compute first 10 PCs
obj.svd <- big_randomSVD(X, fun.scaling = big_scale(), 
                         k = 10, ncores = NCORES)
plot(obj.svd)

# Cleanup
unlink(paste0("test", c(".bk", ".rds")))

Learn more with this introduction to package {bigstatsr}.

If you want to use Rcpp code, look at this tutorial.

Some use cases

Parallelization

Package {bigstatsr} uses package {foreach} for its parallelization tasks. Learn more on parallelism with {foreach} with this tutorial.

Large datasets

Bug report / Help

How to make a great R reproducible example?

Please open an issue if you find a bug.

If you want help using {bigstatsr}, please open an issue as well or post on Stack Overflow with the tag bigstatsr.

I will always redirect you to GitHub issues if you email me, so that others can benefit from our discussion.

References

  • Privé, Florian, et al. "Efficient analysis of large-scale genome-wide data with two R packages: bigstatsr and bigsnpr." Bioinformatics 34.16 (2018): 2781-2787.

  • Privé, Florian, Hugues Aschard, and Michael GB Blum. "Efficient implementation of penalized regression for genetic risk prediction." Genetics 212.1 (2019): 65-74.

Copy Link

Version

Install

install.packages('bigstatsr')

Monthly Downloads

2,840

Version

1.6.1

License

GPL-3

Maintainer

Last Published

September 9th, 2024

Functions in bigstatsr (1.6.1)

big_colstats

Standard univariate statistics
big_apply

Split-Apply-Combine
big_prodMat

Product with a matrix
big_scale

Some scaling functions
big_spLinReg

Sparse linear regression
big_spLogReg

Sparse logistic regression
big_tcrossprodSelf

Tcrossprod
covar_from_df

Numeric matrix from data frame
big_randomSVD

Randomized partial SVD
big_read

Read a file as FBM
block_size

Determine a correct value for the block.size parameter
big_univLinReg

Column-wise linear regression
bigstatsr-package

bigstatsr: Statistical Tools for Filebacked Big Matrices
big_transpose

Transpose an FBM
get_beta

Combine sets of coefficients
big_prodVec

Product with a vector
predict.mhtest

Predict method
predict.big_sp

Predict method
big_write

Write an FBM to a file
big_increment

Increment an FBM
predict.big_sp_list

Predict method
big_univLogReg

Column-wise logistic regression
big_parallelize

Split-parApply-Combine
reexports

Objects exported from other packages
plot.big_SVD

Plot method
plot.big_sp_list

Plot method
plot.mhtest

Plot method
pasteLoc

Get coordinates on plot
sub_bk

Replace extension '.bk'
pcor

Partial correlation
summary.big_sp_list

Summary method
predict.big_SVD

Scores of PCA
without_downcast_warning

Temporarily disable downcast warning
theme_bigstatsr

Theme ggplot2
as_scaling_fun

Scaling function creator
Replace

Create an Implementation of [<- For Custom Matrix-Like Types
asPlotlyText

Plotly text
AUC

AUC
FBM-class

Class FBM
FBM.code256-class

Class FBM.code256
FBM-methods

Methods for the FBM class
big_SVD

Partial SVD
big_copy

Copy as a Filebacked Big Matrix
big_cprodMat

Cross-product with a matrix
big_crossprodSelf

Crossprod
big_counts

Counts for class FBM.code256
big_cprodVec

Cross-product with a vector
COPY_biglasso_part

Train one model
big_attach

Attach a Filebacked Big Matrix
Extract

Create an Implementation of [ For Custom Matrix-Like Types
COPY_biglasso_main

Sparse regression path
big_cor

Correlation