kBET icon indicating copy to clipboard operation
kBET copied to clipboard

batch_sil with non-numeric batch codes

Open jesswhitts opened this issue 2 years ago • 1 comments

Hello,

I get the following error when running batch_sil:

R[write to console]: Error in if (!all(x == round(x))) stop("'x' must only have integer codes") : missing value where TRUE/FALSE needed

R[write to console]: In addition: R[write to console]: Warning message:

R[write to console]: In silhouette(as.numeric(batch), dd) : R[write to console]: NAs introduced by coercion

The problem comes from having non-numeric batch codes, which this line of code converts to NAs: summary(silhouette(as.numeric(batch), dd))

Can you suggest any workaround for this?

Many thanks, Jess

jesswhitts avatar Apr 13 '23 10:04 jesswhitts

Hi @jesswhitts thanks for pointing this out! A quick fix would be converting all batch codes to numeric values. If your batch covariate is a factor, you can usually convert the values of a factor to numeric with as.numeric(batch), as shown in the code. You can check if using a factor fixed the problem. I cannot reproduce the error, so it would be helpful to have a little example along with your R version. Thanks!

mbuttner avatar Jul 19 '23 17:07 mbuttner