Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • normalden() strange behaviour

    I have a program which calls Mata's normalden() function, which is behaving strangely and I can't work out why it's behaving as it is. In the part of the program where normalden() is called, I have a column vector called deviation and a scalar called resvar. I want to calculate the vector of normal density values for the deviation values using the residual variance stored in resvar. To do this I call:

    normalden(deviation,resvar^0.5)

    Unfortunately this call gives values which are smaller than they should be. To illustrate, I also call:

    normalden(deviation:/(resvar^0.5))/(resvar^0.5)

    which gives the correct values. For example, in one run of the program the deviation vector is equal to:

    1
    +----------------+
    1 | .3880710602 |
    2 | 4.010488868 |
    3 | 6.00246942 |
    4 | -3.155819535 |
    5 | 5.351455569 |
    6 | -1.435972333 |
    7 | -.7803928852 |
    8 | 11.09337795 |
    9 | -.5308794677 |
    10 | .244594872 |
    +----------------+


    With a resvar=28.67805607, calling normalden(deviation,resvar^0.5) gives

    1
    +---------------+
    1 | .0743752284 |
    2 | .0027977697 |
    3 | 5.53183e-08 |
    4 | 1.85649e-06 |
    5 | .0000366686 |
    6 | .0011626469 |
    7 | .0062139636 |
    8 | 5.25177e-27 |
    9 | .0513836254 |
    10 | .0742187197 |
    +---------------+



    These values are too small. Calling normalden(deviation:/(resvar^0.5))/(resvar^0.5)

    1
    +---------------+
    1 | .074492159 |
    2 | .0664407275 |
    3 | .0455416223 |
    4 | .0514770675 |
    5 | .0571204026 |
    6 | .064437141 |
    7 | .0683154238 |
    8 | .0098876768 |
    9 | .0735377498 |
    10 | .0744866874 |
    +---------------+


    whose values are correct. I simply cannot work out why the call to normalden() passing the sd as the second argument is giving incorrect values. If I try the same code directly in Mata from the command box everything works correctly, but when included into my larger program the above behaviour occurs. Everything works fine using the call normalden(deviation:/(resvar^0.5))/(resvar^0.5), so I will now use this in my program. But it would be good to understand why I am getting incorrect values using the two argument normalden() call in my program. If anyone can shed any light I'd be most grateful.

    Thanks
    Jonathan


Working...
X