# _meta.shrinkage_: An R Package for Meta-Analyses for Simultaneously Estimating Individual Means
## 2 Background
### Restricted Maximum Likelihood Estimators under Ordered Means  
We consider the restricted maximum likelihood (RML) estimator when the individual means are ordered. Without loss of generality, we consider the increasing order \(\mu_{1}\leq\ldots\leq\mu_{G}\). This indicates that \(\boldsymbol{\mu}\) belongs to \(\{(\mu_{1},\ldots,\mu_{G}):\mu_{1}\leq\ldots\leq\mu_{G}\}\). If there are such parameter constraints, they should be incorporated into the estimators in order to improve the estimation accuracy [20]. The RML estimator satisfying \(\delta_{1}\leq\ldots\leq\delta_{G}\) is calculated by  
\[\delta_{l}^{\text{RML}}=\max_{1\leq s\leq i\leq t\leq s}\min_{i=s}\frac{\sum_{ j=s}^{t}Y_{j}}{t-s+1}.\]  
The above formula is called the pool-adjacent violators algorithm (PAVA). The computation requires the \"average-min-max\" steps (Figure 1). We developed an R function \"rml(. )\" in our R package to perform the matrix-based computation of Figure 1. This R function initially computes all the elements of the matrix (Figure 1). Then, it applies the command \"max(apply(z, 1, min))\", where \"1\" indicates that \"min\" applies to the rows of the matrix \"z\". This yields easy-to-understand code in the R program. To understand the reason why the matrix-based computation (Figure 1) is necessary, we give an example for calculating \(\delta_{2}^{\text{RML}}\) from a dataset \(\mathbf{Y}=(Y_{1},Y_{2},Y_{3})\). By setting \(i=2\) and \(G=3\) in Figure 1, the calculation for \(\delta_{2}^{\text{RML}}\) proceeds as follows:  
\[\left[ \begin{array}{cc}\frac{Y_{1}+Y_{2}}{2}&\frac{Y_{1}+Y_{2}+Y_{3}}{3}\\ Y_{2}&\frac{Y_{2}+Y_{3}}{2}\end{array} \right]\Rightarrow\left[ \begin{array}{ cc}\min\left(\frac{Y_{1}+Y_{2}}{2},\frac{Y_{1}+Y_{2}+Y_{3}}{3}\right),\min \left(Y_{2},\frac{Y_{2}+Y_{3}}{2}\right)\end{array} \right]\Rightarrow\max\biggl{\{} \min\biggl{(}\frac{Y_{1}+Y_{2}}{2},\frac{Y_{1}+Y_{2}+Y_{3}}{3}\biggr{)},\min \biggl{(}Y_{2},\frac{Y_{2}+Y_{3}}{2}\biggr{)}\biggr{\}}.\]  
The matrix in the preceding formula keeps four sub-averages of \((Y_{1},Y_{2},Y_{3})\), including \(Y_{2}\). Any one of the four components of the matrix can be \(\delta_{2}^{\text{RML}}\). Hence, the matrix is _necessary_ as well as _sufficient_ to calculate \(\delta_{2}^{\text{RML}}\). That aside, matrices are easy to manipulate in R.  
The RML estimator \(\delta^{\text{RML}}\equiv\left(\delta_{1}^{\text{RML}},\ldots,\delta_{\text{G }}^{\text{RML}}\right)\) gives a smaller WMSE than \(\mathbf{Y}\)[20]. For theories and applications of the PAVA, we refer to [30; 31; 32; 33; 34]. We decided not to use the \"pava(. )\" function available in the R package \"Iso\" [33] to ensure the independence of our package from others. Nonetheless, we checked that \"rml(. )\" and \"pava(. )\" gave numerically identical results. So far, we have assumed that the studies (i.e., \(i=1,2,\ldots,G\)) are ordered to achieve \(\mu_{1}\leq\ldots\leq\mu_{G}\). However, usually, the studies in a raw dataset may be arbitrarily ordered, and hence, one needs to find covariates to order the studies. For instance, one can use publication years if the \(\mu_{i}\) values increase with them. More generally, we assume that there exists an _increasing_ sequence of covariates (\(x_{1}<\ldots<x_{G}\)) or a _decreasing_ sequence of covariates (\(x_{1}>\ldots>x_{G}\)) to achieve the order \(\mu_{1}\leq\ldots\leq\mu_{G}\). In our R package, the function \"rml(. )\" can compute \(\delta^{\text{RML}}\). The function allows users to enter covariates when studies are not ordered. For instance, we enter the estimates (y), SEs (s), and the proportion of males (x) from the COVID-19 data with \(G=11\)[7; 20]. \[ \begin{array}{l}\text{y<-c(0.6881,0.5933,1.1756,0.5365,0.678,0.5878,0.4637,0.52 47,1.2326,2.8904,1.1378)}\\ \text{s<-c(0.6732,0.2754,0.2821,0.2493,0.1713,0.3302,0.0956,0.3272,0.1489,1.4263,0.2097)}\\ \text{x<-c(56.4,63.0,52.0,49.0,62.1,49.5,82.0,58.047,9.45,0.62.0) \# proportion of males}\\ \hline\end{array}