Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated fix for Isssue #120 #212

Merged
merged 3 commits into from
Jun 8, 2022
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
20 changes: 10 additions & 10 deletions R/plotLoadings.R
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ plotLoadings.mint.pls <-
if(any(study == "global"))
{
# if study == "global" then we plot the results on the concatenated data, thus direct call to plotLoadings.plsda
plotLoadings.mixo_pls(object = object, block = "X", comp = comp, ndisplay = ndisplay,
plotLoadings.mixo_pls(object = object, block = c("X", "Y"), comp = comp, ndisplay = ndisplay,
size.name = size.name,
name.var = name.var,
name.var.complete = name.var.complete,
Expand All @@ -549,11 +549,11 @@ plotLoadings.mint.pls <-
# if study != "global" then we plot the results on each study

# -- input checks
check = check.input.plotLoadings(object = object, block = "X", title = title, col = col, size.name = size.name, name.var = name.var)
check = check.input.plotLoadings(object = object, block = c("X", "Y"), study = study, title = title, col = col, size.name = size.name, name.var = name.var)

col = check$col
size.name = check$size.name
block = check$block # "X"
block = check$block # c("X", "Y")

#study needs to be either: from levels(object$study), numbers from 1:nlevels(study) or "global"
if (any(!study%in%c(levels(object$study), "global" , "all.partial")))
Expand Down Expand Up @@ -967,10 +967,10 @@ check.input.plotLoadings <- function(object,
# --
if (missing(block))
{
if (!is(object, "DA"))
if (!inherits(object, "DA"))
{
block = object$names$blocks
} else if (is(object, c("mixo_plsda", "mixo_splsda"))) {
} else if (inherits(object, c("mixo_plsda", "mixo_splsda"))) {
block = "X"
} else {
if (!is.null(object$indY))
Expand All @@ -982,17 +982,17 @@ check.input.plotLoadings <- function(object,
}
}

if (is(object, c("mixo_plsda", "mixo_splsda")) & (!all(block %in% c(1,"X")) | length(block) > 1 ))
if (inherits(object, c("mixo_plsda", "mixo_splsda")) & (!all(block %in% c(1,"X")) | length(block) > 1 ))
stop("'block' can only be 'X' or '1' for plsda and splsda object")

if (is(object, c("mixo_plsda", "mixo_splsda","pca")))
if (inherits(object, c("mixo_plsda", "mixo_splsda","pca")))
{
object$indY = 2
} else if (is(object, c("mixo_pls", "mixo_spls"))) {
} else if (inherits(object, c("mixo_pls", "mixo_spls"))) {
object$indY = 3 # we don't want to remove anything in that case, and 3 is higher than the number of blocks which is 2
}

if(!is(object, "DA"))
if(!inherits(object, "DA"))
object$indY = length(object$names$blocks)+1 # we don't want to remove anything in that case, and 3 is higher than the number of blocks which is 2

if(is.numeric(block))
Expand Down Expand Up @@ -1203,7 +1203,7 @@ get.loadings.ndisplay <- function(object,

#comp
# ----
if (is(object, c("mixo_pls","mixo_spls", "rcc")))# cause pls methods just have 1 ncomp, block approaches have different ncomp per block
if (inherits(object, c("mixo_pls","mixo_spls", "rcc")))# cause pls methods just have 1 ncomp, block approaches have different ncomp per block
{
ncomp = object$ncomp
object$X = list(X = object$X, Y = object$Y) # so that the data is in object$X, either it's a pls or block approach
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-plotLoadings.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ test_that("plotLoadings.mint.splsda works", code = {

})


test_that("plotLoadings.mint.spls works", code = {
data(stemcells)
samples <- c(1:5,60:64)
X <- stemcells$gene[samples, 1:10]
Y <- stemcells$gene[samples+5, 1:10]
S <- as.character(stemcells$study[samples])

res = mint.spls(X = X, Y = Y, ncomp = 3,
keepX = seq(3, 9, 3),
keepY = seq(3, 9, 3),
study = S)
pl_res <- plotLoadings(res, contrib = "max")

expect_is(pl_res, "list")
})


test_that("plotLoadings margin errrors is handled properly", code = {
data(nutrimouse)
Y = nutrimouse$diet
Expand Down