Question: [sva] Error in density.default(x, adjust = adj) : 'x' contains missing values
2
gravatar for anton.kratz
18 months ago by
anton.kratz50
United States, San Diego, UCSD
anton.kratz50 wrote:

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 • 1.5k views
ADD COMMENTlink modified 10 weeks ago by Benjamin_2013140 • written 18 months ago by anton.kratz50

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 REPLYlink written 11 weeks ago by rodrigo.duarte880
Answer: [sva] Error in density.default(x, adjust = adj) : 'x' contains missing values
0
gravatar for Benjamin_201314
10 weeks ago by
Benjamin_2013140 wrote:

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 COMMENTlink written 10 weeks ago by Benjamin_2013140
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 102 users visited in the last hour