Resources

Model Definition for Pareto Distribution

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: svrtpare.sas
 Description: Example Program from SAS/ETS User's Guide,
              The SEVERITY Procedure
       Title: Model Definition for Pareto Distribution
     Product: SAS/ETS Software
        Keys: fitting continuous distributions
        PROC: SEVERITY
       Notes: If you run this sample program without any modification, then
              the Sasuser.Svrtdist library contains functions and subroutines
              that are identical to those in the Sashelp.Svrtdist library.
              Further, if you run this sample without any modification to the
              names of functions and subroutines, then PROC FCMP writes
              warnings of the following nature to the SAS log:
              WARNING: Function  was defined in a previous package.
                       Function  as defined in the current program will
                       be used as default when the package is not specified.
              You can ignore such warnings; they appear because the functions
              defined in this sample are already defined in the input library
              Sashelp.Svrtdist.

--------------------------------------------------------------*/
proc fcmp library=sashelp.svrtdist outlib=sasuser.svrtdist.models;
    function PARETO_DESCRIPTION() $32;
        length model $32;
        model = "Pareto Distribution";
        return(model);
    endsub;

    function PARETO_PARMCOUNT();
        return(2);
    endsub;

    function PARETO_LOGPDF(x, Theta, Alpha);
        /* Theta : Scale */
        /* Alpha : Shape */
        if (x < 0) then
            return (.);
        else do;
            return (log(Alpha/Theta) - (Alpha+1) * log1px(x/Theta));
        end;
    endsub;
    function PARETO_PDF(x, Theta, Alpha);
        /* Theta : Scale */
        /* Alpha : Shape */
        if (x < 0) then
            return (0);
        else do;
            logpdf = PARETO_LOGPDF(x, Theta, Alpha);
            if (logpdf < 174) then
                return ( exp(logpdf) );
            else
                return ( . );
        end;
    endsub;

    function PARETO_LOGCDF(x, Theta, Alpha);
        /* Theta : Scale */
        /* Alpha : Shape */
        if (x < 0) then
            return (.);
        else
            return (log1px(-(1 + x/Theta)**(-Alpha)));
    endsub;
    function PARETO_CDF(x, Theta, Alpha);
        /* Theta : Scale */
        /* Alpha : Shape */
        if (x < 0) then
            return (0);
        else
            return (1 - (1 + x/Theta)**(-Alpha));
    endsub;

    function PARETO_LOGSDF(x, Theta, Alpha);
        /* Theta : Scale */
        /* Alpha : Shape */
        if (x < 0) then
            return (0);
        else
            return (-Alpha*log1px(x/Theta));
    endsub;
    function PARETO_SDF(x, Theta, Alpha);
        /* Theta : Scale */
        /* Alpha : Shape */
        if (x < 0) then
            return (1);
        else
            return ((1 + x/Theta)**(-Alpha));
    endsub;

    subroutine PARETO_PARMINIT(dim, x[*], nx[*], F[*], Ftype, Theta, Alpha);
        outargs Theta, Alpha;
        array m[2] / nosymbols;

        /* Use Method of Moments */
        call svrtutil_rawmoments(dim, x, nx, 2, m);

        if (missing(m[1])) then do;
            Theta = .;
            Alpha = .;
        end;
        else do;
            t1 = m[2] - m[1]**2;
            t2 = 2*t1 - m[2];

            eps = constant('MACEPS');
            if (t1 < eps or t2 < eps) then do;
                Theta = m[1];
                Alpha = 2;
            end;
            else do;
                Theta = (m[1]*m[2])/t2;
                Alpha = (2*t1)/t2;
            end;
        end;
    endsub;

    function PARETO_QUANTILE(p, Theta, Alpha);
        /* Theta : Scale */
        /* Alpha : Shape */
        return (((1-p)**(-1/Alpha)-1)*Theta);
    endsub;
quit;