Error in champ.svd - function 'EstDimRMTv2' within champ.svd acting inconsistently?
0
0
Entering edit mode
behr201 • 0
@336ed33e
Last seen 2.6 years ago
United Kingdom

When running champ.svd() on the example dataset included with minfi I get the following error:

Error in 1:ncol(svd.obj$v) : argument of length 0

Within the champ.svd() function (code viewable here), this error occurs on line 90. However, I think the error can be traced back as follows:

#on line 75 in function splot:
v=x$v[1:y$dim,1:y$dim]  #this causes an error later on because y$dim = 1

#$dim comes from line 37 in function EstDimRMTv2:
intdim <- length(which(eigen.o$values > thdens.o$max));
return(list(cor=C,dim=intdim,estdens=estdens.o,thdens=thdens.o));

Here is the full EstDimRMTv2 function:

#EstDimRMTv2 takes 'tmp.m' as an input:
tmp.m <- beta-rowMeans(beta)  %>%  beta=myNorm

  EstDimRMTv2 <- function(data.m)
  {    
    ### standardise matrix
    M <- data.m;
    for(c in 1:ncol(M)) M[,c] <- (data.m[,c]-mean(data.m[,c]))/sqrt(var(data.m[,c]));
    sigma2 <- var(as.vector(M));
    Q <- nrow(data.m)/ncol(data.m);
    thdens.o <- thdens(Q,sigma2,ncol(data.m));
    C <- 1/nrow(M) * t(M) %*% M;

    eigen.o <- eigen(C,symmetric=TRUE);
    estdens.o <- density(eigen.o$values,from=min(eigen.o$values),to=max(eigen.o$values),cut=0);

    GenPlot(thdens.o,estdens.o,eigen.o$values);
    intdim <- length(which(eigen.o$values > thdens.o$max));
    return(list(cor=C,dim=intdim,estdens=estdens.o,thdens=thdens.o));
  }

The weird problem I am having is that when I run EstDimRMTv2 line-by-line, $dim equals 2, which does not cause an error in champ.svd(). However, when I run the full function at once, using View(EstDimRMTv2(tmp.m)), $dim equals 1, which I think is probably what's causing the error.

Does anyone know what might be causing this or how to solve it? Many thanks in advance!

minfiData ChAMP • 1.0k views
ADD COMMENT

Login before adding your answer.

Traffic: 892 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