TABLE OF CONTENTS


CmakeLikelihood/LikelihoodHazardLogSum [ Functions ]

NAME

    LikelihoodHazardLogSum --- utility to efficiently compute a sum of log-hazards

FUNCTION

Because the log function is quite slow (especially it seems on the MacIntel architecture), this function computes the sum of log-hazards by multiplying several together at a time, then taking logs.

SYNOPSIS

1614 static inline double LikelihoodHazardLogSum(int nx, double *status, double *Y)

INPUTS

    nx        number of observations
    Y         vector of length nx
    status    vector of length nx

OUTPUTS

    lik       sum of status*log(Y)

SOURCE

1618 {
1619     double lik=0;
1620     double thislik = 1;
1621     // sum LIK_MOD elements at a time
1622     for(int i=0; i<nx; i++) {
1623         thislik *= status[i] > 0 ? Y[i] : 1.0;
1624         if(i % LIK_MOD == 0){
1625             lik += log(thislik);
1626             thislik = 1;
1627         }
1628     }  
1629     lik+=log(thislik);
1630     return lik;  
1631 }