The internal functions .G
, .indexg
, .genlist
,
.ranmul
, and .selfmat
are used for calculating
genotype probabilities under partial selfing. The internal function
.unal1loc
finds all unique alleles at a single locus. The internal
function fixloci
converts locus names to a format that will be
compatible as column headers for allele frequency tables.
1 2 3 4 5 6 7 
q 
Integer. 
n 
Integer. 
ag1 
A vector representing an unambiguous genotype. 
na1 
Integer. The number of alleles, including a null. 
m2 
Integer. The ploidy. 
ng 
Integer. The number of genotypes. 
ag 
An array of genotypes such as that produced by

object 
A 
samples 
Optional, a numeric or character vector indicating which samples to use. 
locus 
A character string or number indicating which locus to use. 
loci 
A character vector of locus names. 
warn 
Boolean indicating whether a warning should be issued if locus names are changed. 
.G
returns
(n+q)!/((q+1)! * (n1)!)
.indexg
returns an integer indicating the row containing a
particular genotype in the matrix produced by .genlist
.
.genlist
returns an array with dimensions ng, m2
,
containing all possible unambiguous genotypes, one in each row. The null
allele is the highestnumbered allele.
.ranmul
returns a list. The first item is a vector of
polynomial coefficients for calculating genotype frequencies under
random mating. The second is an array
showing how many copies of each allele each genotype has.
.selfmat
returns the selfing matrix. Parental genotypes are
represented in rows, and offspring genotypes in columns. The numbers
indicate relative amounts of offspring genotypes produced when the
parental genotypes are selffertilized.
.unal1loc
returns a vector containing all unique alleles, not
including Missing(object)
.
fixloci
returns a character vector of corrected locus names.
Lindsay V. Clark
De Silva, H. N., Hall, A. J., Rikkerink, E., and Fraser, L. G. (2005) Estimation of allele frequencies in polyploids under certain patterns of inheritance. Heredity 95, 327–334
deSilvaFreq
, meandistance.matrix2
,
genotypeProbs
, genambig.to.genbinary
,
alleleDiversity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  # Calculation of genotype probabilities in a tetraploid with four
# alleles plus a null, and a selfing rate of 0.5. This is a translation
# of code in the supplementary material of De Silva et al. (2005).
m2 < 4
m < m2/2
na1 < 5
self < 0.5
ng < na1
for(j in 2:m2){
ng < ng*(na1+j1)/j
}
ag < polysat:::.genlist(ng, na1, m2)
temp < polysat:::.ranmul(ng, na1, ag, m2)
rmul < temp[[1]]
arep < temp[[2]]
rm(temp)
smat < polysat:::.selfmat(ng, na1, ag, m2)
smatdiv < (polysat:::.G(m1,m+1))^2
p1 < c(0.1, 0.4, 0.2, 0.2, 0.1) # allele frequencies
# GPROBS subroutine
rvec < rep(0,ng)
for(g in 1:ng){
rvec[g] < rmul[g]
for(j in 1:m2){
rvec[g] < rvec[g]*p1[ag[g,j]]
}
}
id < diag(nrow=ng)
smatt < smat/smatdiv
s3 < id  self * smatt
s3inv < solve(s3)
gprob < (1self) * s3inv
# gprob is a vector of probabilities of the seventy genotypes.

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.