[R] What are the pros and cons of the log.p parameter in (p|q)norm and similar?
||@t@ @end|ng |rom dewey@myzen@co@uk
Fri Aug 6 18:02:42 CEST 2021
Thanks Bill and Duncan. I only asked for advice but I got an education too.
On 03/08/2021 21:24, Bill Dunlap wrote:
> In maximum likelihood problems, even when the individual density values
> are fairly far from zero, their product may underflow to zero.
> Optimizers have problems when there is a large flat area.
> > q <- runif(n=1000, -0.1, +0.1)
> > prod(dnorm(q))
>  0
> > sum(dnorm(q, log=TRUE))
>  -920.6556
> A more minor advantage for some probability-related functions is speed.
> E.g., dnorm(log=TRUE,...) does not need to evaluate exp().
> > q <- runif(1e6, -10, 10)
> > system.time(for(i in 1:100)dnorm(q, log=FALSE))
> user system elapsed
> 9.13 0.11 9.23
> > system.time(for(i in 1:100)dnorm(q, log=TRUE))
> user system elapsed
> 4.60 0.19 4.78
> On Tue, Aug 3, 2021 at 11:53 AM Duncan Murdoch <murdoch.duncan using gmail.com
> <mailto:murdoch.duncan using gmail.com>> wrote:
> On 03/08/2021 12:20 p.m., Michael Dewey wrote:
> > Short version
> > Apart from the ability to work with values of p too small to be
> of much
> > practical use what are the advantages and disadvantages of
> setting this
> > to TRUE?
> > Longer version
> > I am contemplating upgrading various functions in one of my
> packages to
> > use this and as far as I can see it would only have the advantage of
> > allowing people to use very small p-values but before I go ahead
> have I
> > missed anything? I am most concerned with negatives but if there
> is any
> > other advantage I would mention that in the vignette. I am not
> > about speed or the extra effort in coding and expanding the
> These are often needed in likelihood problems. In just about any
> problem where the normal density shows up in the likelihood, you're
> better off working with the log likelihood and setting log = TRUE in
> dnorm, because sometimes you want to evaluate the likelihood very far
> from its mode.
> The same sort of thing happens with pnorm for similar reasons. Some
> likelihoods involve normal integrals and will need it.
> I can't think of an example for qnorm off the top of my head, but I
> imagine there are some: maybe involving simulation way out in the
> The main negative about using logs is that they aren't always needed.
> Duncan Murdoch
> R-help using r-project.org <mailto:R-help using r-project.org> mailing list --
> To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
> Virus-free. www.avg.com
More information about the R-help