[Rd] What should dnorm(0, 0, -Inf) return?
Wang Jiefei
@zwj|08 @end|ng |rom gm@||@com
Sat Dec 7 23:40:12 CET 2019
Good question, I cannot speak for R's developers but I would like to
provide some information on the problem. Here are the first few lines of
the dnorm function located at src\nmath\dnorm.c:
```
double dnorm4(double x, double mu, double sigma, int give_log)
{
#ifdef IEEE_754
if (ISNAN(x) || ISNAN(mu) || ISNAN(sigma))
return x + mu + sigma;
#endif
if(!R_FINITE(sigma)) return R_D__0;
if(!R_FINITE(x) && mu == x) return ML_NAN;/* x-mu is NaN */
if (sigma <= 0) {
if (sigma < 0) ML_ERR_return_NAN;
/* sigma == 0 */
return (x == mu) ? ML_POSINF : R_D__0;
}
....
}
```
You can clearly see where the problem is. I think either the document or
the code needs a modification.
Best,
Jiefei
On Sat, Dec 7, 2019 at 5:05 PM Weigand, Stephen D. via R-devel <
r-devel using r-project.org> wrote:
> Hi,
> Apropos of a recent Inf question, I've previously wondered if dnorm "does
> the right thing" with
>
> dnorm(0, 0, -Inf)
>
> which gives zero. Should that be zero or NaN (or NA)?
>
> The help says "'sd < 0' is an error and returns 'NaN'" and since -Inf < 0
> is TRUE, then... is this a bug?
>
> Thank you,
> Stephen
> Rochester, MN USA
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
[[alternative HTML version deleted]]
More information about the R-devel
mailing list