####################################################################
# Posterior summary of the random effects
###################################################################
#' Posterior means/medians of the random effects from a joint model fit
#' @description Returns posterior means/medians of the random effects. Note that the random effects are shared between the
#' longitudinal and survival components, and the link between these two processes via the random effects
#' is commonly known as \emph{latent association}. The formulation of the joint model is
#' is described in \code{\link{jmreg.aft}}.
#' @keywords Joint model, Posterior summary, Random effects
#' @param bayes.fit fit of the joint model using \code{jmreg.aft}.
#' @param posterior.mean returns posterior means if TRUE, and posterior medians if FALSE.
#' @details The random effects are monitored in MCMC simulations.
#' @return Returns posterior means/medians of the random effects.
#' @seealso \code{\link{jmreg.aft}}, \code{\link{jm.resid}}, \code{\link{jm.summary}}
#' @examples
#' data(pbc.long)
#' data(pbc.surv)
#' agec<-pbc.surv$age-mean(pbc.surv$age)
#' pbc.surv0<-data.frame(pbc.surv,agec=agec)
#' # use natural splines
#' lme.fit<-lme(log(bilirubin)~drug+ns(futime,2),data=pbc.long,
#' random=~ns(futime,2)|id)
#' surv.fit<-coxph(Surv(st,status2)~drug*agec,data=pbc.surv0,x=TRUE)
#' # use rand.model="ns"
#' jmfit.w<-jmreg.aft(surv.fit=surv.fit,lme.fit=lme.fit,
#' surv.model="weibull",rand.model="ns",timevar="futime",
#' n.chain=2,n.adapt = 5000, n.burn = 15000,
#' n.iter = 150000, n.thin = 5)
#' jm.reffects(jmfit.w)
#' jm.reffects(jmfit.w,posterior.mean=FALSE)
#' @export
jm.reffects<-function(bayes.fit,posterior.mean=TRUE){
if(posterior.mean){
return(list("Posterior means of the random effects"=bayes.fit[["MCMC output"]]$random.effects.mean))
} else{
return(list("Posterior medians of the random effects"=bayes.fit[["MCMC output"]]$random.effects.median))
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.