Search code examples
arraysrnormalizationloess

Trouble normalizing data using lowess method in R:


Subset of data which is producing the same NaN error:

    V1  V2  V3  V4  V5  V6  V7  V8  V9  V10 V11 V12
1   10901   1147    964 84  116 91  35  1234    7831    61  440 10
2   492 6062    342 9   1886    48  3822    396 1039    30  1   173
3   289 136 14  23  3833    50  2758    3559    227 3967    187 190
4   981 4   2   18  19  45  74  3754    548 407 2869    44
5   -1  773 67  48  272 1573    53  30  316 209 30  332
6   54  154 8920    78  89  422 4719    8   1082    779 683 1736
7   34  2753    91  15575   468 3856    3   10056   72  133 325 272
8   60  8   120 4589    45280   253 14  6   6   569 2324    16915
9   287 8   5   2441    14  4542    1   239 952 1074    121 37
10  12  1   1463    61  43  420 834 11  2057    12  95  -2

I have a data matrix and I want to normalize the arrays within, I have used this code:

library (affy)
loess.matrix<-normalize.loess(data.matrix,subset=1:nrow(data.matrix))

and I got this error:

Warning message: In normalize.loess(sample, subset = 1:nrow(sample)) : NaNs produced

I also got the following error with a larger dataset, but I think the root of the problem is the production of NaN values:

Error in simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize, : NA/NaN/Inf in foreign function call (arg 1) In addition: Warning message: In normalize.loess(data.matrix, subset = 1:nrow(data.matrix)) : NaNs produced

Has anyone encountered this before?


Solution

  • The problem was that my data contained negative values and when performing lowess normalisation NaN values were being produced.

    I handled the negative values by applying the logic below, this allowed me to successfully normalise my dataset.

    data.matrix[data.matrix <= 0]=1e-15