Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: monaLisa
Type: Package
Title: Binned Motif Enrichment Analysis and Visualization
Version: 1.17.0
Version: 1.17.1
Authors@R: c(
person("Dania", "Machlab", email = "dania.machlab@gmail.com", role = c("aut"),
comment = c(ORCID = "0000-0002-2578-6930")),
Expand Down Expand Up @@ -61,7 +61,7 @@ Suggests:
TxDb.Mmusculus.UCSC.mm10.knownGene
License: GPL (>= 3)
Encoding: UTF-8
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
VignetteBuilder: knitr
biocViews:
MotifAnnotation,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(ggplot2,ylim)
importFrom(glmnet,glmnet)
importFrom(glmnet,predict.glmnet)
importFrom(grDevices,col2rgb)
importFrom(grDevices,colorRampPalette)
importFrom(grid,gpar)
Expand Down Expand Up @@ -150,6 +149,7 @@ importFrom(stats,model.matrix)
importFrom(stats,p.adjust)
importFrom(stats,pbinom)
importFrom(stats,ppois)
importFrom(stats,predict)
importFrom(stats,quantile)
importFrom(stats,reorder)
importFrom(stats,runif)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# monaLisa 1.17.1

* clarifications of supported families for the stability selection

# monaLisa 1.15.3

* minor updates to adjust to breaking changes in `ggplot2` version 4
Expand Down
19 changes: 13 additions & 6 deletions R/stability_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
#'
#' @seealso \code{\link[stabs]{glmnet.lasso}} and \code{\link[glmnet]{glmnet}}
#'
#' @importFrom glmnet glmnet predict.glmnet
#' @importFrom stats model.matrix runif
#' @importFrom glmnet glmnet
#' @importFrom stats model.matrix runif predict
#' @importFrom cli cli_abort cli_inform
#'
#' @keywords internal
Expand Down Expand Up @@ -71,7 +71,7 @@
x, y, dfmax = q - 1,
penalty.factor = 1/stats::runif(ncol(x), weakness, 1), ...)

selected <- glmnet::predict.glmnet(fit, type = "nonzero")
selected <- predict(fit, type = "nonzero")
selected <- selected[[length(selected)]]
ret <- logical(ncol(x))
ret[selected] <- TRUE
Expand All @@ -92,7 +92,9 @@
#' package, but implements the randomized lasso version.
#'
#' @param x The predictor matrix.
#' @param y The response vector.
#' @param y The response vector. This should be a numeric vector (also for
#' the binomial case - in this case it will be converted to a factor
#' internally by \code{glmnet}).
#' @param weakness Value between 0 and 1 (default = 0.8).
#' It affects how strict the method will be in selecting predictors. The
#' closer it is to 0, the more stringent the selection. A weakness value
Expand All @@ -105,7 +107,8 @@
#' \code{cutoff} and \code{PFER}).
#' The available arguments to \code{.glmnetRandomizedLasso} are the same as
#' the ones for \code{\link[stabs]{glmnet.lasso}}. A typical use case would
#' be to define the \code{family} argument to \code{\link[glmnet]{glmnet}}.
#' be to define the \code{family} argument to \code{\link[glmnet]{glmnet}}
#' (currently "gaussian" and "binomial" are supported).
#' @param cutoff Value between 0 and 1 (default = 0.8) which is the cutoff
#' for the selection probability. Any variable with a selection probability
#' that is higher than the set cutoff will be selected.
Expand Down Expand Up @@ -238,7 +241,7 @@ randLassoStabSel <- function(x, y, weakness=0.8, cutoff=0.8, PFER=2,
if (!is(x, "matrix")) {
cli_abort("{.arg x} must be a {.cls matrix}")
}
.assertVector(y, type = "numeric")
.assertVector(x = y, type = "numeric")
if (nrow(x) != length(y)) {
cli_abort(paste0(
"nrow of {.arg x} and length of {.arg y} are not equal. The rows of ",
Expand Down Expand Up @@ -268,6 +271,10 @@ randLassoStabSel <- function(x, y, weakness=0.8, cutoff=0.8, PFER=2,
paste(names(glmnet.args)[i], collapse = ",")))
glmnet.args <- glmnet.args[!i]
}
if ("family" %in% names(glmnet.args) &&
!glmnet.args$family %in% c("binomial", "gaussian")) {
cli_abort("currently only binomial and gaussian families are supported")
}
}

# run randomized lasso stability selection
Expand Down
7 changes: 5 additions & 2 deletions man/randLassoStabSel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions tests/testthat/test_stability_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ test_that("randLassoStabSel() works properly", {
Y <- rnorm(n = 500, mean = 2, sd = 1)
X <- matrix(data = NA, nrow = length(Y), ncol = 50)
for (i in seq_len(ncol(X))) {
X[ ,i] <- runif(n = 500, min = 0, max = 3)
X[, i] <- runif(n = 500, min = 0, max = 3)
}
s_cols <- sample(x = seq_len(ncol(X)), size = 10, replace = FALSE)
for (i in seq_along(s_cols)) {
X[ ,s_cols[i]] <- X[ ,s_cols[i]] + Y
X[, s_cols[i]] <- X[, s_cols[i]] + Y
}

X2 <- X
Expand Down Expand Up @@ -61,6 +61,12 @@ test_that("randLassoStabSel() works properly", {
x = 3, weakness = 0.1))
}, "Ignoring the following elements")
expect_identical(ssbnf, ssbnf2)

expect_error(randLassoStabSel(x = X, y = factor(Y > 2)),
".y. must be of class .numeric.")
expect_error(randLassoStabSel(x = X, y = as.numeric(Y > 2),
glmnet.args = list(family = "multinomial")),
"currently only binomial and gaussian")
})

test_that("randLassoStabSel() is deterministic", {
Expand Down
Loading