Computes the fitted mean matrix
mu = exp(gmean + tcrossprod(alpha, W) + offset) from the per-gene
coefficients of a negative binomial GLM, with optional
per-gene winsorisation of the log-means to median +/- winsor * MAD to
bound the influence of extreme fitted values. Exposed so downstream packages
(e.g. spiDE) can reconstruct fitted means from a fitNB result;
for the generic (intercept-free) fit pass gmean = rep(0, nrow(alpha)).
Usage
calculateMu(
gmean,
alpha,
W,
winsor = DEFAULT_WINSOR,
backend = c("cpu", "auto", "gpu"),
offset = NULL
)Arguments
- gmean
a numeric vector of per-gene intercepts (length
nrow(alpha)).- alpha
a genes x covariates matrix of coefficients.
- W
a cells x covariates design matrix.
- winsor
a numeric, the number of MADs at which per-gene log-means are winsorised (default 4);
Infdisables winsorisation.- backend
one of
"cpu"(default – always returns a base R matrix, matching this function's behaviour before GPU dispatch was added),"gpu"or"auto"(use an accelerator if one is available; the result is a torch tensor in that case, not a matrix).- offset
either
NULL(the default) or anrow(alpha)xnrow(W)matrix added to the linear predictor with a coefficient of 1, matchingfitNB'soffsetargument. Note thatwinsorclamps the total log-mean, i.e. after the offset has been added.
Value
a genes x cells matrix (or torch tensor, if backend resolves
to an accelerator) of fitted means.
Details
Runs on the accelerator when backend resolves to one (alpha/
W/gmean are pushed onto the active device via
toGPUMatrix/toGPUVector); the result is a torch
tensor in that case (convert back with toRMatrix if needed),
or a base R matrix otherwise.