Computes the K-fold cross-validation loss of a PhiSpace model over a grid
of numbers of components (ncomp) and then over a grid of numbers of
features per phenotype (nfeat), and returns the chosen values with the
selected features. In an interactive session the function plots each loss
curve and asks for a value unless ncomp or nfeat is given. In a
non-interactive session it chooses the ncomp with the lowest loss, and
nfeat must be given when tune_nfeat = TRUE.
tunePhiSpace(
reference,
assayName = "logcounts",
phenotypes = NULL,
YY = NULL,
ncomp = NULL,
impScores = NULL,
center = TRUE,
scale = FALSE,
tune_ncomp = TRUE,
tune_nfeat = TRUE,
ncompLimits = c(1, 100),
ncompGridSize = 20,
ncompGrid = NULL,
selectedFeat = NULL,
nfeatLimits = c(10, 15000),
nfeatGridSize = 30,
nfeatV = NULL,
Kfolds = 5,
regMethod = "PLS",
labelCode = "-1,1",
Ncores = 1,
seed = 5202056,
cellTypeThreshold = NULL,
nfeat = NULL
)SingleCellExperiment object.
Character.
Character.
Matrix.
Integer. With tune_ncomp = TRUE, the value to use after the
cross-validation instead of asking or taking the lowest loss. With
tune_ncomp = FALSE, the value to use; NULL uses the number of
columns of YY.
Matrix.
Logical.
Logical.
Logical: compute the cross-validation loss for each value in the ncomp grid.
Logical: compute the cross-validation loss for each value in the nfeat grid.
Vector.
Integer.
Vector.
Vector.
Vector.
Integer.
Vector.
Integer.
Character.
Character.
Integer.
Integer. The function sets the seed with withr::local_seed(), so the session's random-number state is restored on exit.
Integer or NULL. If a positive integer, cell types with fewer than this many cells in the reference will be removed before tuning. Only used when phenotypes is provided. Default is NULL (no filtering).
Integer. With tune_nfeat = TRUE, the number of features
per phenotype to use after the cross-validation instead of asking;
required in a non-interactive session.
A list with ncomp, nfeat, impScores (feature importance
scores), selectedFeat (selected features), and tuneNcompErrs and
tuneNfeatErrs (data frames of the cross-validation loss for each grid
value, or NULL when that parameter was not tuned).
set.seed(1)
ref <- logNormTransf(scuttle::mockSCE(ncells = 200, ngenes = 300))
# Outside an interactive session, nfeat must be given.
tuned <- tunePhiSpace(ref, assayName = "logcounts", phenotypes = "Cell_Cycle",
ncompGrid = 1:4, nfeatV = c(20, 50), Kfolds = 3,
nfeat = 50)
tuned$ncomp
tuned$tuneNcompErrs