⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maxboot.src

📁 没有说明
💻 SRC
字号:
/*
** maxboot.src   MAXBoot - Bootstrapped Maximum Likelihood
**
**
** (C) Copyright 1994-1996  Aptech Systems, Inc.
** All Rights Reserved.
**
** This Software Product is PROPRIETARY SOURCE CODE OF APTECH
** SYSTEMS, INC.    This File Header must accompany all files using
** any portion, in whole or in part, of this Source Code.   In
** addition, the right to create such files is strictly limited by
** Section 2.A. of the GAUSS Applications License Agreement
** accompanying this Software Product.
**
** If you wish to distribute any portion of the proprietary Source
** Code, in whole or in part, you must first obtain written
** permission from Aptech Systems.
**
**-------------------**------------------**-------------------**-----------**
**-------------------**------------------**-------------------**-----------**
**
**> MAXBoot
**
**  Purpose:  Computes bootstrap simulation of parameters
**
**  Format:  { x,f,g,cov,retcode } = MAXBoot(dataset,vars,&fct,start)
**
**  Input:    dataset      string containing name of GAUSS data set, or
**                         name of data matrix stored in memory
**
**            vars         Kx1 vector or scalar zero.  If Kx1, character
**                         vector of labels selected for analysis,
**                         or numeric vector of column numbers in data
**                         set of variables selected for analysis.
**                         If scalar zero, all columns are selected.
**
**            fct          the name of a procedure that returns either
**                         the log-likelihood for one observation or a
**                         vector of log-likelihoods for a matrix of
**                         observations
**
**            start        Kx1 vector, start values
**
**
**  Output:   b            Kx1 vector, bootstrap estimates
**
**            f            scalar, bootstrap function at minimum
**                         (mean log-likelihood)
**
**            g            Kx1 vector, bootstrap gradient
**
**            cov          KxK matrix, covariance matrix of bootstrap
**                         estimates
**
**            retcode      return code:
**
**                            0   normal convergence
**                            1   forced exit
**                            2   maximum number of iterations exceeded
**                            3   function calculation failed
**                            4   gradient calculation failed
**                            5   Hessian calculation failed
**                            6   step length calculation failed
**                            7   function cannot be evaluated at initial
**                                parameter values
**                            8   number of elements in the gradient vector
**                                inconsistent with number of starting values
**                            9   gradient function returned a column vector
**                                rather than the required row vector
**                           10   secant update failed
**                           11   maximum time exceeded
**                           12   weights could not be found
**                           20   Hessian failed to invert
**                           34   data set could not be opened
**                           99   termination condition unknown
**
**  Globals:
**
**    _max_BootFname      string, file name of GAUSS dataset (do not include
**                        the .DAT extension) containing bootstrapped
**                        parameter estimates.  If not specified, MAXBOOT
**                        will select the file name, BOOTxxxx where xxxx is
**                        0000 incremented by 1 until a name is found that
**                        doesn't exist on the current directory.
**
**    _max_NumSample      scalar, sets number of re-samples for the bootstrap.
**                        Default = 100.
**
**    _max_MaxTime        scalar, maximum time in bootstrap.
**                        Default = 1e5 minutes.
**
**   see MAXLIK.SRC for description of additional global variables
*/

#include maxlik.ext

proc (5) = MAXBoot(dataset,var,lfct,start);
    local x,f,g,h,retcode,ofname;
    local nobs,wgt,ttime,tt0,ff,l1,fhandle,fout,g0,ncase, itdta,
        mm,mn,incr,tme,iter,xv,title0,it0,yv,zv,i,j,k,l;

    if type(dataset) == 13 and dataset $/= "";
        open fhandle = ^dataset;
        if fhandle == -1;
            if not trapchk(4);
                errorlog dataset $+ " could not be opened";
            endif;
            retp(start,error(0),error(0),error(0),error(34));
        endif;
        nobs = rowsf(fhandle);
        fhandle = close(fhandle);
    else;
        nobs = rows(dataset);
    endif;

    if _max_BootFname $== "";
        ofname = tempname("","boot",".dat");
        if ofname $== "";
            errorlog "ERROR:  file name selection for bootstrap dataset fai"\
                "led";
            retp(start,error(0),error(0),error(0),error(99));
        endif;
        _max_BootFname = ofname;
    else;
        ofname = _max_BootFname;
    endif;

    if _max_ParNames $== "";
        create fout = ^ofname with PAR_,rows(start),8;
    else;
        create fout = ^ofname with ^_max_ParNames,0,8;
    endif;
    _max_BootFname = ofname;

    tme = 0;
    iter = 1;
    ttime = date;
    tt0 = ftos(_max_NumSample,"%0*.*lf",1,0);
    clear ncase,mn,mm,ff,g0,itdta;
    do until iter > _max_NumSample or tme > _max_MaxTime;

        if __weight == 0;
            wgt = _maxboot_rnd3(nobs);
        else;
            wgt = __weight .* _maxboot_rnd3(nobs);
        endif;

        title0 = __title $+ " - " $+ ftos(iter,"%0*.*lf",1,0) $+ " of " $+
            tt0 $+ " -";

        { x,f,g,L1,retcode,L1,it0,L1,L1,_max_dat,_max_NumObs,_max_row,
            _max_dsn,_max_Diagnostic } = _Max(dataset,var,lfct,start,
            _max_Algorithm, _max_Diagnostic, _max_GradCheckTol,
            _max_LineSearch, 0, _max_GradMethod, _max_GradStep, _max_Delta,
            _max_Extrap, _max_GradProc, _max_GradTol, _max_HessProc,
            _max_Interp, _max_Key, _max_Lag, _max_MaxIters, _max_MaxTime,
            _max_MaxTry, _max_NumObs, _max_ParNames, _max_RandRadius,
            _max_Options, _max_UserSearch, _max_UserNumGrad,
            _max_UserNumHess, _max_Active, _max_dat, _max_dsn, _max_row,
            __altnam, __output, __row, title0, wgt );

        if retcode == 0;
            ncase = ncase + 1;
            mn = mn + x;
            mm = mm + x * x';
            ff = ff + f;
            g0 = g0 + g;
            itdta = itdta + it0;
            call writer(fout,x');
        endif;

        tme = ethsec(ttime,date)/6000;
        iter = iter + 1;
    endo;

    fout = close(fout);
    if ncase > 0;
        mn = mn / ncase;
        mm = mm / ncase - mn * mn';
        ff = ff / ncase;
        g0 = g0 / ncase;
        itdta[1:2] = itdta[1:2] / iter;
        itdta[3] = "BOOT";
        _max_IterData = itdta;
        if tme >= _max_MaxTime;
            retcode = 11;
        else;
            retcode = 0;
        endif;
    else;
        mn = error(0);
        ff = error(0);
        g0 = error(0);
        mm = error(0);
        _max_IterData = itdta;
        _max_IterData[3] = "";
        retcode = 99;
    endif;
    _max_NumObs = ncase;

    if __output;
        cls;
        print "bootstrapped coefficients stored in "$+ofname;
    endif;

    retp(mn,ff,g0,mm,retcode);

endp;

proc _maxboot_rnd3(n);
    local ff;

    ff = { 0.367879441171442, 0.735758882342884, 0.919698602928604,
        0.981011843123844, 0.996340153172654, 0.999405815182418,
        0.999916758850708, 0.999989750803323, 0.999998874797402,
        0.999999888574521, 0.999999989952236, 0.999999999168391,
        0.999999999936404, 0.999999999995483, 0.999999999999697,
        0.999999999999984, 1.000000000000000 };

    retp(sumc(rndu(n,1)'.>ff));
endp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -