#' Meta-Analysis of Correlated Genetic Association Studies
#'
#' `metalcor` generalizes the genetic association study meta-analysis software METAL to model studies with correlated statistics, which arise due to cryptic relatedness between studies.
#' 
#' This package also models the distribution of the product of correlated standard normal variables.
#' This is crucial for estimating correlation using the median product of z-scores, since in this case the median differs substantially from the mean.
#' The median provides robustness from the outliers caused by strongly associated loci.
#'
#' @examples
#' # construct two toy studies just to run example, with minimal columns
#' study1 <- data.frame(
#'   id = paste0( 'rs', 1:5 ),
#'   chr = 1,
#'   pos = 1:5,
#'   n = 2000,
#'   beta = rnorm( 5 ),
#'   se = rnorm( 5 )
#' )
#' # note the second study is missing the 5th SNP, this is fine
#' study2 <- data.frame(
#'   id = paste0( 'rs', 1:4 ),
#'   chr = 1,
#'   pos = 1:4,
#'   n = 5000,
#'   beta = rnorm( 4 ),
#'   se = rnorm( 4 )
#' )
#' 
#' library(metalcor)
#' # gather the studies in a list
#' studies <- list( study1, study2 )
#' # this performs the meta-analysis modeling covariance!
#' out <- metalcor( studies )
#' # this is the meta-analyzed association table
#' out$assoc
#' # and this is the estimated study covariance matrix
#' out$R
#'
#' # if you want to focus on the Z score covariance, you can do this separately
#' # (metalcor does it internally too):
#' Z <- cbind( study1$beta / study1$se, study2$beta / study2$se )
#' R <- estimate_R( Z )
#'
#' # lastly, let's look at the distribution of the product of correlated z scores
#' x <- Z[ , 1] * Z[ , 2]
#' # this estimates the correlation from the median product
#' rho_est <- rho_from_median( median( x ) )
#'
#' # the underlying distribution of these products of correlated standard normal variables
#' # is described by the `*prodcor` family:
#' # simulate some data again
#' rho <- 0.6
#' n <- 100
#' x <- rnorm( n )
#' p <- runif( n )
#' # density function
#' dprodcor( x, rho )
#' # cumulative function
#' pprodcor( x, rho )
#' # quantile function
#' qprodcor( p, rho )
#' # random deviates
#' rprodcor( n, rho )
#' 
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
