\documentclass[nojss]{jss} \usepackage{amsmath,amssymb,array} \usepackage{booktabs} \usepackage{bm} \usepackage{Sweave} %\usepackage{thumbpdf} %% new commands \newcommand{\class}[1]{``\code{#1}''} \newcommand{\fct}[1]{\code{#1()}} \SweaveOpts{engine=R, eps=FALSE, keep.source = TRUE} <>= options(prompt = "R> ", digits = 4, show.signif.stars = FALSE) @ %%\VignetteIndexEntry{Bayesian Robust Generalized Mixed Models for Longitudinal Data} %%\VignettePackage{BayesRGMM} %%\VignetteDepends{BayesRGMM} %%\VignetteKeywords{Bayesian, longitudinal, mixed-effect, R, robust} \author{Kuo-Jung Lee \& Ray-Bing Chen \& Hsing-Ming Chang\\National Cheng Kung University at Taiwan \AND Keunbaik Lee \& Chanmin Kim \\Sungkyunkwan University at Korea} \Plainauthor{Kuo-Jung Lee, Ray-Bing Chen, Keunbaik Lee,Chanmin Kim} \title{Bayesian Robust Generalized Mixed Models for Longitudinal Data} \Plaintitle{Applied Econometrics with R: Package Vignette and Errata} \Shorttitle{\pkg{BayesRGMM}: Package Vignette} \Keywords{Bayesian, Longitudinal, Mixed-Effect, \proglang{R}, Robust} \Plainkeywords{Bayesian, longitudinal, mixed-effect, R, robust} \Address{ Kuo-Jung Lee \\ Deparmtne of Statistis and Institute of Data Science\\ National Cheng Kung University\\ E-mail: \email{kuojunglee@ncku.edu.tw}\\ URL: \url{https://sites.google.com/view/kuojunglee}\\ Ray-Bing Chen \\ Deparmtne of Statistis and Institute of Data Science\\ National Cheng Kung University, Taiwan\\ E-mail: \email{rbchen@ncku.edu.tw}\\ URL: \url{https://sites.google.com/view/ray-bingchenswebsite/home}\\ Keunbaik Lee \\ Department of Statistics\\ Sungkyunkwan University, Korea\\ E-mail: \email{keunbaik@skku.edu}\\ URL: \url{https://ecostat.skku.edu/eng_ecostat/intro/faculty_stat.do}\\ Chanmin Kim \\ Department of Statistics\\ Sungkyunkwan University, Korea\\ E-mail: \email{ckim.bayes@gmail.com}\\ URL: \url{https://ecostat.skku.edu/eng_ecostat/intro/faculty_stat.do}\\ } \Abstract{ \pkg{BayesRGMM} has the functionality to deal with the incomplete longitudinal studies on binary and ordinal outcomes that are measured repeatedly on subjects over time with drop-outs. Here, we briefly describe the background of methodology and provide an overview of the contents in \pkg{BayesRGMM}. } \begin{document} \SweaveOpts{concordance=TRUE} \section{Main Methodology} Denote the response vector for the $i$th subject by $\bm{y}_i=(y_{i1},\cdots,y_{it},\cdots,y_{in_i})'$ where $y_{it}$ is a response at time period $t$ ($i=1,\cdots, N$; $t=1,\cdots,n_i$). Note that the model and associated methodology can be applicable to the unequally spaced times and the distinct number of observations from subject to subject.We assume that the responses on different subjects are independent. Also, we assume that $y_{it}$'s are conditionally independent given a random vector $b_{i}$, and that $y_{it}$'s. For categorical responses, we assume that $y_{it}$ has an exponential family distribution so that generalized linear models (GLMs) can be specified by \begin{eqnarray} &&g\left\{E(y_{it})\right\}=x_{it}^T\beta+z_{it}^Tb_{i}, \label{Eq:Probit-1}\\ &&b_i=(b_{i1},\ldots,b_{iq})^T\stackrel{\mbox{indep.}}{\sim} N(0,v_i^{-1}\Sigma), \notag\\ &&v_i \stackrel{\mbox{indep.}}{\sim} \Gamma\left(\nu/2,\nu/2\right), \notag \end{eqnarray} where $\beta$ is a $p\times 1$ unknown mean parameter vectors, $x_{it}$ is a $p\times 1$ corresponding vector of covariates, $z_{it}$ is a $q\times 1$ vector, $0$ is a $n_i\times 1$ zero vector, $\Sigma$ is a $q\times q$ covariance matrix reflecting the subject variations, and $\Gamma(a,b)$ denotes the gamma distribution with shape parameter $a$ and scale parameter $b$. In this paper, we consider the normal and binary responses and the corresponding links are identity and probit, respectively. To employ Markov Chain Monte Carlo algorithm techniques for Bayesian estimates and reduce the computational complexity, we introduce a latent variable latent variable $y_{it}^*$ to associate with the binary or ordinal outcome $y_{it}$ as follows, respectively. \begin{description} \item [Binary outcome:] The unobservable latent variable $y_{it}^*$ and the observed binary outcome $y_{it}$ are connected by: \[ y_{it}=\mathbf{I}_{(y_{it}^*>0)}, \quad t = 1, \ldots, n_i, \] where $\mathbf{I}_{A}$ is the indicator of event $A$. Note that $y_{it}$ is 1 or 0 according to the sign of $y_{it}^*$. We assume that the latent variable is associated with explanatory variable $x_{it}$ and random effect $z_{it}$ with two different approaches to explaining the correlation of the repeated measures within a subject in next two sections. \item [Ordinal outcome] The atent variable $y_{it}^*$ is associated with each ordinal response $y_{it}$. Hence, the probaility of $y_{it}=k$ is modeled through the probability of $y_{it}^*$ falling into the interval of $(\alpha_{k-1},\alpha_k]$, that is, given the random effect $b_i$, \begin{eqnarray}\label{model-3} y_{it}=k \mbox{ if } \alpha_{k-1} < y_{it}^* \leq \alpha_k \mbox{ for }k=1,\ldots, K, \end{eqnarray} where $-\infty=\alpha_0<\alpha_1<\cdots<\alpha_K=\infty$. As consequence, we have the following result: \begin{eqnarray*} p(y_{it}=k | b_i)=p(\alpha_{k-1}< y_{it}^* \leq \alpha_{k} | b_i), \end{eqnarray*} for $k=1,\ldots,K$. \end{description} We assume that the latent variable is associated with explanatory variable $x_{it}$ and random effect $z_{it}$ with two different approaches to explaining the correlation of the repeated measures within a subject in next two sections. \subsection{Modified Cholesky Decomposition with Hypersphere Decomposition} We assume \[ y_{it}^*=x_{it}^T\beta+z_{it}^Tb_i+\epsilon_{it}, \] where $\epsilon_{it}$'s are prediction error and are assumed as \[ \bm{\epsilon}_i=(\epsilon_{i1},\ldots,\epsilon_{in_i})^T \stackrel{indep.}{\sim} N(0,R_i) \] with a correlation matrix $R_i$. Then the model~\eqref{Eq:Probit-1} is equivalent to, for $i=1, \ldots, N$ and $t=1, \ldots, n_i$, \begin{equation}\label{Eq:ProbitLatentVariable} \begin{aligned} y_{it} &= \begin{cases} 1, & y_{it}^*>0; \\ 0 & \mbox{otherwhise}. \end{cases} \end{aligned} \end{equation} Let $\bm{y}_i^* = (y_{i1}, \ldots, y_{in_i})'$ and rewrite~\eqref{Eq:ProbitLatentVariable} in matrix form as \begin{eqnarray*} \bm{y}_i^*=X_i\beta+Z_i b_i +\bm{\epsilon}_i, \end{eqnarray*} where $X_i$ and $Z_i$ are $n_i\times p$ and $n_i\times q$ matrices and defined as follows, respectively, \begin{eqnarray*} X_i=\left( \begin{array}{c} x_{i1}^T \\ \vdots \\ x_{in_i}^T \\ \end{array} \right), Z_i=\left( \begin{array}{c} z_{i1}^T \\ \vdots \\ z_{in_i}^T \\ \end{array} \right) . \end{eqnarray*} On account of identifiability, $R_i$ is restricted as a correlation matrix. In addition to the diagonal elements equal to 1 and off-diagonal elements between -1 and 1, $R_i$ is required to be a positive definite matrix. Moreover, the number of parameters to be estimated increases quadratically with the dimension of the matrix. In order to model $R_{i}$ being positive definite, while alleviating the computational expensive, we propose a modeling of the correlation matrix using the hypersphere decomposition (HD) approach \citep{Zhang:etal:2015}. The correlation matrix $R_i$ is reparameterized via hyperspherical coordinates \citep{Zhang:etal:2015} by the following decomposition: \begin{eqnarray*} R_i=F_iF_i^T, \end{eqnarray*} where $F_i$ is a lower triangular matrix with the $(t, j)$th element $f_{itj}$ given by {\small \begin{eqnarray*} f_{itj}=\left\{ \begin{array}{ll} 1, & \hbox{for $t=j=1$;}\\ \cos(\omega_{itj}), & \hbox{for $j=1$, $t=2,\cdots,n_i$;} \\ \cos(\omega_{itj})\prod_{r=1}^{j-1}\sin(\omega_{itr}), & \hbox{for $2\leq j>= # Simulation study for MCD correlation structure library(BayesRGMM) rm(list=ls(all=TRUE)) Fixed.Effs = c(-0.2, -0.3, 0.8, -0.4) P = length(Fixed.Effs) q = 1 T = 5 N = 100 num.of.iter = 100 HSD.para = c(-0.5, -0.3) a = length(HSD.para) w = array(runif(T*T*a), c(T, T, a)) for(time.diff in 1:a) w[, , time.diff]=1*(as.matrix(dist(1:T, 1:T, method="manhattan")) ==time.diff) HSD.sim.data = SimulatedDataGenerator(Num.of.Obs = N, Num.of.TimePoints = T, Fixed.Effs = Fixed.Effs, Random.Effs = list(Sigma = 0.5*diag(1), df=3), Cor.in.DesignMat = 0., Missing = list(Missing.Mechanism = 2, RegCoefs = c(-1.5, 1.2)), Cor.Str = "HSD", HSD.DesignMat.para = list(HSD.para = HSD.para, DesignMat = w)) hyper.params = list( sigma2.beta = 1, sigma2.delta = 1, v.gamma = 5, InvWishart.df = 5, InvWishart.Lambda = diag(q) ) HSD.output = BayesRobustProbit(fixed = as.formula(paste("y~-1+", paste0("x", 1:P, collapse="+"))), data=HSD.sim.data$sim.data, random = ~ 1, HS.model = ~IndTime1+IndTime2, Robustness=TRUE, subset = NULL, na.action='na.exclude', hyper.params = hyper.params, num.of.iter = num.of.iter, Interactive = FALSE) original = options(digits = 4) Model.Estimation = BayesRobustProbitSummary(HSD.output) cat("\nCoefficients:\n") print(Model.Estimation$beta.est.CI) cat("\nParameters in HSD model:\n") print(Model.Estimation$delta.est.CI) cat("\nRandom effect: \n") print(Model.Estimation$random.cov) cat("\nModel Information:\n") print(Model.Estimation$model.info) cat("\nEstimate of Ri: \n") print(Model.Estimation$Ri, quote = FALSE) options(original) @ \subsection{Simulation 2: ARMA Correlation Structure} To model the serial dependence for the repeated measurement, we consider an ARMA(1, 1) correlation structure with \[ \phi = 0.4, \qquad \mbox{and}\qquad \psi = 0.2. \] <>= library(BayesRGMM) rm(list=ls(all=TRUE)) Fixed.Effs = c(-0.2,-0.8, 1.0, -1.2) P = length(Fixed.Effs) q = 1 T = 10 N = 100 num.of.iter = 100 ARMA.sim.data = SimulatedDataGenerator(Num.of.Obs = N, Num.of.TimePoints = T, Fixed.Effs = Fixed.Effs, Random.Effs = list(Sigma = 0.5*diag(1), df=3), Cor.in.DesignMat = 0., list(Missing.Mechanism = 2, RegCoefs = c(-1.5, 1.2)), Cor.Str = "ARMA", ARMA.para=list(AR.para = 0.4, MA.para=0.2)) ARMA.output = BayesRobustProbit(fixed = as.formula(paste("y~-1+", paste0("x", 1:P, collapse="+"))), data=ARMA.sim.data$sim.data, random = ~ 1, Robustness=TRUE, subset = NULL, na.action='na.exclude', arma.order = c(1, 1), num.of.iter = num.of.iter, Interactive = FALSE) original = options(digits = 4) Model.Estimation = BayesRobustProbitSummary(ARMA.output) cat("\nCoefficients:\n") print(Model.Estimation$beta.est.CI) cat("\nAMRA parameters:\n\n") print(Model.Estimation$arma.est) cat("\nRandom effect: \n") print(Model.Estimation$random.cov) cat("\nModel Information:\n") print(Model.Estimation$model.info) options(original) @ \subsection{Ordinal Outcome} We consider a simple random intercept model ($q=1$). For $k = 1, 2, 3$ and $t=1,\ldots,n_i$, the model is given by: \begin{align} &y_{it}^*=\beta_{1}Time_{it}+\beta_{2}Group_{i}+\beta_{3}Time_{it}\times Group_{i}+b_{i0}+\epsilon_{it},\label{sim-1}\\ &b_{i0}\sim N(0,\sigma_b^2),\label{sim-2}\\ &\epsilon_{i}=(\epsilon_{i1},\ldots,\epsilon_{in_i})^T\sim N(0,R_i),\label{sim-3} \end{align} where $Time_{it}\sim N(0,1)$ and $Group_{i}$ equals 0 or 1 with approximately the same sample size for each group. The true parameters in the simulations are as below: \begin{eqnarray*} &&(\beta_{01},\beta_{02})=(-0.5,0.5);~~(\beta_1,\beta_2,\beta_3)=(-0.1,0.1,-0.1);~~ \sigma_b^2=0.2. \end{eqnarray*} The model for correlation matrix $R_i$ is given by \begin{eqnarray} \log\left(\frac{\omega_{itj}}{\pi-\omega_{itj}}\right)=\delta_1 1_{(|t-j|=1)}+\delta_2 1_{(|t-j|=2)}, \end{eqnarray} where $(\delta_1,\delta_2)=(-0.9,-0.6)$. We consider a data that is missing completely at random (MCAR) with a machine defined by \begin{align*} \eta_{it} &= -0.7\times y_{t-1, i} -0.2\times y_{t-2, i}-0.1\times y_{t-3, i}; \end{align*} Then the missing probability depends on $\eta_{it}$'s defined as \[ p^{\mbox{miss}}_{it} = \frac{e^{\eta_{it}}}{1+e^{\eta_{it}}}. \] The data for subject $i$ at time point $t$ is missing according to three observed responses for the subject. <>= library(BayesRGMM) rm(list=ls(all=TRUE)) Fixed.Effs = c(-0.1, 0.1, -0.1) #c(-0.8, -0.3, 1.8, -0.4) #c(-0.2,-0.8, 1.0, -1.2) P = length(Fixed.Effs) q = 1 #number of random effects T = 7 #time points N = 100 #number of subjects Num.of.Cats = 3 #in KBLEE simulation studies, please fix it. num.of.iter = 1000 #number of iterations HSD.para = c(-0.9, -0.6) #the parameters in HSD model a = length(HSD.para) w = array(runif(T*T*a), c(T, T, a)) #design matrix in HSD model for(time.diff in 1:a) w[, , time.diff] = 1*(as.matrix(dist(1:T, 1:T, method="manhattan")) ==time.diff) x = array(0, c(T, P, N)) for(i in 1:N){ #x[,, i] = t(rmvnorm(P, rep(0, T), AR1.cor(T, Cor.in.DesignMat))) x[, 1, i] = 1:T x[, 2, i] = rbinom(1, 1, 0.5) x[, 3, i] = x[, 1, i]*x[, 2, i] } DesignMat = x #Generate a data with HSD model #MAR CPREM.sim.data = SimulatedDataGenerator.CumulativeProbit(Num.of.Obs = N, Num.of.TimePoints = T, Num.of.Cats = Num.of.Cats, Fixed.Effs = Fixed.Effs, Random.Effs = list(Sigma = 0.5*diag(1), df=3), DesignMat = DesignMat, Missing = list(Missing.Mechanism = 2, MissingRegCoefs=c(-0.7, -0.2, -0.1)), HSD.DesignMat.para = list(HSD.para = HSD.para, DesignMat = w)) print(table(CPREM.sim.data$sim.data$y)) print(CPREM.sim.data$classes) BCP.output = BayesRobustProbit(fixed = as.formula(paste("y~", paste0("x", 1:P, collapse="+"))), data=CPREM.sim.data$sim.data, random = ~ 1, Robustness = TRUE, subset = NULL, na.action='na.exclude', HS.model = ~IndTime1+IndTime2, hyper.params=NULL, num.of.iter=num.of.iter, Interactive = FALSE) BCP.Est.output = BayesRobustProbitSummary(BCP.output) BCP.Est.output @ \bibliography{BayesRGMM} \end{document}