## ================================================================================ ##
## generate a simulated dataset from the negative binomial mixed-effect
## independent model:
## Y_ij | G_i = g_i ~ NB(r_ij,p_i) where r_ij = exp(X^T beta)/a , p_i =1/(a*g_i+1)
## with G_i ~ log-normal(E(G_i)=1,var(G_i)=th)
set.seed(1)
sn = 5 # the number of repeated measures of each patient
n = 80 ## the number of patients
loga = - 0.5
a = exp(loga) ## dispersion parameter
logtheta <- 1.3
th = exp(logtheta) ## the variance of the gamma distributed random effect g_i
## No difference between the means of groups
## The model only has an intercept term beta0 = 0.5
b0 = 0.5
u1 = rep(exp(b0),sn) ## the mean vector for group 1 at time point 1,...,sn
u2 = rep(exp(b0),sn) ## the mean vector for group 2 at time point 1,...,sn
## Data 0 generated from the IND model
DT.ind= rNBME.R(gdist="N", n=n, a=a, th=th, u1=u1, u2=u2, sn=sn)
## Data 1
DT.ar= rNBME.R(gdist="N", n=n, a=a, th=th, u1=u1, u2=u2, sn=sn, d=0.4)
dt.ind=data.frame(CEL=DT.ind$y,Vcode=DT.ind$vn-2,ID=DT.ind$id)
dt.ar=data.frame(CEL=DT.ar$y,Vcode=DT.ar$vn-2,ID=DT.ar$id)
## ================================================================================ ##
#### Fit IND models
tst1=lmeNB(CEL~1, data=dt.ind, ID=dt.ind$ID, IPRT=T)
tst2=lmeNB(CEL~1, data=dt.ar, ID=dt.ar$ID, IPRT=T)
tst3=lmeNB(CEL~1, data=dt.ind, ID=dt.ind$ID, IPRT=T, RE="N")
tst4=lmeNB(CEL~1, data=dt.ar, ID=dt.ar$ID, IPRT=T, RE="N") #not printing
tst5=lmeNB(CEL~Vcode, data=dt.ind, ID=dt.ind$ID, IPRT=T, RE="N")
## conditional probability index
Psum5=index.batch(olmeNB=tst5, labelnp=dt.ind$Vcode >= 1, data=dt.ind, ID=dt.ind$ID)
## Fit the semi-parametric model
tst6=lmeNB(CEL~1, data=dt.ind, ID=dt.ind$ID, IPRT=T, RE="semipara")
tst7=lmeNB(CEL~Vcode, data=dt.ind, ID=dt.ind$ID, IPRT=T, RE="semipara")
## conditional probability index
Psum7=index.batch(olmeNB=tst7,labelnp=dt.ind$Vcode >= 1, data=dt.ind,
ID=dt.ind$ID, Vcode=Vcode)
## Fit the AR1 models
tst8=lmeNB(CEL~1, data=dt.ind, ID=dt.ind$ID, IPRT=T,AR=T,Vcode=dt.ind$Vcode)
tst9=lmeNB(CEL~1, data=dt.ar, ID=dt.ar$ID, IPRT=T,AR=T,Vcode=dt.ar$Vcode)
## conditional probability index
Psum9=index.batch(olmeNB=tst9, labelnp=dt.ind$Vcode >= 1, data=dt.ind,
ID=dt.ind$ID,Vcode=dt.ind$Vcode)
Run the code above in your browser using DataLab