s-news
[Top] [All Lists]

RE: [S] log(0) problem

To: "'Bruce McCullough'" <BMCCULLO@fcc.gov>
Subject: RE: [S] log(0) problem
From: "CHASALOW, SCOTT [AG/2165]" <scott.chasalow@cereon.com>
Date: Fri, 17 Dec 1999 15:50:29 -0600
Cc: "'S-NEWS'" <s-news@wubios.wustl.edu>
Sender: owner-s-news@wubios.wustl.edu
Bruce,

Sorry I can't answer your question, but it brings to
mind a somewhat related problem I had with S-plus (4.5)
quite recently.  I was dealing with a multinomial
likelihood, containing factors such as p^x.  The log-
likelihood, of course, contained summands such as xlog(p).

Now the problem.  Suppose p = 0.  That means that that class
is impossible under the model, and if x is *not* 0, the
likelihood should be 0, and the log-likelihood, -Inf.
So far, so good:

> 0^2
[1] 0

> log(0)
[1] -Inf

> 2*log(0)
[1] -Inf

> 2*(-Inf)
[1] -Inf

But suppose now that x = 0 too.  Then that (impossible) class
should contribute a factor 0^0 = 1 to the likelihood.  And so
it does in S-Plus:

> 0^0
[1] 1

However, much to my annoyance, the contribution to the log-
likelihood became NA, not 0:

> 0*log(0)
[1] NA

> 0*(-Inf)
[1] NA

Now, it seems to me that if you're going to define 0^0 as 1,
it would be only consistent and polite to define
0log(0) = log(1) = 0.  Or am I missing something here?
Are there times when you would not want 0log(0) (or for that
matter, 0*(-Inf)) to be 0?

Cheers,
Scott

Cereon Genomics
Scott.Chasalow@cereon.com

} -----Original Message-----
} From: Bruce McCullough [mailto:BMCCULLO@fcc.gov]
} Sent: Friday, 17 December, 1999 15:53
} To: s-news@wubios.wustl.edu
} Subject: [S] log(0) problem
}  
} Let "lik" be the likelihood of an invidual observation.
} 
} Doing some replication work, the other guy (using an
} inferior package) encountered a problem with log(lik) 
} when lik is close to zero.  Using S-Plus to replicate, 
} I had no such problem and so did not use the
} following lines from the other guy's code:
} 
} b = lik < 0.1^(10)               (a dummy variable)
} lik = lik*(1-b) + b*0.1^(10)
} L = log(lik)
} 
} Clearly this is not a good thing to do.  
} I ran the code on S-Plus both with and without
} these lines, and got two radically different answers.
} 
} Question: does anyone know of a published
} reference that disabuses people of this errant
} practice or its cousin: replacing values that
} are zero with a very small number?
} 
} Many thanks,
} 
} Bruce
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>