## Not run:
# ## loading a simulated bivariate longitudinal binary data with 500 subjects
# ## and 4 time points
# data(pnmtrem1.sim.data1)
# data(pnmtrem1.sim.data2)
#
# ## number of subjects, multiple responses and time points
# nsubj<-500
# nresp<-2
# ntime<-4
#
# ## sepearating the portion of data which pnmtrem1 function will use
# covmat1<-as.matrix(pnmtrem1.sim.data1[,5:6])
# covmat<-as.matrix(pnmtrem1.sim.data2[,5:7])
# mresp1<-as.matrix(pnmtrem1.sim.data1[,4])
# mresp<-as.matrix(c(pnmtrem1.sim.data1[,4],pnmtrem1.sim.data2[,4]))
#
# ## obtaining initials for \beta^*
# glm1<-glm(mresp1~-1+covmat1,family=binomial(link=probit))
# bsinit<-glm1$coef;names(bsinit)<-NULL
#
# ## initials for parameters in the baseline model, i.e. \beta^*, \lambda^*, c_1
# param01<-c(bsinit,1,log(0.5))
#
# ## obtaining initials of \beta
# # preparing data to be analyzed by mmm2
# mresp.mmm<-as.matrix(pnmtrem1.sim.data2[,4])
# id<-as.matrix(rep(seq(1:nsubj),((ntime-1)*nresp)))
# time<-as.matrix(c(rep(2,nsubj*nresp),rep(3,nsubj*nresp),rep(4,nsubj*nresp)))
# data<-cbind(id,time,mresp.mmm,covmat)
#
# # ordering data by subject ID
# data2<-NULL
# for (i in 1:nsubj){
# data.id<-data[data[,1]==i,]
# data2<-rbind(data2,data.id)
# }
# # subsetting data by response type (6th column of data2)
# data.resp1<-data2[data2[,6]==1,]
# data.resp2<-data2[data2[,6]==0,]
# data.mmm<-cbind(data.resp1[,1],data.resp1[,3],data.resp2[,3],data.resp1[,5])
# library(mmm2)
# mmm2.fit<-mmm2(data=data.mmm,nresp=2,family=binomial(link=probit),
# corstr = "exchangeable")
# binit<-coef(mmm2.fit)
#
# ## obtaining initials of \alpha
# glm3<-glm(mresp[(nsubj*nresp+1):(2*nsubj*nresp),]~-1+mresp1,family=binomial(link=probit))
# glm4<-glm(mresp[(2*nsubj*nresp+1):(3*nsubj*nresp),]~-1+
# mresp[(nsubj*nresp+1):(2*nsubj*nresp),],family=binomial(link=probit))
# glm5<-glm(mresp[(3*nsubj*nresp+1):(4*nsubj*nresp),]~-1+
# mresp[(2*nsubj*nresp+1):(3*nsubj*nresp),],family=binomial(link=probit))
# alpinit<-c(glm3$coef[1],glm4$coef[1],glm5$coef[1]);names(alpinit)<-NULL
#
# ## initials for parameters in the t \geq 2 model, i.e. \beta, \alpha, \lambda, c_2, c_3, c_4
# param02<-c(binit,alpinit,1,log(0.5),log(0.5),log(0.5))
#
# ## implicit function initials, \beta_0 and \alpha_0
# beta0<-matrix(c(0,0,0),ncol=1)
# alpha0<-matrix(c(0,0,0),ncol=1)
#
# ## covariate set to be interacted with the response history
# z<-matrix(rep(1,3*nsubj*nresp),ncol=1)
#
# fit<-pnmtrem1(covmat1=covmat1,covmat2=covmat,respmat1=mresp1,respmat2=mresp,z=z,
# nsubj=500,nresp=2,param01=param01,param02=param02,beta0=beta0,alpha0=alpha0,
# tol1=0.0001,tol2=0.0001,maxiter1=50,maxiter2=50,tun1=1,tun2=1,x01=0,eps1=10^-10,
# x02=0,eps2=10^-10,silent=FALSE,delta.print=TRUE,deltastar.print=TRUE)
#
# ## manipulation of the output
# fit
# fit$output1
# fit$maxloglik1
# fit$output2
# fit$maxloglik2
# fit$delta
# fit$delstar
# fit$empbayes## End(Not run)
Run the code above in your browser using DataLab