inv_var_est_bayesian: Calculate expectations of inverse variance terms over the...

View source: R/inv_var_est_bayesian.R

inv_var_est_bayesianR Documentation

Calculate expectations of inverse variance terms over the posterior distribution of the ancestral allele frequency

Description

This function assumes that each sample allele frequency x in the input has a Beta distribution with mean p and variance p*(1-p)*kinship⁠, where ⁠p⁠is the true allele frequency and is unknown, while⁠kinship⁠is the mean kinship of the sample and is known. Using this assumption, an expectation over the posterior distribution of⁠p⁠is calculated for what we call an inverse variance term, namely⁠1 / ( p * ( 1 - p ) )^g⁠, where ⁠p * ( 1 - p )⁠corresponds to the Bernoulli variance, and⁠g⁠is some desired exponent. Note that this function estimates these posteriors each from a single data point⁠x'.

Usage

inv_var_est_bayesian(p_anc_est, kinship, g)

Arguments

p_anc_est

A vector of sample allele frequencies (each refered to as x above)

kinship

The mean kinship coefficient of the data

g

The exponent of the variance term

Value

A vector of expectations of 1 / ( p * ( 1 - p ) )^g over the marginalized, unknown true ancestral allelel frequencies p, weighted by how likely they are in the posterior given each input sample allele frequency. The length of the vector is the same as the input p_anc_est, and each element in the output was estimated from each corresponding element in the input only.

See Also

p_anc_est_beta_mle() for another way to get less biased estimates of the ancestral allele frequencies and related terms.

Examples

# select a relatively high value for example
kinship <- 0.1

# try a grid of values, including edge cases (0,1)
m_loci <- 1000
p_anc_est <- 0 : (m_loci - 1) / (m_loci - 1)

# calculate the desired estimates!
# here g=0.5 estimates `1 / sqrt( p * ( 1 - p ) )`
inv_var_est <- inv_var_est_bayesian( p_anc_est, kinship, 0.5 )


OchoaLab/simtrait documentation built on July 4, 2025, 3:48 a.m.