Skip to contents

Applies specified weight methods to the datasets X and Y, returning weight matrices for each method. Handles both univariate and multivariate methods, and filters out columns in X with zero standard error. This function utilizes parallel processing to handle multiple methods.

Usage

learnTwasWeights(
  X,
  Y,
  weightMethods,
  study = "",
  context = "",
  trait = "",
  numThreads = 1,
  fittedModels = NULL,
  retainFits = FALSE,
  retainFitDetail = c("slim", "full"),
  standardized = FALSE,
  dataType = NULL,
  ldSketch = NULL,
  verbose = 1,
  seed = NULL
)

Arguments

X

A matrix of samples by features, where each row represents a sample and each column a feature.

Y

A matrix (or vector, which will be converted to a matrix) of samples by outcomes, where each row corresponds to a sample.

weightMethods

A list of methods and their specific arguments, formatted as list(method1 = method1_args, method2 = method2_args), or alternatively a character vector of method names (eg, c("susie_weights", "enet_weights")) in which case default arguments will be used for all methods. methods in the list can be either univariate (applied to each column of Y) or multivariate (applied to the entire Y matrix).

study

Character. Study identity label recorded on the resulting weights.

context

Character. Context identity label recorded on the resulting weights.

trait

Character. Trait identity label recorded on the resulting weights.

numThreads

The number of threads to use for parallel processing. If set to -1, the function uses all available cores. If set to 0 or 1, no parallel processing is performed. If set to 2 or more, parallel processing is enabled with that many threads.

fittedModels

Optional named list of fitted SuSiE-family models.

retainFits

If TRUE, retain fitted model objects as attributes on returned weight matrices when supported by the weight method.

retainFitDetail

Character. Level of fit detail to retain: "slim" (default) or "full".

standardized

Logical. Whether the supplied X / Y are already standardized. Default FALSE.

dataType

Character or NULL. Data-type label recorded on the weights (e.g. "individual").

ldSketch

A genotype panel (see readGenotypes) to record on the weights as their LD sketch, or NULL.

verbose

Integer controlling verbosity level: 0 = suppress all messages, 1 = suppress external package messages (default), 2 = show all messages including those from external packages.

seed

Integer or NULL. When supplied, seeds the main-process RNG and the parallel method-fitting RNG via the BiocParallel RNGseed, for reproducibility under multi-threading. The main-process seed is scoped to the call, so the session RNG is left as it was found. NULL (default) does not seed at all.

Value

A list where each element is named after a method and contains the weight matrix produced by that method.

Examples

data(multiTraitData)
X <- multiTraitData$X[, 1:80]
Y <- multiTraitData$Y
learnTwasWeights(X, Y[, 1, drop = FALSE],
  weightMethods = list(susie_weights = list()))
#>   Fitting susie ...
#>   Fitting susie done in 0.0s
#> TwasWeights: 1 entries
#>   1 studies, 1 contexts, 1 traits, 1 methods
#>   LD sketch: NULL (individual-level fit)