AFT Model - logProb of data node is.censored[8]: logProb is -Inf

6 views
Skip to first unread message

Colton Padilla

unread,
Jun 11, 2024, 5:32:48 PMJun 11
to nimble-users
Hi everyone,

I am running an example accelerated failure time model from some code that I found at this link (https://arxiv.org/pdf/2005.05952). I had attempted my own version with simulated code that did not work, so I opted to go through an example. I attempted to run the model through nimble, but I am getting a warning about logProb of both is.censored and lambdas. Could someone point me in the correct direction as to where I may be going wrong? I thought the interval set up was correct but the model runs correctly through JAGS.

library(KMsurv)
data("larynx")
larynx

cens <- matrix(c(larynx$time, rep(NA, length(larynx$time))),
               nrow = length(larynx$time), ncol = 2)
larynx$time[larynx$delta == 0] <- NA
is.censored <- as.numeric(is.na(larynx$time))

larynx$age <- as.numeric(scale(larynx$age))
larynx$diagyr <- as.numeric(scale(larynx$diagyr))
larynx$stage <- as.factor(larynx$stage)
X <- model.matrix(~ stage + age + diagyr, data = larynx)

larynx.weibull.model <- nimbleCode({
  for(i in 1:n){
    # Survival and censoring times
    is.censored[i] ~ dinterval(time[i], cens[i, 1])
    time[i] ~ dweib(alpha, lambda[i])
    lambda[i] <- exp(-mu[i] * alpha)
    mu[i] <- inprod(beta[1:Nbetas], X[i,])
  }
 
  ## priors for betas
  for(j in 1:Nbetas){
    beta[j] ~ dnorm(0, 0.001)
  }
 
  ### prior for shape
  alpha ~ dunif(0, 10)
 
})

d.jags <- list(time = larynx$time, cens = cens,
               X = X,
               is.censored = is.censored)
c.jags <- list(Nbetas = ncol(X), n = nrow(larynx))
i.jags <- list(beta = rnorm(ncol(X)), alpha = runif(1))
p.jags <- c("beta", "alpha", "lambda", "is.censored")

# Model
model <- nimbleModel(code = larynx.weibull.model,
                     data = d.jags,
                     inits = i.jags,
                     constants = c.jags,
                     calculate = F)


# Configure
confMCMC <- configureMCMC(model,
                          monitors = p.jags,
                          thin = 1,
                          useConjugacy = F,
                          enableWAIC = F)



# Build the MCMC
nimMCMC <- buildMCMC(confMCMC)

# Compile the model
Cnim <- compileNimble(model)

# Now compile model and MCMC
CnimMCMC <- compileNimble(nimMCMC, project = model)

# Run to check time
mcmcout <- runMCMC(CnimMCMC,
                   niter = 10000,
                   nburnin = 1000,
                   thin = 1,
                   nchains = 3,
                   samplesAsCodaMCMC = T,
                   summary = T,
                   WAIC = F)
mcmcout$summary$all.chains

Chris Paciorek

unread,
Jun 13, 2024, 3:00:22 PMJun 13
to Colton Padilla, nimble-users
Hi Colton,

It looks like you need valid (i.e., consistent with the censoring value) initial values for the `time` variable for the cases where the value is censored (i.e., where `time[i]` is unknown and will be estimated as part of the MCMC).

Nimble doesn't have a way of initializing those values in a way that they are guaranteed to be valid because we just use the prior, which doesn't take account of the `dinterval` constraint.
I believe JAGS must have implemented an initialization procedure that deals with the constraint, and at various points in the past, I've wanted to add functionality to handle this but I've never found the time.

-chris

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/e89f1ce9-ee74-4001-9d0f-dccc644d8934n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages