2
$\begingroup$

I need to simulate data from a cox model with specified values of the parameters: $$\lambda_0(t)exp(X \beta)$$

For reasons I don't want to get into, the scale of my X's is very large. They range between 0 and 100. When I apply the algorithm of Bender et. all (2005) explained very well in this post on Cross Validated, I cannot get reasonable parameter estimates. I believe it is because the denominator of the expression,

$$T = S^{-1}(V \,|\, \mathbf{x}) = H_0^{-1} \left( - \frac{\log(V)}{\exp(\mathbf{x}^\prime \mathbf{\beta})} \right)$$

becomes very large and forces $- \frac{\log(V)}{\exp(\mathbf{x}^\prime \mathbf{\beta})}$ to 0.

Here's the example code, shamelessly ripped from user ocram:

# baseline hazard: Weibull
# N = sample size    
# lambda = scale parameter in h0()
# rho = shape parameter in h0()
# beta = fixed effect parameter

    simulWeib <- function(N, lambda, rho, beta){
  # covariate --> N Bernoulli trials
  x <- runif(N, 0, 1)# , size = 1, prob = .5)

  # Weibull event times
  v <- runif(N)
  Tlat <- (- log(v) / (lambda * exp(beta * x)))^(1 / rho) # Inverse Weibull cdf

  # data set
  return(data.frame(id=1:N,
             time=Tlat,
             x=x))
}

Along with the subsequent test to see how well beta is estimated:

set.seed(1)
coefs = rep(0, times = 1e3)
for(k in 1:1e3){
  dat <- simulWeib(N=100, lambda=0.01, rho=1, 
               beta = 2)
  fit <- coxph(Surv(time) ~ x, data=dat)
  coefs[k] <- fit$coef
}

I get an estimate of around 0.015. I can get very precise estimate when the scale of $X^{\prime} \beta$ is smaller.

So is there any way to simulate from a cox PH model with a large X, or equivalently large $\beta$?

$\endgroup$
1
$\begingroup$

You could do the internal calculations on the log scale, then exponentiate the result:

$$H^{-1}_0(exp( log(-log(v)) - x'\beta ))$$

That should stabilize it somewhat.

The other option is to only use very small values of $\beta$ with your $x$ variable. In realistic situations $\beta$ would tend to be small in absolute value if $x$ is on a broad scale like that. Is it realistic that 2 subjects could really have a hazard ratio of $e^{200}$?

$\endgroup$
1
  • $\begingroup$ Thank you for the sanity check. I mixed up the scale of my coefficients. You're right that there's no reason for a hazard ratio of that size. $\endgroup$
    – Eli
    Feb 26 '18 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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