0
$\begingroup$

I'm trying to write out the log hazard function of the lognormal distribution and use this in R.

Using the survival function:

enter image description here

and the hazard function:

enter image description here

I have the following for the log(hazard):

log(hazard) = $-\log(2\pi)/2-\log(\sigma)-\log(t) - ((\log(t)-\mu)^2)/(2\sigma^2) - \log(1-\phi((\log(t)-\mu)/\sigma))$

In R I think this should be:

log(hazard) = -0.5*log(2*pi)-log(sigma)-log(t) - 
               ((log(t)-mu)^2)/(2*sigma^2) - 
               log(1-pnorm(log(t),mu,sigma))

Can anyone confirm whether this is the correct syntax to use?

Thanks in advance.

$\endgroup$
2
  • $\begingroup$ How do you estimate the parameters using the log hazard? You probably want to maximise the log-likelihood instead, I guess... $\endgroup$
    – ocram
    Commented Jan 6, 2016 at 18:55
  • $\begingroup$ @ocram: why are you convinced that they want to estimate the parameters with the log hazard? $\endgroup$
    – Cliff AB
    Commented Jan 9, 2016 at 5:48

1 Answer 1

2
$\begingroup$

I think that's right. But I'm not going into to really check the details because it's unnecessary. It's much easier to calculate the log hazard directly from the definition. In other words,

logNormLogHaz <- function(x, mu, s){
    dens_vals <- dnorm(x, mu, s)
    s_vals <- 1 - pnorm(x, mu, s)
    logHazs <- log(dens_vals) - log(s_vals)
    ## More numerically stable then
    ## logHazs <- log(dens_vals/s_vals) *I think*
    return(logHazs)
}

And if you have a very good reason for explicitly writing it out as you have, you can at least use the above function to check that your new function is correct.

$\endgroup$
1
  • $\begingroup$ Just to provide more details - I want to use this log hazard function to be able to estimate the parameters mu and s. When I attempt this, my value for mu is almost identical to that obtained when fitting the lognormal aftreg/survreg survival equation, but my estimate for sigma is slightly out, so I didn't know if there was an error somewhere. $\endgroup$
    – agness13
    Commented Jan 10, 2016 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.