Error in while (change > conv) { : missing value where TRUE/FALSE needed
2
4
Entering edit mode
7.2 years ago
lessismore ★ 1.4k

Hello everybody,

I am using ComBat for correcting Batch effects: 3 batches and 3 conditions.

I have my modelmatrix and my datasets ready.

sample <- row.names(Pheno_complete)
batch <- Pheno_complete$Batch_num
condition <- Pheno_complete$Stage_num
modmatrix <- model.matrix(~as.factor(condition), data=pdata)
Combat_D1_log2 <- ComBat(dat=RNA_seq_log2_D1, batch=batch, mod=modmatrix)

I get this error

Error in while (change > conv) { : missing value where TRUE/FALSE needed

Someone knows what does that mean?

Combat Batch-effect RNA-Seq • 15k views
ADD COMMENT
0
Entering edit mode

I find it strange that you are using ComBat on logged values. Should it not be performed on unlogged data? If you have a batch effect, try to correct for it in the design model of whichever RNA-seq analysis program that you are using. ComBat is an extreme form of batch correction.

In any case, it looks like there may be NA values in key parts of your data.

You have a couple of options:

Remove rows (genes?) with any NA value:

RNA_seq_log2_D1 <- RNA_seq_log2_D1[complete.cases(RNA_seq_log2_D1),]

Convert NA value to zero

RNA_seq_log2_D1[is.na(RNA_seq_log2_D1)] <- 0

Convert NA values to half the min

RNA_seq_log2_D1[is.na()] <- min(RNA_seq_log2_D1, na.rm=TRUE)/2
ADD REPLY
0
Entering edit mode

Hey Kevin, it can be any kind of values.

i found this: https://stackoverflow.com/questions/21532998/error-when-using-combat https://groups.google.com/forum/#!msg/combat-user-forum/_z8DxYQNFJ8/7UI_a2nCoUEJ

it seems there should be a problem with the variance, i dont have NA values in my datamatrix

ADD REPLY
0
Entering edit mode

Yes, I saw that thread. Rows of constant variance will cause problems too. If you are using logged data, it is more probably to have rows of constant variance due to the transformation.

Did you try ComBat on the un-logged counts?

You can check variance with the var() command. For example, to check if a row has constant variance, then use apply(RNA_seq_log2_D1, 1, var)!=0 to create a TRUE/FALSE vector, which you can then use to filter.

ADD REPLY
0
Entering edit mode

Hey Kevin, thanks for your answer. It seems there's no problem about it.

length(which ((apply(RNA_seq_log2_D1, 1, var)!=0) == "TRUE"))
[1] 21726
length(which ((apply(RNA_seq_log2_D1, 1, var)!=0) == "FALSE"))
[1] 0

I tried the Combat with the TPM and I get the same error.

ADD REPLY
0
Entering edit mode

It's kind of strange. If i quantile normalize my dataset (log2 and counts) there is no error anymore.

ADD REPLY
0
Entering edit mode

That is strange. It would be great to see the distribution of each data with the hist() function! That may give more information.

ADD REPLY
1
Entering edit mode
ADD REPLY
1
Entering edit mode

That's more like an inverse hypergeometric distribution, as opposed to normal/binomial. I wonder if that's part of the issue. There are many counts near 0.

Quantile normalising will produce a more 'normal' distribution, which is perhaps why that works.

Gracias

ADD REPLY
3
Entering edit mode

It seems you're right. So running ComBat with the not-quantile-normalized dataset and with par.prior = FALSE which assumes your distribution as nonparametric it worked!

ADD REPLY
1
Entering edit mode

That's very interesting!

ADD REPLY
1
Entering edit mode

There is another possibility: you probably didn't remove constant genes within one batch. Check the numbers batch by batch, and remove those genes with same values within one batch, and then you can perform parametric adjustment as well.

ADD REPLY
1
Entering edit mode

Could you give an example of how you could do this?

ADD REPLY
1
Entering edit mode
4.1 years ago
keryruo ▴ 20

I encountered the exact same error when I try to remove known batches using combat function, I found 2 problems matters:

  1. the type of 'dat', it should be matrix instead of data.frame;
  2. variance of variables in 'dat' should not equal zero.

Once these 2 conditions satisfied, you can run combat successfully.

I attached the code and running log below to make it more clearly.

> batch = wu_our_cli$group
> modcombat = model.matrix(~1, data=wu_our_cli)
> eRNA=wu_our_RNA[apply(wu_our_RNA,1,var)>0,]
> class(wu_our_RNA)

[1] "data.frame"

> combat_edata = ComBat(dat=as.matrix(wu_our_RNA), batch=batch, mod=modcombat, par.prior=TRUE, prior.plots=F)

Found2batches
Adjusting for0covariate(s) or covariate level(s)
Standardizing Data across genes
Fitting L/S model and finding priors
Finding parametric adjustments
Error in while (change > conv) { : missing value where TRUE/FALSE needed

> combat_edata = ComBat(dat=as.matrix(eRNA), batch=batch, mod=modcombat, par.prior=TRUE, prior.plots=F)

Found2batches
Adjusting for0covariate(s) or covariate level(s)
Standardizing Data across genes
Fitting L/S model and finding priors
Finding parametric adjustments
Adjusting the Data

> combat_edata = ComBat(dat=eRNA, batch=batch, mod=modcombat, par.prior=TRUE, prior.plots=F)

Found2batches
Adjusting for0covariate(s) or covariate level(s)
Standardizing Data across genes
Error in ((dat - t(design %*% B.hat))^2) %*% rep(1/n.array, n.array) :
  requires numeric/complex matrix/vector arguments
ADD COMMENT
0
Entering edit mode

Thanks I had the same problem, I got rid of the error when I removed rows with sd=0

ADD REPLY
0
Entering edit mode
2.1 years ago
James • 0

This is an old thread, but for anyone having the same problem, I just removed all rows that had a rowSums() of less than 10:

rows.to.keep <- rowSums(counts_data) >= 10
counts_data <- counts_data[rows.to.keep,]
ADD COMMENT

Login before adding your answer.

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