Learn R Programming

DNAprofiles (version 0.3.1)

pr.next.allele: Probability of seeing next allele (Dirichlet sampling)

Description

Probability of seeing next allele (Dirichlet sampling)

Usage

pr.next.allele(i, seen, fr, theta = 0)

Arguments

i
Integer (vector), allele number
seen
Integer matrix with alleles already seen
fr
Numeric vector with allelic proportions
theta
Numeric giving the inbreeding coefficient

Value

numeric (vector) of probabilities

Details

When a population is subdivided into subpopulations, consecutively sampled alleles are not independent draws. This function implements the Dirichlet formula which states that after sampling $n$ alleles, of which $m$ are of type $A_i$, the probability that the next allele is of type $A_i$ equals:

$(m*\theta+(1-\theta)*p_i)/(1+(n-1)*\theta)$

The alleles already sampled are passed as the rows of the matrix seen, while the corresponding element of i specifies for which next allele the probability of sampling is computed. The length of i has to be equal to the number of rows of seen.

See Also

pr.next.alleles, rmp

Examples

Run this code
# theta=0 means independent sampling, so after seeing
# allele 1 three times the pr. remains 1/2
pr.next.allele(1,seen=matrix(c(1,1,1),nrow=1),fr=c(1/2,1/2),theta=0)
# theta>0 slighly increases the pr. of
# seeing the same allele again
pr.next.allele(1,seen=matrix(c(1,1,1),nrow=1),fr=c(1/2,1/2),theta=0.05)

# the function also works on vectors
# after seeing 1,1,1, the pr. of 1 remains 1/2
# and the same applies to the pr. of 2 after 2,2,1
pr.next.allele(c(1,2),seen=matrix(c(1,1,1,2,2,1),nrow=2,byrow=TRUE),fr=c(1/2,1/2),theta=0)
pr.next.allele(c(1,2),seen=matrix(c(1,1,1,2,2,1),nrow=2,byrow=TRUE),fr=c(1/2,1/2),theta=0.05)

Run the code above in your browser using DataLab