# aedl

`aedl` implements almost-exact inference for the DerSimonian-Laird (DL)
test statistic in the normal-normal random-effects meta-analysis model.

The implementation follows the numerical procedure described in the
supplemental material of Hanada and Sugimoto (2023), with the code organized and streamlined
for use as an R package. Development validation against the original
supplemental program is kept in `dev/compare_original_fast.R`; the `dev/`
directory is not included in CRAN builds.

## Installation

```r
# From a local checkout
install.packages("aedl_0.1.0.tar.gz", repos = NULL, type = "source")

# Or during development
# devtools::install()
```

## Basic Use

```r
library(aedl)

yi <- c(0.10, 0.25, 0.05, 0.30)
vi <- c(0.04, 0.05, 0.03, 0.06)

res <- aedl(
  yi,
  vi,
  method = "plugin",
  t_grid = seq(-6, 6, by = 0.2),
  nsim = 100,
  nsim_chi = 500,
  n_tau = 50,
  seed = 1
)

res
confint(res)
```

`method = "plugin"` corresponds to the `exactDL` option in the supplemental
program and uses the DL estimate of the between-study variance to construct
the almost-exact distribution.

`method = "i2c"` uses a corrected heterogeneity measure. In this package,
`I_c^2` is computed from the row of the simulated conditional distribution
corresponding to the observed `I2hat`, that is,
`p(I2hat_obs | I2)` over the `I2_grid`.

```r
res_i2c <- aedl(
  yi,
  vi,
  method = "i2c",
  a = 0,
  b = 1,
  t_grid = seq(-6, 6, by = 0.2),
  I2_grid = seq(0, 0.95, by = 0.05),
  nsim = 100,
  nsim_chi = 500,
  n_tau = 50,
  seed = 2
)
```

## Berkey PD Example

The Berkey probing depth (PD) data are available from `metadat`, which is a
suggested package rather than a dependency of `aedl`.

```r
if (requireNamespace("metadat", quietly = TRUE)) {
  data("dat.berkey1998", package = "metadat")
  dat_pd <- subset(dat.berkey1998, outcome == "PD")

  res_pd <- aedl(
    dat_pd$yi,
    dat_pd$vi,
    method = "plugin",
    t_grid = seq(-6, 6, by = 0.2),
    nsim = 200,
    nsim_chi = 1000,
    n_tau = 80,
    seed = 123
  )

  res_pd
}
```

For broader comparisons with DL, HKSJ, PLBC, or exact meta-analysis methods,
use packages such as `metafor`, `pimeta`, or `rma.exact` in analysis scripts.
Those packages are not required by the core `aedl` computation.

The package also provides helper functions, `aedl_tau2_density()` and
`aedl_stat_density()`, to evaluate the approximate density of the DL variance
estimator and the almost-exact density of the DL statistic.

## Full Analysis Settings

The examples above use small Monte Carlo settings so that they run quickly.
For substantive analyses, use larger settings, for example:

```r
# aedl(
#   yi, vi,
#   method = "plugin",
#   nsim = 10000,
#   nsim_chi = 100000,
#   n_tau = 1000
# )
```

## Reference

Hanada, K., & Sugimoto, T. (2023). Inference using an exact distribution of test statistic for random-effects meta-analysis. *Annals of the Institute of Statistical Mathematics*, 75(2), 281-302. doi:10.1007/s10463-022-00844-4.
