Resources

Model Definition for Exponential Distribution

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

                    SAS Sample Library

        Name: svrtexp.sas
 Description: Example Program from SAS/ETS User's Guide,
              The SEVERITY Procedure
       Title: Model Definition for Exponential 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.

--------------------------------------------------------------*/
proc fcmp outlib=sasuser.svrtdist.models;
    function EXP_DESCRIPTION() $32;
        length model $32;
        model = "Exponential Distribution";
        return(model);
    endsub;

    function EXP_PARMCOUNT();
        return(1);
    endsub;

    function EXP_LOGPDF(x,Theta);
        /* Theta : Scale */
        if (x < 0) then
            return (-180.218266); /* constant('LOGSMALL') */
        else
            return (-x/Theta - log(Theta));
    endsub;
    function EXP_PDF(x,Theta);
        /* Theta : Scale */
        if (x < 0) then
            return (0);
        else
            return (exp(-x/Theta)/Theta);
    endsub;

    function EXP_LOGCDF(x,Theta);
        /* Theta : Scale */
        if (x < 0) then
            return (-180.218266); /* constant('LOGSMALL') */
        else do;
            c = exp(-x/Theta);
            if (c < 1) then
                return (log1px(-c));
            else
                return (-180.218266); /* constant('LOGSMALL') */
        end;
    endsub;
    function EXP_CDF(x,Theta);
        /* Theta : Scale */
        if (x < 0) then
            return (0);
        else
            return (1.0 - exp(-x/Theta));
    endsub;

    function EXP_LOGSDF(x,Theta);
        /* Theta : Scale */
        if (x < 0) then
            return (0);
        else
            return (-x/Theta);
    endsub;
    function EXP_SDF(x,Theta);
        /* Theta : Scale */
        if (x < 0) then
            return (1);
        else
            return (exp(-x/Theta));
    endsub;

    subroutine EXP_PARMINIT(dim, x[*], nx[*], F[*], Ftype, Theta);
        outargs Theta;

        /* Compute estimate using method of moments */
        Theta = 0;
        n = 0;
        do i=1 to dim;
            Theta = Theta + nx[i] * x[i];
            n = n + nx[i];
        end;
        if (n = 0) then
            Theta = .;
        else
            Theta = Theta / n;
    endsub;

    function EXP_QUANTILE(p,Theta);
        /* Theta : Scale */
        if (p < 0 or p > 1) then
            return (.);
        else
            return (quantile('EXPO',p,Theta));
    endsub;

    function EXP_MEAN(x, Theta);
        return (Theta);
    endsub;
quit;