Search code examples
rnormal-distribution

How to determine the standard normal loss function L(z)


I have a standard normal distribution table with 4 columns. One of the rows looks like this:

z f01(z) F01(z) L(z)
2.42 0.0213 0.9922 0.0026

I know that i can use qnorm(0.9922)to get the z-value (2.42), but now I need a function to get the L(z)-value based on the z-value. What function can I use to achieve this?

EDIT: what i was looking for L(z) is in fact called the standard normal loss function. Thanks @GavinKelly for this hint.


Solution

  • We can easily help you, if you give as a definition of L(.). Ok, let's believe the answer by Gavin Kelly.

    In that case,

    L0 <- function(x) exp(-(x^2)/2)/sqrt(2*pi) - x * (1 - pnorm(x))
    L <- function(x) dnorm(x) - x * pnorm(x, lower.tail=FALSE)
    

    is a numerically better, namely accurate also for large x, where L0 suffers from cancellation:

     > L(10)
     [1] 7.47456e-25
     > L0(10)
     [1] 7.694599e-23
    

    As the OP further asked for the inverse function as well, @Ben Bolker showed the standard solution via root finding,

     Linv <- function(y) uniroot(function(x) L(x) - y, interval=c(-10,10))$root
    

    which works in good cases, if the argument is of length 1. OTOH, if Linv itself should vectorize, and if you want it and L(.) to also work for boundary cases, there are some tricks and speedups one can do.

    ---> Nice extended answer on rpubs: http://rpubs.com/maechler/16436