View source: R/inv_var_est_bayesian.R
inv_var_est_bayesian | R Documentation |
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
pis the true allele frequency and is unknown, while
kinshipis the mean kinship of the sample and is known. Using this assumption, an expectation over the posterior distribution of
pis 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
gis some desired exponent. Note that this function estimates these posteriors each from a single data point
x'.
inv_var_est_bayesian(p_anc_est, kinship, g)
p_anc_est |
A vector of sample allele frequencies (each refered to as |
kinship |
The mean kinship coefficient of the data |
g |
The exponent of the variance term |
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.
p_anc_est_beta_mle()
for another way to get less biased estimates of the ancestral allele frequencies and related terms.
# 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 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.