plotMDS dimensions bug
1
1
Entering edit mode
@jamiegearing-12556
Last seen 12 months ago
Australia

Hello,

I have just noticed a small issue with plotMDS in limma v3.48.1 when trying to create a new MDS plot showing different dimensions, using a saved MDS object.

library(limma)

sd <- 0.3*sqrt(4/rchisq(1000,df=4))
x <- matrix(rnorm(1000*6,sd=sd),1000,6)
rownames(x) <- paste("Gene",1:1000)
x[1:50,4:6] <- x[1:50,4:6] + 2

mds1 <- plotMDS(x,  col=c(rep("black",3), rep("red",3)) )

plotMDS(mds1, dim.plot = c(3, 4), col=c(rep("black",3), rep("red",3)) )
# Error in plotMDS.MDS(mds1, dim.plot = c(3, 4), col = c(rep("black", 3),  : 
#   object 'mds' not found

I think that the problem is just that the variable mds inside the plotMDS.MDS function needs to be renamed to match the current function argument, x.

Best regards,

Jamie.

function (x, labels = NULL, pch = NULL, cex = 1, dim.plot = NULL, 
    xlab = NULL, ylab = NULL, var.explained = TRUE, ...) 
{
    if (is.null(labels) & is.null(pch)) {
        labels <- colnames(x$distance.matrix.squared)
        if (is.null(labels)) 
            labels <- 1:length(x$x)
    }
    if (is.null(dim.plot)) {
        dim.plot <- x$dim.plot
    }
    else {
        if (!identical(dim.plot, x$dim.plot)) {
            x$dim.plot <- dim.plot
            lambda <- pmax(x$eigen.values, 0)
            i <- dim.plot[1]
            mds$x <- mds$eigen.vectors[, i] * sqrt(lambda[i])
            if (lambda[i] < 1e-13) 
                warning("dimension ", i, " is degenerate or all zero")
            i <- dim.plot[2]
            mds$y <- mds$eigen.vectors[, i] * sqrt(lambda[i])
            if (lambda[i] < 1e-13) 
                warning("dimension ", i, " is degenerate or all zero")
        }
    }

 # etc.
sessionInfo()
# R version 4.1.0 (2021-05-18)
# Platform: x86_64-apple-darwin17.0 (64-bit)
# Running under: macOS Mojave 10.14.6
# 
# Matrix products: default
# BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
# LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
# 
# locale:
#   [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] limma_3.48.1
# 
# loaded via a namespace (and not attached):
#   [1] compiler_4.1.0 tools_4.1.0
limma plotMDS • 1.1k views
ADD COMMENT
1
Entering edit mode
@gordon-smyth
Last seen 10 hours ago
WEHI, Melbourne, Australia

Thanks for the heads-up, now fixed.

ADD COMMENT
0
Entering edit mode

You're welcome. Thanks for the great package!

ADD REPLY

Login before adding your answer.

Traffic: 946 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6