Search
Question: [sva] Error in density.default(x, adjust = adj) : 'x' contains missing values
2
9 months ago by
anton.kratz40
United States, San Diego, UCSD
anton.kratz40 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).