EDIT: I've re-read the thread and realize this sound a general question on mixed effects models than specifically for the coxme
function. In addition, for the simulation, I increased the animals per genotype per experiment, to avoid any sample-size related issues.
I have survival data from two different animal strains (WT vs KO) over 24 days that was produced in 5 different, independent experiments. Therefore, I wanted to analyze my data using Mixed effects Cox Model, for which I want to use the coxme
function from the coxme
package. In order to simulate a similar dataset, I wrote this code:
library(survival)
library(survminer)
library(coxme)
set.seed(123)
tb<-data.frame(Experiment=rep(c("Exp1","Exp2","Exp3","Exp4","Exp5",
"Exp6","Exp7","Exp8","Exp9","Exp10"),each=200),
Genotype=rep(rep(c("WT","KO"),each=100),times=10),
Mortality=rep(c(rbinom(100,size = 1,prob=0.2),
rbinom(100,size=1,prob=0.6)),times=10))
tb$TimePoint[tb$Mortality==0]<-24
tb$TimePoint[tb$Mortality==1]<-sample(1:24,replace = T,
size = length(tb$Mortality[tb$Mortality==1]))
My question is, in order to account for different mortality rates in the experiments, as well as different genotype effect in the different experiments, how should I structure the random effects? Normally for a general lmer, I would add the intercept and a random slope for the Genotype varying with the Experiment, like this: (1 + Genotype|Experiment)
. However, this doesn't seem to work with coxme
, producing the following output:
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
Does anyone knows how I should include the random slope for the coxme
function?
Thanks!