jtleek / sva-devel

28 stars 46 forks source link

Iteration (out of 5 ):Error in density.default(x, adjust = adj) : 'x' contains missing values #47

Closed romunov closed 3 years ago

romunov commented 3 years ago

Got the above error when I tried to use the null model as model of interest (assuming I don't have any other variable available).

mod <- model.matrix(~ 1, data = mydata)
n.sv <- num.sv(dat, mod = mod, method = "be")

svaseq(dat, mod = mod, n.sv = n.sv)

Using a variables in the model solved the problem

mod <- model.matrix(~ SomeVariable, data = mydata)
jieeewu commented 2 years ago

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 should remove these genes.

maggiebr0wn commented 1 year ago

Hello, I am also getting the same error. I've filtered for all genes with 0 gene expression, and the min mean expression in my matrix is 0.013:

sva_out <- sva(

  • monocytes_mat,
  • mod = biovar,
  • mod0 = adjvar) Number of significant surrogate variables is: 6 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 min(rowMeans(monocytes_mat)) [1] 0.01336896