Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: moptimize lf2 evaluator syntax -- manual wrong again?


From   Jeffrey Pitblado <jpitblado@stata.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: moptimize lf2 evaluator syntax -- manual wrong again?
Date   Sat, 27 Feb 2010 23:09:37 -0600

László Sándor found some typos in the help file for Mata's -moptimize()- suite of functions:

Am I right that the manual's example on an lf2 evaluator for
-moptimize- won't run, as 'fv' is a vector here, while
-moptimize_util_matsum- expects a scalar as its last argument?
                if (todo>=1) {
                        s1  = z:/s
                        s2  = z:^2 :- 1
                        S   = (s1, s2)
                        if (todo==2) {
                                h11 = -1:/s:^2
                                h22 = -2*z:^2
                                h12 = -2*z:/s
                                H11 = moptimize_util_matsum(M, 1,1, h11, fv)
                                H22 = moptimize_util_matsum(M, 2,2, h22, fv)
                                H12 = moptimize_util_matsum(M, 1,2, h12, fv)
                                H   = (H11, H12 \ H12', H22)
                        }
                }
(From: http://www.stata.com/help.cgi?mata+moptimize() )

Also, there is a parenthesis missing in fv's defining line: fv  =
ln(normalden(y1:-p1, 0, s)

Yes, -moptimize_util_matsum()- requires a scalar as it's fifth argument. Any scalar will do here, it is merely used to speed things up when a missing value is encountered. Here is a working version of the evaluator function:

*** BEGIN
function linregevallf2(transmorphic M, real scalar todo,
                       real rowvector b, fv, S, H)
{
        y1  = moptimize_util_depvar(M, 1)
        p1  = moptimize_util_xb(M, b, 1)
        p2  = moptimize_util_xb(M, b, 2)

        s   = exp(p2)
        z   = (y1:-p1):/s

        fv  = ln(normalden(y1:-p1, 0, s))

        if (todo>=1) {
                s1  = z:/s
                s2  = z:^2 :- 1
                S   = (s1, s2)
                if (todo==2) {
                        h11 = -1:/s:^2
                        h22 = -2*z:^2
                        h12 = -2*z:/s
                        check = 0
                        H11 = moptimize_util_matsum(M, 1,1, h11, check)
                        H22 = moptimize_util_matsum(M, 2,2, h22, check)
                        H12 = moptimize_util_matsum(M, 1,2, h12, check)
                        H   = (H11, H12 \ H12', H22)
                }
        }
}
*** END

We will fix the help file in a future update.

--Jeff Pitblado
  <jpitblado@stata.com
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index