Skip to contents

Memory-bounded access to large predictor and outcome matrices

Usage

l0glmData(
  x,
  format = "auto",
  n = NULL,
  p = NULL,
  dataset = NULL,
  transpose = NULL,
  missing = NULL,
  control = list()
)

Arguments

x

A matrix, sparse Matrix, bigmemory object/descriptor, DelayedMatrix, or path to a BED, PGEN, VCF, H5AD, h5Seurat, loom or HDF5 file.

format

"auto" detects objects/extensions. Explicit options are "matrix", "bigmemory", "delayed", "bed", "pgen", "vcf", "h5ad", "h5seurat", "loom" and "hdf5".

n, p

Sample and variant counts for BED files. PGEN stores its dimensions.

dataset

HDF5 dataset, h5Seurat assay path (default "assays/RNA/counts"), or H5AD layer (NULL selects X).

transpose

Whether to transpose the backend. NULL uses observations as rows: H5AD, h5Seurat and loom single-cell assays become cells by genes. Generic HDF5 and resident matrices retain their supplied orientation.

missing

"error" or "mean". BED/PGEN default to mean imputation; other backends default to error. Means use nonmissing training observations with positive weight in at least one response. All-missing columns use zero.

control

Named list: block.columns=256L, block.cells=2e6, max.cells=5e7, nthreads=1L, working.columns=10000L. nthreads controls selected BED decoding; screen.nthreads in l0glmFit() controls fused BED screening. VCF conversion additionally needs cache (new output prefix) and plink (PLINK 2 executable; defaults to Sys.which("plink2")). dosage=NULL imports GT hardcalls; dosage="DS" preserves expected ALT dosages. working.columns caps the resident candidate pool for large file-backed Gaussian identity ISIS fits; zero disables that cache. Its size also respects max.cells. Global checks preserve the ordinary ISIS path, and cached or small-support refits are accepted only when GIC improves.

Value

A serializable L0glm_data matrix descriptor. It retains paths or backend references and views, with bounded reads on demand.

Details

Subsets with drop=FALSE are cheap matrix views. Explicit as.matrix() respects max.cells. Sparse backends retain sparse working blocks. sisGLM() streams predictor columns, reusing its exact family-specific null context. BED screening decodes two-bit calls directly inside native OpenMP reductions. Ties and within-column summation order match resident matrices. Double-precision bigmemory sources without missing-value imputation are screened directly through their existing native mapping, using read-only access. Row/column views retain their original indexing; the operating system pages the backing file without a design-sized R allocation. Other source types and mean-imputed data use bounded working blocks.

Large file-backed Gaussian identity models with an unconstrained coefficient vector, the GIC preset, unpenalized refitting and Eigen LLT can also reuse a resident pool of up to working.columns predictors when at least three screening rounds are requested. The ordinary global ISIS path is retained. Cached candidates and small-support Gaussian refits are selected only when the original-p GIC improves. Exact repetition of a Gaussian coefficient vector avoids a redundant final file scan. Weights, offsets, compulsory terms and fixed or estimated dispersion retain their meanings. This cache uses scalar or automatic starts; a supplied ridge centre or validation set uses ordinary streamed ISIS. The diagnostics in fit$screening$working.set report the pool size and full-file scan count. Set working.columns=0L for ordinary streamed ISIS.

l0glmFit() and l0glmTune() fit the retained SIS/ISIS columns with the existing GLM/NB, joint multinomial or Cox engine. Presets and criteria retain the original predictor count, and coefficients retain the original sparse dimensions. Starts, nonnegativity, weights, offsets, interactions and local refinement keep their fitting meanings. A small explicit starting support can also be materialized directly. Intercepts in file-backed designs should be requested with intercept=TRUE, named explicitly, or declared mandatory.

Cross-validation learns imputation within each training fold. Predictions, validation and bootstrap fits reuse or relearn the corresponding training means. Source files must remain available at their saved paths.

The working IRLS design must fit within max.cells; unscreened fitting of larger designs requires a smaller active set or a larger explicit guard. This interface streams screening and source access; it does not replace every solver by an arbitrary-size row-streamed IRLS engine.

glmDist() and Ward glmCluster() accumulate distances and cut losses over row blocks. Returned centres and aggregates, and the pairwise channel-distance array, obey the same guard. Bregman agglomeration uses a bounded materialized matrix. Predictor groups retain their documented screening restrictions.

BED support is PLINK 1 variant-major, with 0/1/2 copies of BIM allele 1. PGEN uses the official pgenlibr dosage reader, with ALT alleles combined for multiallelic records. VCF conversion creates a reusable PGEN cache with input provenance; existing unrelated caches are preserved. HDF5Array handles dense and sparse H5AD layers and delayed assays; h5Seurat CSC assays use its sparse seed. The physical HDF5 layout determines how much I/O a column subset needs.

See also

l0glmFit(), l0glmTune(), sisGLM(), glmCluster() and the file-backed tutorial for reproducible million-predictor Gaussian and packed-genotype examples.

Examples

set.seed(18)
X <- matrix(rnorm(100*2000),100,2000)
y <- 2*X[,1]-2*X[,2]+rnorm(100)
source <- l0glmData(X,control=list(block.cells=20000,max.cells=30000))
fit <- l0glmFit(source,y,screen="SIS",nsis=20L,lambda="gic")
head(predict(fit,source[1:4,,drop=FALSE]))
if (FALSE) { # \dontrun{
genotype <- l0glmData("genotypes.bed",n=4000L,p=1733480L)
fit <- l0glmFit(genotype,y,family=binomial(),screen="SIS",nsis=1000L)
assay <- l0glmData("cells.h5ad",dataset="counts")
fit <- l0glmFit(assay,response,family=poisson())
} # }