Code for Survival Example


data(Kidney)
Kidney = Kidney[,1:5]

## generally a good idea to scale the responce, as otherwise numerical overflow can happen.
## this is one way to do it.
Kidney$time = Kidney$time / max(Kidney$time)

## this is needed to have a corner point parametrization of the disease
corner.point = matrix(0,76,3)
for(i in 1:76)
  {
    if(Kidney$disease[i]==1) corner.point[i,] <- c(0,0,0)
    else if (Kidney$disease[i]==2) corner.point[i,] <- c(1,0,0)
    else if (Kidney$disease[i]==3) corner.point[i,] <- c(0,1,0)
    else if (Kidney$disease[i]==4) corner.point[i,] <- c(0,0,1)

  }
Kidney <- cbind(Kidney, corner.point)
names(Kidney)[6:8] = c("dis2", "dis3", "dis4")
Kidney = cbind(Kidney, ID=rep(1:38, each=2))

## define the formula
formula = inla.surv(time,event)~ age + sex + dis2 + dis3 + dis4 + f(ID, model="iid")

## run the model
mod = inla(formula, family="weibull", data=Kidney, control.inla=list(h=0.001))
 
hyper = inla.hyperpar(mod,diff.logdens=10,dz=0.5,verbose=T)


Comments