Dear R users: Sorry for this simple question: I am writing a function where I would need to pickup p values and make -log10 of it. The p values are from an anova output and sometime it can yield me 0. -log10 (0) [1] Inf I can not replace Inf with 0, which not case here. This is restricting me to go further in the function and out me the error. You help is highly appreciated. Thanks; -- Ram H [[alternative HTML version deleted]]
On Aug 28, 2011, at 11:37 AM, Ram H. Sharma wrote:> Dear R users: > > Sorry for this simple question: > > I am writing a function where I would need to pickup p values and make > -log10 of it. > > The p values are from an anova output and sometime it can yield me 0. > > -log10 (0) > > [1] Inf > > I can not replace Inf with 0, which not case here.Well you could, but if you did, you would be shooting yourself in the foot.> > > This is restricting me to go further in the function and out me the > error. > You help is highly appreciated.I would think that one would be better served , not by trying to redefine the log of small numbers, but rather by first putting a lowering bound on the p-values. pvec.trimmed <- pmax(pvec, 0.0000001) min(log10(pvec.trimmed)) # now would be -7 The alternative that you suggest would be putting all of the p-values of 0 in the same locations as the p-values of 1 after log transformation. That cannot be a wise idea. Rather like redefining pi to be 3.14. -- David Winsemius, MD West Hartford, CT
On 28-Aug-11 15:37:06, Ram H. Sharma wrote:> Dear R users: > Sorry for this simple question: > > I am writing a function where I would need to pickup p values > and make -log10 of it. > > The p values are from an anova output and sometime it can > yield me 0. > > -log10 (0) > > [1] Inf > > I can not replace Inf with 0, which not case here. > > > This is restricting me to go further in the function and out > me the error. > You help is highly appreciated. > > Thanks; > -- > Ram HYou cannot do anything about -log10(0) except to accept "Inf". However, since log10() switches from a numeric answer to "Inf" between 1/(10^308)) and 1/(10^309), one possibility for reporting such a result is to report "> 308): -log10(1/(10^307)) # [1] 307 -log10(1/(10^308)) # [1] 308 -log10(1/(10^309)) # [1] Inf Note that the above forces R to compute the number before applying log10() to it. You can get a bit further with: -log10(1e-322) # [1] 322.0052 -log10(1e-323) # [1] 323.0052 -log10(1e-324) # [1] Inf -log10(1e-325) # [1] Inf which may have something to do with R parsing the expression before applying log10() to it (I don;t know). However, since the p-value returned from an ANOVA will be a number rather than an expression, the first set of results is probably more relevant to your case. Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 28-Aug-11 Time: 17:12:34 ------------------------------ XFMail ------------------------------