Missing value where TRUE/FALSE needed in R
0
0
Entering edit mode
5.0 years ago

First, I pre-process my dataset (TCGA breast cancer including GE and CNA) like the way the below paper did on TCGA cutaneous melanoma: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5559859/pdf/12864_2017_Article_3990.pdf (Data analysis, Page 9 of 12)

At the end of pre-processing, I have TCGA BRCA Gene expression (478 genes - 981 samples) and TCGA BRCA CNA (589 genes - 981 samples), assigned as c_exp and c_cna , respectively. For the above study, they process their dataset and then perform integrative analysis using the analysis tool ANCut.

Next, the above group of authors developed a novel tool: AWNCut: https://www.ncbi.nlm.nih.gov/pubmed/30094873 and continue to use the above pre-processed dataset (ANCut) to perform analyses using AWNCut.

Now, I've been applying my pre-processed dataset to AWNCut.

#library
source("AWNCut_fun.R") #https://github.com/shuanggema/AWNCut/blob/master/AWNCut_fun.R
#This sets up the initial parameters
lambda <- seq(1,15,0.5) #Tuning parameter lambda
Tau <- seq(0.1,1.5,0.1) #Tuning parameter tau 
K=7; #Number of clusters 
X=t(c_exp) #row=patients, column=gene
Z=t(c_cna) #row=patients, column=gene

Tune1 <- AWNcut.TuningSelection(X, Z, K, lambda, Tau, B=500, L=1000)

I run into a problem:

Error in if (OP.value <= OP.value.old) {:

Missing value where TRUE/FALSE needed

In addition: there were 50 or more warnings

I do some researches and know that I get this problem when I am trying to compare the missing value (NA, NAN,...) with boolen value (TRUE/FALSE). But when I check my dataset:

tableis.na(c_exp))
#FALSE 
#468918 
tableis.na(c_cna))
#FALSE 
#577809 
table(is.finite(c_exp))
#TRUE 
#468918 
table(is.finite(c_cna))
#TRUE 
#577809

Please help me clarify what problem I am facing? Any suggestion is appreciated!

R Clustering • 3.7k views
ADD COMMENT
1
Entering edit mode

Have you ran debug(AWNcut) and caledl AWNcut.TuningSelection with your input? From the source code https://github.com/shuanggema/AWNCut/blob/1af5af8498acfdddb69938bab9cbf58fe04de96c/AWNCut_fun.R there seems to be a few places where a missing value could arise

ADD REPLY
0
Entering edit mode

Hi Russhh, I've just written additionally a code line like you said: debug(AWNcut) and it doesn't report any problem?

And what does "caledl AWNcut.TuningSelection with your input" means? can you figure it out?

ADD REPLY
1
Entering edit mode

Sorry, that was a typo. Call AWNcut.TuningSelection with your input ...

ADD REPLY
0
Entering edit mode

There's an introduction to using the debugger in "Advanced R": https://adv-r.hadley.nz/debugging.html#browser

ADD REPLY
0
Entering edit mode
> debug(AWNcut)
> Tune1 <- AWNcut.TuningSelection(X, Z, K, lambda, Tau, B=500, L=1000)
debugging in: AWNcut(X, Z, K, lambda, Tau, B, L = 1000)
debug at AWNCut_fun.R#56: {
    X <- scale(X)
    Z <- scale(Z)
    Para <- as.data.frame(cbind(rep(lambda, each = length(Tau)), 
        rep(Tau, length(lambda))))
    out <- list()
    for (para in 1:nrow(Para)) {
        lam <- Para[para, 1]
        tau <- Para[para, 2]
        p1 <- ncol(X)
        p2 <- ncol(Z)
        w1 <- rep(1/sqrt(p1), p1)
        w2 <- rep(1/sqrt(p2), p2)
        b <- 0
        ws.old <- c(w1, w2)
        ws <- rep(0, p1 + p2)
        Cs.old <- matrix(rep(0, nrow(Z) * K), nrow(Z), K)
        for (i in 1:nrow(Z)) {
            Cs.old[i, sample(K, 1)] <- 1
        }
        while ((b <= B) || (sum(ws - ws.old)/sum(ws.old) >= 0.001)) {
            b <- b + 1
            wm1 <- AWNcut.W(X, Z, ws.old)
            WX1 <- wm1[[1]]
            WZ1 <- wm1[[2]]
            a1 <- AWNcut.OP(X, Z, WX1, WZ1, Cs.old, tau)
            OP.value.old <- a1$TOP + lam * sum(ws.old * a1$Cor.perfeature)/(p1 + 
                p2)
            Cs <- AWNcut.UpdateCs(WX1, WZ1, K, Cs.old)
            ws <- AWNcut.UpdateWs(X, Z, K, WX1, WZ1, b, Cs, ws.old, 
                tau)
            wm2 <- AWNcut.W(X, Z, ws)
            WX2 <- wm2[[1]]
            WZ2 <- wm2[[2]]
            a2 <- AWNcut.OP(X, Z, WX2, WZ2, Cs, tau)
            OP.value <- a2$TOP + lam * sum(ws * a2$Cor.perfeature)/(p1 + 
                p2)
            if (OP.value <= OP.value.old) {
                des <- rbinom(1, 1, Prob(OP.value, OP.value.old, 
                  L, b))
                if (des == 1) {
                  Cs.old <- Cs
                  ws.old <- ws
                }
                else {
                  Cs <- Cs.old
                  ws <- ws.old
                }
            }
            else {
                Cs.old <- Cs
                ws.old <- ws
            }
        }
        out[[para]] <- list(lambda = lam, tau = tau, Cs = Cs.old, 
            ws = ws.old, OP.value = OP.value)
    }
    return(out)
}
Browse[2]> AWNcut.TuningSelection
function(X, Z, K, lambda, Tau, B=500, L=1000){
  out <- AWNcut(X, Z, K, lambda, Tau, B, L=1000)
  Para <- as.data.frame(cbind(rep(lambda,each=length(Tau)),rep(Tau,length(lambda))))
  dbi <- NULL
  for(i in 1:nrow(Para)){
    Cs <- out[[i]]$Cs
    ws <- out[[i]]$ws
    dbi <- c(dbi, DBI(cbind(X,Z),K,Cs,ws))
  }
  return(list(num=which.max(dbi),Table=t(cbind(Para,dbi)), lam=Para[which.max(dbi),1], tau=Para[which.max(dbi),2], DBI=max(dbi)))
}
<bytecode: 0x1409c5710>
ADD REPLY
0
Entering edit mode
#This sets up the initial parameters
lambda <- seq(1,15,0.5) #Tuning parameter lambda
Tau <- seq(0.1,1.5,0.1) #Tuning parameter tau 
K=7; #Number of clusters 
X=t(c_exp) #row=patients, column=gene
Z=t(c_cna) #row=patients, column=gene

Tune1 <- AWNcut.TuningSelection(X, Z, K, lambda, Tau, B=500, L=1000)

I assigned c_exp to X, c_cna to Z, K=7, lambda = seq(1,15,0.5), and Tau <- seq(0.1,1.5,0.1) as you can see, in which c_exp and c_cna are my two data as matrix equivalent to gene expression and CNA, respectively

ADD REPLY

Login before adding your answer.

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