[sva] Error in density.default(x, adjust = adj) : 'x' contains missing values
2
3
Entering edit mode
anton.kratz ▴ 60
@antonkratz-8836
Last seen 1 day ago
Japan, Tokyo, The Systems Biology Instiā€¦

When running the sva function, I get an error "Error in density.default(x, adjust = adj) : 'x' contains missing values".

I have a data frame with raw RNA-seq counts with sample names in columns and gene names in rows, and another data frame describing the condition of each sample. There is only one condition column and it has 8 possible states (I cannot post the actual dataset). Here is my code:

library(sva)

mycoldata <- read.delim("contrast.txt", header = TRUE, sep = "\t")

mycountdata <- read.delim("expr_table.tsv", header = TRUE, sep = "\t")
mycountdata$checksum <- NULL
mycountdata$score <- NULL
df <- data.matrix(mycountdata)

# build the FULL model matrix
mod = model.matrix(~as.factor(condition), data=mycoldata)

# build the NULL model matrix
mod0 = model.matrix(~1,data=mycoldata)

n.sv = num.sv(df,mod,method="leek")
n.sv

# estimate the surrogate variables
svobj = sva(df,mod,mod0,n.sv=n.sv)

n.sv for this data set is 14. When I run the last command, I get the following error message:

> svobj = sva(df,mod,mod0,n.sv=n.sv)
Number of significant surrogate variables is:  14 
Iteration (out of 5 ):Error in density.default(x, adjust = adj) : 'x' contains missing values
In addition: Warning message:
In pf(fstats, df1 = (df1 - df0), df2 = (n - df1)) : NaNs produced

I found some posts describing what looks to be the same error [1][2][3], however none of these seem to have led to an accepted explanation of this error or a way to resolve this (approaches described were: just reducing the number of n.sv until it works, removing genes with low counts until it works).

[1] https://www.biostars.org/p/198820/

[2] https://support.bioconductor.org/p/78142/

[3] https://stackoverflow.com/questions/43101585/error-when-generating-the-sva-object-using-package-sva-in-r

sva • 9.0k views
ADD COMMENT
1
Entering edit mode

I had the same error, and removing low count genes from counts table (as suggested in sva tutorial, https://bioconductor.org/packages/release/bioc/vignettes/sva/inst/doc/sva.pdf) worked for me.

ADD REPLY
0
Entering edit mode
@benjamin_201314-19745
Last seen 5.1 years ago

I had a similar problem. I found that my factor variables read in as characters (which doesn't matter for some packages but it does for this one). Once I changed all my variables labeled as characters to factors the function worked.

ADD COMMENT
0
Entering edit mode
wahaha • 0
@19953279
Last seen 21 months ago
Taiwan

I found the reason, because some gene expression levels are 0 in all samples. you can add these code to check the data:

exp_mean <- apply(exp,1,mean)

filter_gene <- rownames(subset(exp_mean ,exp_mean ==0))

exp_mean2 <-exp_mean [-which(rownames(exp_mean ) %in% filter_gene),]

You can try to remove these genes.

ADD COMMENT

Login before adding your answer.

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