I have been trying to use coxme
to extract random slopes for each of the covariates in my model.
library (coxme)
Start <- runif(5000, 1985, 2015)
Stop <- Start + runif(5000, 2, 10)
S <- data.frame (
X1 <- runif(5000, 5.0, 7.5),
X2 <- runif(5000, 5.0, 7.5),
D <- rbinom(5000, 1, 0.8),
Letters <- sample(LETTERS, 5000, replace = TRUE),
Start <- Start,
Stop <- Stop
)
S_ind1 <- Surv (time = S$Start, time2 = S$Stop, event = S$D)
a <- coxme (S_ind1 ~ X1 + X2 + (X1 + X2|Letters), data = S)
All I get is:
Error in gchol(kfun(theta, varlist, vparm, ntheta, ncoef)) :
NA/NaN/Inf in foreign function call (arg 5)
In addition: Warning messages:
1: In sqrt(xvar * zvar) : NaNs produced
2: In sqrt(xvar * zvar) : NaNs produced
When using my own data I often get:
Error in coxme.fit(X, Y, strats, offset, init, control, weights = weights, :
'Calloc' could not allocate memory (56076596 of 8 bytes)
Is it possible at all to include random slopes using coxme
?
If not, is there any other alternative using other package?
Answer from Terry Therneau, author of the coxme
package via email - he asked me to post this here.
Below is my rewrite of your example, removing the Surv indirection and using '=' inside the data.frame call (I'm a bit surprised that <- works in that context), and adding set.seed so that the example is reproducable.
library (coxme)
set.seed(1953)
time1 <- runif(5000, 1985, 2015)
time2 <- time1 + runif(5000, 2, 10)
test <- data.frame (
x1 = runif(5000, 5.0, 7.5),
x2 = runif(5000, 5.0, 7.5),
death = rbinom(5000, 1, 0.8),
letters = sample(LETTERS, 5000, replace = TRUE),
time1 = time1,
time2 = time2)
fit1 <- coxme(Surv(time1, time2, death) ~ x1 + x2 + (1|letters), data=test)
fit2 <- coxme(Surv(time1, time2, death) ~ x1 + x2 + (1+x1 | letters), test)
fit3 <- coxme(Surv(time1, time2, death) ~ x1 + x2 + (1+x2 | letters), test)
fit4 <- coxme(Surv(time1, time2, death) ~ x1 + x2 + (1+ x1 + x2 | letters),
data=test, vinit= c(1e-6, 1e-8, 1e-8))
*1. All the models work until fit4.
I find your model worrisome, since it has a random slope but no random intercept, in the same way that all regressions through the origin worry me: I have a hard time interpeting the results. Although lme puts intercept terms in by default, coxme does not.
I was hopeful tht fit4 would work, and perhaps with better starting estimates it would. The underlying code for coxme is the hardest maximization problem that I have encountered in all my survival work, hard in the sense that the maximizer gets easily lost and never finds its way. This is a function that sometimes needs hand-holding, via limited iteration counts and/or starting estimates. I wish it were not so, and I have some long term plans to improve this by addition of an alternate MCMC based maximizer, which will in theory never get lost but at the expense of much longer computation time.
If any of the variances get too close to zero then the sqrt() message tends to arise as a function of round off error. In your test case, of course, the actual MLE is at a variance of 0. When this happens, I will often check for a zero variance directly by doing fits with a sequence of fixed variances (vfixed argument). If the likelihood is constant or increasing as the variance goes to values of 1e-6 or less, then I assume the MLE is zero and remove that random term from the model. Terry T.*