[R] Is it possible to define another kind of NA

Keith Jewell Keith.Jewell at campdenbri.co.uk
Thu Nov 13 16:17:19 CET 2014


On 13/11/2014 11:08, Marc Girondot wrote:
> Le 13/11/2014 01:26, MacQueen, Don a écrit :
>> Along the lines of what Bert Gunter said, the ideal way to represent <LDL
>> results depends on the functions used later to analyze them. I deal with
>> such data on a daily basis and have never found it necessary to
>> incorporate that information in the same variable as the results. What
>> would you do if data were censored at both ends, both low and high?
>>
>> Anyway, the functions I use mostly incorporate that information in a
>> second variable, a ³detection indicator² variable, and that¹s what I do.
>>
>> -Don
>>
> I agree that LDL is a special case of what could be named ODL (Out of
> detection limit).
> To answer to Bert Gunter, indeed if LDL (or ODL) values are changed into
> NA, the results will be biased. That's why I would like to introduce
> another category. I don't plan to just transform them as NA.
>
> But thinking again about this problem, a LDL must be always associated
> with one value (or two in the case of ODL) that indicates the detection
> limit. In a dataset, all values have not necessarily the same limit
> depending on the experimental conditions.
> The best solution that I find is to use attributes to indicate the
> limits. A NA attribute for a NA value will be treated as a "true" NA.
> For exemple:
>
>  > values <- c(NA, 29, 30, NA, 3)
>  > attributes(values) <- list(ODL=c(NA, "[10, 40]", "[0, 40]", "[0,
> 40]", "[0, 40]"))
>  > values
> [1] NA 29 30 NA  3
> attr(,"ODL")
> [1] NA         "[10, 40]" "[0, 40]"  "[0, 40]"  "[0, 40]"
>  > values[3]
> [1] 30
>  > attributes(values)$ODL[3]
> [1] "[0, 40]"
>  > values[1]
> [1] NA
>  > attributes(values)$ODL[1]
> [1] NA
>
> The attributes are retained in data.frame. So it seems to be a good
> solution.
>
>  > essai <- data.frame(c1=values)
>  > essai
>    c1
> 1 NA
> 2 29
> 3 30
> 4 NA
> 5  3
>  > essai$c1
> [1] NA 29 30 NA  3
> attr(,"ODL")
> [1] NA         "[10, 40]" "[0, 40]"  "[0, 40]"  "[0, 40]"
>
> Thanks to the list members,
>
> Marc
>
I strongly recommend you re-read and take action on Bert Gunter's 
comment, quoted here for truth!
-----------------------------
Ouch!

The values are **NOT** missing -- they are (left) censored, and need
to be handled by appropriate censored data methods. I suggest you
(all!) either read up on this or consult someone locally who has
knowledge of such methods.

-- Bert
------------------------
You are re-inventing the wheel and yours will probably end up square!
R already has facilities for handling censored data, e.g. Surv in the 
survival package (which despite its name is applicable to applications 
other than survival analysis).



More information about the R-help mailing list